diff --git a/compiler/lib/js_parser.mly b/compiler/lib/js_parser.mly index 7bddaac0ff..90e11b8928 100644 --- a/compiler/lib/js_parser.mly +++ b/compiler/lib/js_parser.mly @@ -649,6 +649,20 @@ variable_with_loc: let name, _raw = i in var (p $symbolstartpos) name } + | ident_semi_keyword { var (p $symbolstartpos) (utf8_s (Js_token.to_string $1)) } + +(* add here keywords which are not considered reserved by ECMA *) +ident_semi_keyword: + | T_OF { T_OF } + | T_TYPE { T_TYPE } + | T_DECLARE { T_DECLARE } + | T_PUBLIC { T_PUBLIC } | T_PRIVATE { T_PRIVATE } | T_PROTECTED { T_PROTECTED } + (* can have AS and ASYNC here but need to restrict arrow_function then *) + | T_ASYNC { T_ASYNC } + (* TODO: would like to add T_IMPORT here, but cause conflicts *) + | T_PACKAGE { T_PACKAGE } + | T_IMPLEMENTS { T_IMPLEMENTS } + | T_OPAQUE { T_OPAQUE } label: | T_IDENTIFIER { diff --git a/compiler/tests-compiler/js_parser_printer.ml b/compiler/tests-compiler/js_parser_printer.ml index f31e6f0b71..6c16b466ba 100644 --- a/compiler/tests-compiler/js_parser_printer.ml +++ b/compiler/tests-compiler/js_parser_printer.ml @@ -481,3 +481,21 @@ c 11: 0:}, 12: 0://Provides: test(annot), 13: 0:c (identifier), 0:; (virtual), |}] + +let%expect_test _ = + parse_print_token + ~extra:true + {| +Event.prototype.initEvent = function _Event_initEvent(type, bubbles, cancelable) { + this.type = type + this.bubbles = bubbles + this.cancelable = cancelable +} +|}; + [%expect + {| + 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:{, + 3: 4:this, 8:., 9:type, 14:=, 16:type, 0:; (virtual), + 4: 4:this, 8:., 9:bubbles (identifier), 17:=, 19:bubbles (identifier), 0:; (virtual), + 5: 4:this, 8:., 9:cancelable (identifier), 20:=, 22:cancelable (identifier), 0:; (virtual), + 6: 0:}, 0:; (virtual), |}]