import error from './error.js'; /** * Splits an access path string into its component parts. * Handles dot notation, bracket notation, and quoted strings. */ export default function splitAccessPath(p: string): string[] { const path: string[] = [], n = p.length; let q: string | null = null, b = 0, s = ''; let i: number; let j: number; let c: string; p = p + ''; function push() { path.push(s + p.substring(i, j)); s = ''; i = j + 1; } for (i=j=0; j i) { push(); } else { i = j + 1; } } else if (c === '[') { if (j > i) push(); b = i = j + 1; } else if (c === ']') { if (!b) error('Access path missing open bracket: ' + p); if (b > 0) push(); b = 0; i = j + 1; } } if (b) error('Access path missing closing bracket: ' + p); if (q) error('Access path missing closing quote: ' + p); if (j > i) { j++; push(); } return path; }