Skip to content

Commit

Permalink
[easy] Don't parse JSON files with strict mode
Browse files Browse the repository at this point in the history
Summary:Strict mode does indeed address the octals difference between JS objects and JSON, but it also limits the ability to write duplicate properties in JSON (sometimes used as a way of writing comments in JSON).

While ES6 does permit duplicate object properties again, ES5 had the restriction -- so rather than removing the error from the parser entirely I figured we'd just stay conservative. I could be swayed here if someone feels strongly about this.

Reviewed By: gabelevi

Differential Revision: D3207718

fb-gh-sync-id: a1eb27979f3e6599f9a2ed5ffcff557db8b0198e
fbshipit-source-id: a1eb27979f3e6599f9a2ed5ffcff557db8b0198e
  • Loading branch information
jeffmo committed Apr 21, 2016
1 parent 042ea81 commit 85ed295
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parsing/parsing_service_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let parse_json_file ~fail content file =
esproposal_decorators = false;
esproposal_export_star_as = false;
types = true;
use_strict = true; (* JSON bans octals; this only forbids legacy octals *)
use_strict = false;
}) in

(* parse the file as JSON, then munge the AST to convert from an object
Expand Down
7 changes: 7 additions & 0 deletions tests/json/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ignore]

[include]

[libs]

[options]
2 changes: 2 additions & 0 deletions tests/json/json.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Found 0 errors
4 changes: 4 additions & 0 deletions tests/json/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"duplicates_are_allowed_in_json": 42,
"duplicates_are_allowed_in_json": 43
}

0 comments on commit 85ed295

Please sign in to comment.