Skip to content

Commit c220d3e

Browse files
maxbrunsfeldamaanq
authored andcommitted
feat: add reserved words
1 parent 7ef8551 commit c220d3e

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

grammar.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,48 @@ module.exports = grammar({
3030
/[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/,
3131
],
3232

33+
reserved: {
34+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
35+
global: $ => [
36+
'break',
37+
'case',
38+
'catch',
39+
'class',
40+
'const',
41+
'continue',
42+
'debugger',
43+
'default',
44+
'delete',
45+
'do',
46+
'else',
47+
'export',
48+
'extends',
49+
'false',
50+
'finally',
51+
'for',
52+
'function',
53+
'if',
54+
'import',
55+
'in',
56+
'instanceof',
57+
'new',
58+
'null',
59+
'return',
60+
'super',
61+
'switch',
62+
'this',
63+
'throw',
64+
'true',
65+
'try',
66+
'typeof',
67+
'var',
68+
'void',
69+
'while',
70+
'with',
71+
],
72+
properties: $ => [],
73+
},
74+
3375
supertypes: $ => [
3476
$.statement,
3577
$.declaration,
@@ -173,6 +215,7 @@ module.exports = grammar({
173215
_module_export_name: $ => choice(
174216
$.identifier,
175217
$.string,
218+
'default',
176219
),
177220

178221
declaration: $ => choice(
@@ -841,7 +884,8 @@ module.exports = grammar({
841884
choice('.', field('optional_chain', $.optional_chain)),
842885
field('property', choice(
843886
$.private_property_identifier,
844-
alias($.identifier, $.property_identifier))),
887+
reserved('properties', alias($.identifier, $.property_identifier)),
888+
)),
845889
)),
846890

847891
subscript_expression: $ => prec.right('member', seq(
@@ -1224,7 +1268,7 @@ module.exports = grammar({
12241268
field('value', choice($.pattern, $.assignment_pattern)),
12251269
),
12261270

1227-
_property_name: $ => choice(
1271+
_property_name: $ => reserved('properties', choice(
12281272
alias(
12291273
choice($.identifier, $._reserved_identifier),
12301274
$.property_identifier,
@@ -1233,7 +1277,7 @@ module.exports = grammar({
12331277
$.string,
12341278
$.number,
12351279
$.computed_property_name,
1236-
),
1280+
)),
12371281

12381282
computed_property_name: $ => seq(
12391283
'[',

test/corpus/expressions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Function calls with template strings
193193
============================================
194194

195195
f `hello`;
196-
f
196+
f
197197
`hello`;
198198

199199
---

test/corpus/statements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ export { "string import" as "string export" } from 'foo';
304304
(export_statement
305305
(export_clause
306306
(export_specifier
307-
name: (identifier)
308-
alias: (identifier))))
307+
name: (identifier))))
309308
(export_statement
310309
source: (string
311310
(string_fragment)))

0 commit comments

Comments
 (0)