Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
allow trailing commas in array when allowTrailingCommas option is true
Previously, allowTrailingCommas only allowed trailing commas in objects.
  • Loading branch information
sqs committed Mar 3, 2018
commit a8eef40e1599e9352ce75678c9aefd6ecbafb7dc
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
4 changes: 3 additions & 1 deletion src/test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,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 +264,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