Closed
Description
I ran into an issue with jsonc.parseTree when my input file was an empty file thus causing the text parameter to be an empty string. My code did something very similar to the following:
const rawFileContents = (await readFile(myFilePath)).toString();
const root = jsonc.parseTree(rawFileContents, parseErrors);
if (root.type === MY_EXPECTED_TYPE) {/* do something. */}
else { /* handle invalid file */ }
This causes an exception at root.type
when the file at myFilePath
is empty because root is undefined
.
Is this WAI or should the function signature below include undefined
or the function itself return an empty Node
when text
is the empty string?
/**
* Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
*/
export declare function parseTree(text: string, errors?: ParseError[], options?: ParseOptions): Node;