Skip to content

Commit 719c93e

Browse files
committed
get it nearly working
1 parent 62c0d3c commit 719c93e

File tree

4 files changed

+111800
-61679
lines changed

4 files changed

+111800
-61679
lines changed

grammar.js

+31-36
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,43 @@ module.exports = grammar({
3131
],
3232

3333
reserved: {
34+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
3435
global: $ => [
36+
'break',
37+
'case',
38+
'catch',
39+
'class',
3540
'const',
41+
'continue',
42+
'debugger',
43+
'default',
44+
'delete',
3645
'do',
3746
'else',
47+
'export',
48+
'extends',
49+
'false',
3850
'finally',
3951
'for',
4052
'function',
4153
'if',
42-
'let',
54+
'import',
55+
'in',
56+
'instanceof',
57+
'new',
58+
'null',
4359
'return',
60+
'super',
61+
'switch',
62+
'this',
4463
'throw',
64+
'true',
65+
'try',
66+
'typeof',
4567
'var',
68+
'void',
4669
'while',
70+
'with',
4771
],
4872
properties: $ => [],
4973
},
@@ -62,7 +86,6 @@ module.exports = grammar({
6286
$._expressions,
6387
$._semicolon,
6488
$._identifier,
65-
$._reserved_identifier,
6689
$._jsx_attribute,
6790
$._jsx_element_name,
6891
$._jsx_child,
@@ -108,9 +131,6 @@ module.exports = grammar({
108131

109132
conflicts: $ => [
110133
[$.primary_expression, $._property_name],
111-
[$.primary_expression, $._property_name, $.arrow_function],
112-
[$.primary_expression, $.arrow_function],
113-
[$.primary_expression, $.method_definition],
114134
[$.primary_expression, $.rest_pattern],
115135
[$.primary_expression, $.pattern],
116136
[$.primary_expression, $._for_header],
@@ -122,7 +142,6 @@ module.exports = grammar({
122142
[$.labeled_statement, $._property_name],
123143
[$.computed_property_name, $.array],
124144
[$.binary_expression, $._initializer],
125-
[$.class_static_block, $._property_name],
126145
],
127146

128147
word: $ => $.identifier,
@@ -191,6 +210,7 @@ module.exports = grammar({
191210
_module_export_name: $ => choice(
192211
$.identifier,
193212
$.string,
213+
'default',
194214
),
195215

196216
declaration: $ => choice(
@@ -443,7 +463,7 @@ module.exports = grammar({
443463
empty_statement: _ => ';',
444464

445465
labeled_statement: $ => prec.dynamic(-1, seq(
446-
field('label', alias(choice($.identifier, $._reserved_identifier), $.statement_identifier)),
466+
field('label', alias($.identifier, $.statement_identifier)),
447467
':',
448468
field('body', $.statement),
449469
)),
@@ -515,7 +535,6 @@ module.exports = grammar({
515535
$.member_expression,
516536
$.parenthesized_expression,
517537
$._identifier,
518-
alias($._reserved_identifier, $.identifier),
519538
$.this,
520539
$.super,
521540
$.number,
@@ -548,10 +567,7 @@ module.exports = grammar({
548567
$.pair,
549568
$.spread_element,
550569
$.method_definition,
551-
alias(
552-
choice($.identifier, $._reserved_identifier),
553-
$.shorthand_property_identifier,
554-
),
570+
alias($.identifier, $.shorthand_property_identifier),
555571
))),
556572
'}',
557573
)),
@@ -562,10 +578,7 @@ module.exports = grammar({
562578
$.pair_pattern,
563579
$.rest_pattern,
564580
$.object_assignment_pattern,
565-
alias(
566-
choice($.identifier, $._reserved_identifier),
567-
$.shorthand_property_identifier_pattern,
568-
),
581+
alias($.identifier, $.shorthand_property_identifier_pattern),
569582
))),
570583
'}',
571584
)),
@@ -579,10 +592,7 @@ module.exports = grammar({
579592
object_assignment_pattern: $ => seq(
580593
field('left', choice(
581594
$._destructuring_pattern,
582-
alias(
583-
choice($._reserved_identifier, $.identifier),
584-
$.shorthand_property_identifier_pattern,
585-
),
595+
alias($.identifier, $.shorthand_property_identifier_pattern),
586596
)),
587597
'=',
588598
field('right', $.expression),
@@ -784,7 +794,6 @@ module.exports = grammar({
784794
optional('async'),
785795
choice(
786796
field('parameter', choice(
787-
alias($._reserved_identifier, $.identifier),
788797
$.identifier,
789798
)),
790799
$._call_signature,
@@ -847,7 +856,6 @@ module.exports = grammar({
847856
$.member_expression,
848857
$.subscript_expression,
849858
$._identifier,
850-
alias($._reserved_identifier, $.identifier),
851859
$._destructuring_pattern,
852860
),
853861

@@ -860,7 +868,6 @@ module.exports = grammar({
860868
_augmented_assignment_lhs: $ => choice(
861869
$.member_expression,
862870
$.subscript_expression,
863-
alias($._reserved_identifier, $.identifier),
864871
$.identifier,
865872
$.parenthesized_expression,
866873
),
@@ -1218,10 +1225,7 @@ module.exports = grammar({
12181225
),
12191226

12201227
_property_name: $ => reserved('properties', choice(
1221-
alias(choice(
1222-
$.identifier,
1223-
$._reserved_identifier,
1224-
), $.property_identifier),
1228+
alias($.identifier, $.property_identifier),
12251229
$.private_property_identifier,
12261230
$.string,
12271231
$.number,
@@ -1234,15 +1238,6 @@ module.exports = grammar({
12341238
']',
12351239
),
12361240

1237-
_reserved_identifier: _ => choice(
1238-
'get',
1239-
'set',
1240-
'async',
1241-
'static',
1242-
'export',
1243-
'let',
1244-
),
1245-
12461241
_semicolon: $ => choice($._automatic_semicolon, ';'),
12471242
},
12481243
});

0 commit comments

Comments
 (0)