Skip to content

Commit e37bf0d

Browse files
cknittclaude
andcommitted
Validate fixed literals as strict mode JavaScript
The output is strict, so legacy octal literals such as `007` and octal escapes are rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NP47qMfjMbjUTKZDsLthDo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 393ccaf commit e37bf0d

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎compiler/ml/classify_function.ml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ let classify ?(check : (Location.t * int) option) (prog : string) :
115115

116116
let is_fixed_literal (source : string) : bool =
117117
let open Parser_flow in
118-
let env = Parser_env.init_env None source in
118+
(* The output is strict mode JavaScript, which rejects legacy octal literals
119+
and escapes. *)
120+
let parse_options =
121+
Some {Parser_env.default_parse_options with use_strict = true}
122+
in
123+
let env = Parser_env.init_env ~parse_options None source in
119124
match
120125
do_parse env
121126
(fun env ->

‎tests/ounit_tests/ounit_flow_parser_tests.ml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ let suites =
6161
"1n";
6262
{|"s"|};
6363
"{}";
64+
"0o7";
65+
"0";
66+
{|"\0"|};
6467
"{a: [1, null]}";
6568
"/a/g";
6669
"undefined";
@@ -72,6 +75,8 @@ let suites =
7275
OUnit.assert_bool source
7376
(not (Classify_function.is_fixed_literal source)))
7477
[
78+
"007";
79+
{|"\07"|};
7580
"{[f()]: 0}";
7681
{|{["a"]: 0}|};
7782
"{a: {[f()]: 0}}";

0 commit comments

Comments
 (0)