From 85ed2950db2a88c1a0a5e6b4643784a42adacab8 Mon Sep 17 00:00:00 2001 From: Jeff Morrison Date: Thu, 21 Apr 2016 09:16:32 -0700 Subject: [PATCH] [easy] Don't parse JSON files with strict mode 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 --- src/parsing/parsing_service_js.ml | 2 +- tests/json/.flowconfig | 7 +++++++ tests/json/json.exp | 2 ++ tests/json/test.json | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/json/.flowconfig create mode 100644 tests/json/json.exp create mode 100644 tests/json/test.json diff --git a/src/parsing/parsing_service_js.ml b/src/parsing/parsing_service_js.ml index d213758e91e..d0de3641581 100644 --- a/src/parsing/parsing_service_js.ml +++ b/src/parsing/parsing_service_js.ml @@ -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 diff --git a/tests/json/.flowconfig b/tests/json/.flowconfig new file mode 100644 index 00000000000..4a58bdcdef3 --- /dev/null +++ b/tests/json/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/tests/json/json.exp b/tests/json/json.exp new file mode 100644 index 00000000000..c82edb53368 --- /dev/null +++ b/tests/json/json.exp @@ -0,0 +1,2 @@ + +Found 0 errors diff --git a/tests/json/test.json b/tests/json/test.json new file mode 100644 index 00000000000..3d644a474d3 --- /dev/null +++ b/tests/json/test.json @@ -0,0 +1,4 @@ +{ + "duplicates_are_allowed_in_json": 42, + "duplicates_are_allowed_in_json": 43 +}