Skip to content

Commit 42bf1e0

Browse files
committed
Compiler: fix js parser with semi-keyword
1 parent c3334cf commit 42bf1e0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

compiler/lib/js_parser.mly

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,20 @@ variable_with_loc:
649649
let name, _raw = i in
650650
var (p $symbolstartpos) name
651651
}
652+
| ident_semi_keyword { var (p $symbolstartpos) (utf8_s (Js_token.to_string $1)) }
653+
654+
(* add here keywords which are not considered reserved by ECMA *)
655+
ident_semi_keyword:
656+
| T_OF { T_OF }
657+
| T_TYPE { T_TYPE }
658+
| T_DECLARE { T_DECLARE }
659+
| T_PUBLIC { T_PUBLIC } | T_PRIVATE { T_PRIVATE } | T_PROTECTED { T_PROTECTED }
660+
(* can have AS and ASYNC here but need to restrict arrow_function then *)
661+
| T_ASYNC { T_ASYNC }
662+
(* TODO: would like to add T_IMPORT here, but cause conflicts *)
663+
| T_PACKAGE { T_PACKAGE }
664+
| T_IMPLEMENTS { T_IMPLEMENTS }
665+
| T_OPAQUE { T_OPAQUE }
652666

653667
label:
654668
| T_IDENTIFIER {

compiler/tests-compiler/js_parser_printer.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,21 @@ c
481481
11: 0:},
482482
12: 0://Provides: test(annot),
483483
13: 0:c (identifier), 0:; (virtual), |}]
484+
485+
let%expect_test _ =
486+
parse_print_token
487+
~extra:true
488+
{|
489+
Event.prototype.initEvent = function _Event_initEvent(type, bubbles, cancelable) {
490+
this.type = type
491+
this.bubbles = bubbles
492+
this.cancelable = cancelable
493+
}
494+
|};
495+
[%expect
496+
{|
497+
2: 0:Event (identifier), 5:., 6:prototype (identifier), 15:., 16:initEvent (identifier), 26:=, 28:function, 37:_Event_initEvent (identifier), 53:(, 54:type, 58:,, 60:bubbles (identifier), 67:,, 69:cancelable (identifier), 79:), 81:{,
498+
3: 4:this, 8:., 9:type, 14:=, 16:type, 0:; (virtual),
499+
4: 4:this, 8:., 9:bubbles (identifier), 17:=, 19:bubbles (identifier), 0:; (virtual),
500+
5: 4:this, 8:., 9:cancelable (identifier), 20:=, 22:cancelable (identifier), 0:; (virtual),
501+
6: 0:}, 0:; (virtual), |}]

0 commit comments

Comments
 (0)