Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@ export function visit(text: string, visitor: JSONVisitor, options?: ParseOptions
}
onSeparator(',');
scanNext(); // consume comma
if (_scanner.getToken() === SyntaxKind.CloseBracketToken && allowTrailingComma) {
break;
}
} else if (needsComma) {
handleError(ParseErrorCode.CommaExpected, [], []);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ function assertValidParse(input: string, expected: any, options?: ParseOptions):
var errors: ParseError[] = [];
var actual = parse(input, errors, options);

if (errors.length !== 0) {
assert.notEqual("undefined", typeof errors[0].error);
}
assert.deepEqual([], errors)
assert.deepEqual(actual, expected);
}

Expand Down Expand Up @@ -244,7 +242,6 @@ suite('JSON', () => {

test('parse: array with errors', () => {
assertInvalidParse('[,]', []);
assertInvalidParse('[ 1, 2, ]', [1, 2]);
assertInvalidParse('[ 1 2, 3 ]', [1, 2, 3]);
assertInvalidParse('[ ,1, 2, 3 ]', [1, 2, 3]);
assertInvalidParse('[ ,1, 2, 3, ]', [1, 2, 3]);
Expand All @@ -265,9 +262,12 @@ suite('JSON', () => {
assertValidParse('{ "hello": [] }', { hello: [] }, options);
assertValidParse('{ "hello": [], "world": {}, }', { hello: [], world: {} }, options);
assertValidParse('{ "hello": [], "world": {} }', { hello: [], world: {} }, options);
assertValidParse('[ 1, 2, ]', [1, 2], options);
assertValidParse('[ 1, 2 ]', [1, 2], options);

assertInvalidParse('{ "hello": [], }', { hello: [] });
assertInvalidParse('{ "hello": [], "world": {}, }', { hello: [], world: {} });
assertInvalidParse('[ 1, 2, ]', [1, 2]);
});
test('location: properties', () => {
assertLocation('|{ "foo": "bar" }', [], void 0, false);
Expand Down