@willbooster/tree-sitter-javascript 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +72 -60
- package/package.json +1 -1
- package/queries/highlights.scm +14 -0
- package/src/node-types.json +1 -13
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -8,6 +8,46 @@
|
|
|
8
8
|
/// <reference types="tree-sitter-cli/dsl" />
|
|
9
9
|
// @ts-check
|
|
10
10
|
|
|
11
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
|
|
12
|
+
const RESERVED_WORDS = [
|
|
13
|
+
'break',
|
|
14
|
+
'case',
|
|
15
|
+
'catch',
|
|
16
|
+
'class',
|
|
17
|
+
'const',
|
|
18
|
+
'continue',
|
|
19
|
+
'debugger',
|
|
20
|
+
'default',
|
|
21
|
+
'delete',
|
|
22
|
+
'do',
|
|
23
|
+
'else',
|
|
24
|
+
'export',
|
|
25
|
+
'extends',
|
|
26
|
+
'false',
|
|
27
|
+
'finally',
|
|
28
|
+
'for',
|
|
29
|
+
'function',
|
|
30
|
+
'if',
|
|
31
|
+
'import',
|
|
32
|
+
'in',
|
|
33
|
+
'instanceof',
|
|
34
|
+
'new',
|
|
35
|
+
'null',
|
|
36
|
+
'return',
|
|
37
|
+
'super',
|
|
38
|
+
'switch',
|
|
39
|
+
'this',
|
|
40
|
+
'throw',
|
|
41
|
+
'true',
|
|
42
|
+
'try',
|
|
43
|
+
'typeof',
|
|
44
|
+
'var',
|
|
45
|
+
'void',
|
|
46
|
+
'while',
|
|
47
|
+
'with',
|
|
48
|
+
];
|
|
49
|
+
const NAMED_RESERVED_WORDS = new Set(['this', 'super', 'true', 'false', 'null']);
|
|
50
|
+
|
|
11
51
|
// oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
|
|
12
52
|
module.exports = grammar({
|
|
13
53
|
name: 'javascript',
|
|
@@ -34,44 +74,7 @@ module.exports = grammar({
|
|
|
34
74
|
extras: ($) => [$.comment, $.html_comment, /[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/u],
|
|
35
75
|
|
|
36
76
|
reserved: {
|
|
37
|
-
|
|
38
|
-
global: () => [
|
|
39
|
-
'break',
|
|
40
|
-
'case',
|
|
41
|
-
'catch',
|
|
42
|
-
'class',
|
|
43
|
-
'const',
|
|
44
|
-
'continue',
|
|
45
|
-
'debugger',
|
|
46
|
-
'default',
|
|
47
|
-
'delete',
|
|
48
|
-
'do',
|
|
49
|
-
'else',
|
|
50
|
-
'export',
|
|
51
|
-
'extends',
|
|
52
|
-
'false',
|
|
53
|
-
'finally',
|
|
54
|
-
'for',
|
|
55
|
-
'function',
|
|
56
|
-
'if',
|
|
57
|
-
'import',
|
|
58
|
-
'in',
|
|
59
|
-
'instanceof',
|
|
60
|
-
'new',
|
|
61
|
-
'null',
|
|
62
|
-
'return',
|
|
63
|
-
'super',
|
|
64
|
-
'switch',
|
|
65
|
-
'this',
|
|
66
|
-
'throw',
|
|
67
|
-
'true',
|
|
68
|
-
'try',
|
|
69
|
-
'typeof',
|
|
70
|
-
'var',
|
|
71
|
-
'void',
|
|
72
|
-
'while',
|
|
73
|
-
'with',
|
|
74
|
-
],
|
|
77
|
+
global: () => RESERVED_WORDS,
|
|
75
78
|
properties: () => [],
|
|
76
79
|
},
|
|
77
80
|
|
|
@@ -129,6 +132,7 @@ module.exports = grammar({
|
|
|
129
132
|
],
|
|
130
133
|
|
|
131
134
|
conflicts: ($) => [
|
|
135
|
+
[$._local_export_specifier, $._module_export_name],
|
|
132
136
|
[$.primary_expression, $._property_name],
|
|
133
137
|
[$.primary_expression, $.await_expression],
|
|
134
138
|
[$.primary_expression, $.await_expression, $._property_name],
|
|
@@ -153,7 +157,7 @@ module.exports = grammar({
|
|
|
153
157
|
rules: {
|
|
154
158
|
program: ($) => seq(optional($.hash_bang_line), repeat($.statement)),
|
|
155
159
|
|
|
156
|
-
hash_bang_line: () =>
|
|
160
|
+
hash_bang_line: () => /#![^\n\r\u2028\u2029]*/,
|
|
157
161
|
|
|
158
162
|
//
|
|
159
163
|
// Export declarations
|
|
@@ -167,7 +171,7 @@ module.exports = grammar({
|
|
|
167
171
|
seq('*', $._from_clause),
|
|
168
172
|
seq($.namespace_export, $._from_clause),
|
|
169
173
|
seq($.export_clause, $._from_clause),
|
|
170
|
-
$.export_clause
|
|
174
|
+
alias($._local_export_clause, $.export_clause)
|
|
171
175
|
),
|
|
172
176
|
$._semicolon
|
|
173
177
|
),
|
|
@@ -188,7 +192,22 @@ module.exports = grammar({
|
|
|
188
192
|
export_specifier: ($) =>
|
|
189
193
|
seq(field('name', $._module_export_name), optional(seq('as', field('alias', $._module_export_name)))),
|
|
190
194
|
|
|
191
|
-
|
|
195
|
+
// Without a `from` clause, each name refers to a local binding, which cannot be a reserved word.
|
|
196
|
+
_local_export_clause: ($) =>
|
|
197
|
+
seq('{', commaSep(alias($._local_export_specifier, $.export_specifier)), optional(','), '}'),
|
|
198
|
+
|
|
199
|
+
_local_export_specifier: ($) =>
|
|
200
|
+
seq(field('name', choice($.identifier, $.string)), optional(seq('as', field('alias', $._module_export_name)))),
|
|
201
|
+
|
|
202
|
+
// Reserved words are listed as keywords rather than allowed through the property word set, because the word set
|
|
203
|
+
// would also apply to the local bindings that share these positions until `as` or `from` (e.g. `import { if }`).
|
|
204
|
+
_module_export_name: ($) =>
|
|
205
|
+
choice(
|
|
206
|
+
$.identifier,
|
|
207
|
+
$.string,
|
|
208
|
+
// `this`, `super`, `true`, `false`, and `null` are named rules, and a bare string would make them non-terminals.
|
|
209
|
+
alias(choice(...RESERVED_WORDS.map((word) => (NAMED_RESERVED_WORDS.has(word) ? $[word] : word))), $.identifier)
|
|
210
|
+
),
|
|
192
211
|
|
|
193
212
|
declaration: ($) =>
|
|
194
213
|
choice(
|
|
@@ -547,15 +566,18 @@ module.exports = grammar({
|
|
|
547
566
|
|
|
548
567
|
jsx_identifier: () => /[a-zA-Z_$][a-zA-Z\d_$]*-[a-zA-Z\d_$-]*/,
|
|
549
568
|
|
|
550
|
-
_jsx_identifier: ($) => choice(alias($.jsx_identifier, $.identifier), $.identifier),
|
|
569
|
+
_jsx_identifier: ($) => choice(alias($.jsx_identifier, $.identifier), reserved('properties', $.identifier)),
|
|
551
570
|
|
|
552
571
|
nested_identifier: ($) =>
|
|
553
572
|
prec(
|
|
554
573
|
'member',
|
|
555
574
|
seq(
|
|
556
|
-
field(
|
|
575
|
+
field(
|
|
576
|
+
'object',
|
|
577
|
+
choice(reserved('properties', $.identifier), alias($.nested_identifier, $.member_expression))
|
|
578
|
+
),
|
|
557
579
|
'.',
|
|
558
|
-
field('property', alias($.identifier, $.property_identifier))
|
|
580
|
+
field('property', alias(reserved('properties', $.identifier), $.property_identifier))
|
|
559
581
|
)
|
|
560
582
|
),
|
|
561
583
|
|
|
@@ -905,17 +927,7 @@ module.exports = grammar({
|
|
|
905
927
|
|
|
906
928
|
escape_sequence: () =>
|
|
907
929
|
token.immediate(
|
|
908
|
-
seq(
|
|
909
|
-
'\\',
|
|
910
|
-
choice(
|
|
911
|
-
/[^xu0-7]/,
|
|
912
|
-
/[0-7]{1,3}/,
|
|
913
|
-
/x[0-9a-fA-F]{2}/,
|
|
914
|
-
/u[0-9a-fA-F]{4}/,
|
|
915
|
-
/u\{[0-9a-fA-F]+\}/,
|
|
916
|
-
/[\r?][\n\u2028\u2029]/
|
|
917
|
-
)
|
|
918
|
-
)
|
|
930
|
+
seq('\\', choice(/[^xu0-7]/, /[0-7]{1,3}/, /x[0-9a-fA-F]{2}/, /u[0-9a-fA-F]{4}/, /u\{[0-9a-fA-F]+\}/, /\r\n/))
|
|
919
931
|
),
|
|
920
932
|
|
|
921
933
|
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
|
@@ -960,15 +972,15 @@ module.exports = grammar({
|
|
|
960
972
|
'[',
|
|
961
973
|
repeat(
|
|
962
974
|
choice(
|
|
963
|
-
seq('\\',
|
|
964
|
-
/[^\]\
|
|
975
|
+
seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
|
|
976
|
+
/[^\]\\\n\r\u2028\u2029]/ // any character besides ']', '\', or a line terminator
|
|
965
977
|
)
|
|
966
978
|
),
|
|
967
979
|
']'
|
|
968
980
|
), // square-bracket-delimited character class
|
|
969
|
-
seq('\\',
|
|
981
|
+
seq('\\', /[^\n\r\u2028\u2029]/), // escaped character
|
|
970
982
|
// oxlint-disable-next-line no-useless-escape -- tree-sitter's regex parser rejects an unescaped `[` in a character class.
|
|
971
|
-
/[^/\\\[\n]/ // any character besides '[', '\', '/',
|
|
983
|
+
/[^/\\\[\n\r\u2028\u2029]/ // any character besides '[', '\', '/', or a line terminator
|
|
972
984
|
)
|
|
973
985
|
)
|
|
974
986
|
)
|
|
@@ -1113,7 +1125,7 @@ module.exports = grammar({
|
|
|
1113
1125
|
method_definition: ($) =>
|
|
1114
1126
|
seq(
|
|
1115
1127
|
repeat(field('decorator', $.decorator)),
|
|
1116
|
-
optional(choice('static', alias(token(seq('static', /\s+/, 'get', /\s
|
|
1128
|
+
optional(choice('static', alias(token(seq('static', /\s+/, 'get', /\s*[\n\r\u2028\u2029]/)), 'static get'))),
|
|
1117
1129
|
optional('async'),
|
|
1118
1130
|
optional(choice('get', 'set', '*')),
|
|
1119
1131
|
field('name', $._property_name),
|
package/package.json
CHANGED
package/queries/highlights.scm
CHANGED
|
@@ -202,3 +202,17 @@
|
|
|
202
202
|
"with"
|
|
203
203
|
"yield"
|
|
204
204
|
] @keyword
|
|
205
|
+
|
|
206
|
+
; `default` as a module export name is an identifier node.
|
|
207
|
+
(export_specifier
|
|
208
|
+
name: (identifier) @keyword
|
|
209
|
+
(#eq? @keyword "default"))
|
|
210
|
+
(export_specifier
|
|
211
|
+
alias: (identifier) @keyword
|
|
212
|
+
(#eq? @keyword "default"))
|
|
213
|
+
(import_specifier
|
|
214
|
+
name: (identifier) @keyword
|
|
215
|
+
(#eq? @keyword "default"))
|
|
216
|
+
(namespace_export
|
|
217
|
+
(identifier) @keyword
|
|
218
|
+
(#eq? @keyword "default"))
|
package/src/node-types.json
CHANGED
|
@@ -1094,10 +1094,6 @@
|
|
|
1094
1094
|
"multiple": false,
|
|
1095
1095
|
"required": false,
|
|
1096
1096
|
"types": [
|
|
1097
|
-
{
|
|
1098
|
-
"type": "default",
|
|
1099
|
-
"named": false
|
|
1100
|
-
},
|
|
1101
1097
|
{
|
|
1102
1098
|
"type": "identifier",
|
|
1103
1099
|
"named": true
|
|
@@ -1112,10 +1108,6 @@
|
|
|
1112
1108
|
"multiple": false,
|
|
1113
1109
|
"required": true,
|
|
1114
1110
|
"types": [
|
|
1115
|
-
{
|
|
1116
|
-
"type": "default",
|
|
1117
|
-
"named": false
|
|
1118
|
-
},
|
|
1119
1111
|
{
|
|
1120
1112
|
"type": "identifier",
|
|
1121
1113
|
"named": true
|
|
@@ -1727,10 +1719,6 @@
|
|
|
1727
1719
|
"multiple": false,
|
|
1728
1720
|
"required": true,
|
|
1729
1721
|
"types": [
|
|
1730
|
-
{
|
|
1731
|
-
"type": "default",
|
|
1732
|
-
"named": false
|
|
1733
|
-
},
|
|
1734
1722
|
{
|
|
1735
1723
|
"type": "identifier",
|
|
1736
1724
|
"named": true
|
|
@@ -2186,7 +2174,7 @@
|
|
|
2186
2174
|
"fields": {},
|
|
2187
2175
|
"children": {
|
|
2188
2176
|
"multiple": false,
|
|
2189
|
-
"required":
|
|
2177
|
+
"required": true,
|
|
2190
2178
|
"types": [
|
|
2191
2179
|
{
|
|
2192
2180
|
"type": "identifier",
|
|
Binary file
|