Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ const parse = (input, options = {}) => {
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
}

let braceStack = [];
for (const char of input) {
if (char === '{') {
braceStack.push('{');
} else if (char === '}') {
if (braceStack.length === 0) {
throw new SyntaxError("Mismatched closing brace found");
}
braceStack.pop();
}
}

if (braceStack.length > 0) {
throw new SyntaxError("Mismatched open brace found");
}

let ast = { type: 'root', input, nodes: [] };
let stack = [ast];
let block = ast;
Expand Down