json-asty
json-asty copied to clipboard
initial blank lines in text causes first callback from jsonAsty.parse to have extra chars in prolog
I am calling parse with this ...
ast = jsonAsty.parse('\n\n{"a":1}');
I have this code at beginning of callback ...
ast.walk((node: any, depth: number, parent: any, when: string) => {
console.log(node.A.prolog.charCodeAt(0));
console.log(node.A.prolog.charCodeAt(1));
console.log(node.A.prolog.charCodeAt(2));
console.log(node.A.prolog.charCodeAt(3));
<< I put a breakpoint here so only first callback runs >>
which gives this result ...
10
44
10
123
A 10 is a line feed and a 44 is a comma. So the first prolog has commas between the line feeds. This only happens with two or more blank lines at the beginning.
P.S. Can you give me a hint on how I can debug your code in my node_modules? The code is compressed.
I stripped the comments in the first prolog and it works so far in testting. But it makes me nervous that this bug might cause problems in other situations that testing hasn't found. I dislike band-aids in general.