@willbooster/tree-sitter-javascript 0.0.0-placeholder.0 → 1.0.1
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/LICENSE +22 -0
- package/README.md +107 -1
- package/grammar.js +1145 -0
- package/package.json +64 -2
- package/queries/highlights-jsx.scm +8 -0
- package/queries/highlights-params.scm +12 -0
- package/queries/highlights.scm +204 -0
- package/queries/injections.scm +31 -0
- package/queries/locals.scm +23 -0
- package/queries/tags.scm +99 -0
- package/src/node-types.json +3622 -0
- package/tree-sitter-javascript.wasm +0 -0
- package/tree-sitter.json +41 -0
package/package.json
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-javascript",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "JavaScript grammar for tree-sitter",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"incremental",
|
|
7
|
+
"parsing",
|
|
8
|
+
"tree-sitter",
|
|
9
|
+
"javascript"
|
|
10
|
+
],
|
|
5
11
|
"repository": {
|
|
6
12
|
"type": "git",
|
|
7
13
|
"url": "git+https://github.com/WillBooster/tree-sitter-javascript.git"
|
|
8
14
|
},
|
|
9
15
|
"license": "MIT",
|
|
10
16
|
"author": "WillBooster Inc.",
|
|
17
|
+
"files": [
|
|
18
|
+
"grammar.js",
|
|
19
|
+
"tree-sitter.json",
|
|
20
|
+
"queries/*",
|
|
21
|
+
"src/node-types.json",
|
|
22
|
+
"*.wasm"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build-wasm": "tree-sitter build --wasm",
|
|
26
|
+
"build/ci": "tree-sitter generate && tree-sitter build --wasm",
|
|
27
|
+
"cleanup": "bun wb lint --fix --format",
|
|
28
|
+
"format": "bun wb lint --format",
|
|
29
|
+
"lint": "bun wb lint",
|
|
30
|
+
"lint-fix": "bun wb lint --fix",
|
|
31
|
+
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
32
|
+
"release": "wb release",
|
|
33
|
+
"prestart": "bun run build-wasm",
|
|
34
|
+
"start": "tree-sitter playground",
|
|
35
|
+
"test": "bun wb test",
|
|
36
|
+
"test/ci": "bun wb test-on-ci",
|
|
37
|
+
"test/ci-setup": "playwright install --with-deps chromium",
|
|
38
|
+
"typecheck": "bun wb typecheck",
|
|
39
|
+
"verify": "bun wb verify",
|
|
40
|
+
"verify-full": "bun wb verify --full"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@semantic-release/exec": "7.1.0",
|
|
44
|
+
"@tsconfig/bun": "1.0.11",
|
|
45
|
+
"@types/bun": "1.4.2",
|
|
46
|
+
"@vitest/browser-playwright": "5.0.1",
|
|
47
|
+
"@willbooster/oxfmt-config": "1.2.2",
|
|
48
|
+
"@willbooster/oxlint-config": "1.4.8",
|
|
49
|
+
"@willbooster/wb": "22.11.5",
|
|
50
|
+
"@willbooster/web-tree-sitter": "1.0.0",
|
|
51
|
+
"conventional-changelog-conventionalcommits": "10.4.0",
|
|
52
|
+
"lefthook": "2.1.14",
|
|
53
|
+
"oxfmt": "0.70.0",
|
|
54
|
+
"oxlint": "1.85.0",
|
|
55
|
+
"oxlint-tsgolint": "7.0.2002",
|
|
56
|
+
"playwright": "1.63.0",
|
|
57
|
+
"semantic-release": "25.0.9",
|
|
58
|
+
"sort-package-json": "4.0.0",
|
|
59
|
+
"tree-sitter-cli": "0.27.0",
|
|
60
|
+
"typescript": "7.0.2",
|
|
61
|
+
"vite": "8.3.0",
|
|
62
|
+
"vitest": "5.0.1",
|
|
63
|
+
"wrangler": "4.136.2"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@willbooster/web-tree-sitter": "^1.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"@willbooster/web-tree-sitter": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
72
|
+
},
|
|
11
73
|
"publishConfig": {
|
|
12
74
|
"access": "public",
|
|
13
75
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
|
2
|
+
(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
|
3
|
+
(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
|
4
|
+
|
|
5
|
+
(jsx_attribute (property_identifier) @attribute)
|
|
6
|
+
(jsx_opening_element (["<" ">"]) @punctuation.bracket)
|
|
7
|
+
(jsx_closing_element (["</" ">"]) @punctuation.bracket)
|
|
8
|
+
(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(formal_parameters
|
|
2
|
+
[
|
|
3
|
+
(identifier) @variable.parameter
|
|
4
|
+
(array_pattern
|
|
5
|
+
(identifier) @variable.parameter)
|
|
6
|
+
(object_pattern
|
|
7
|
+
[
|
|
8
|
+
(pair_pattern value: (identifier) @variable.parameter)
|
|
9
|
+
(shorthand_property_identifier_pattern) @variable.parameter
|
|
10
|
+
])
|
|
11
|
+
]
|
|
12
|
+
)
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
; Variables
|
|
2
|
+
;----------
|
|
3
|
+
|
|
4
|
+
(identifier) @variable
|
|
5
|
+
|
|
6
|
+
; Properties
|
|
7
|
+
;-----------
|
|
8
|
+
|
|
9
|
+
(property_identifier) @property
|
|
10
|
+
|
|
11
|
+
; Function and method definitions
|
|
12
|
+
;--------------------------------
|
|
13
|
+
|
|
14
|
+
(function_expression
|
|
15
|
+
name: (identifier) @function)
|
|
16
|
+
(function_declaration
|
|
17
|
+
name: (identifier) @function)
|
|
18
|
+
(method_definition
|
|
19
|
+
name: (property_identifier) @function.method)
|
|
20
|
+
|
|
21
|
+
(pair
|
|
22
|
+
key: (property_identifier) @function.method
|
|
23
|
+
value: [(function_expression) (arrow_function)])
|
|
24
|
+
|
|
25
|
+
(assignment_expression
|
|
26
|
+
left: (member_expression
|
|
27
|
+
property: (property_identifier) @function.method)
|
|
28
|
+
right: [(function_expression) (arrow_function)])
|
|
29
|
+
|
|
30
|
+
(variable_declarator
|
|
31
|
+
name: (identifier) @function
|
|
32
|
+
value: [(function_expression) (arrow_function)])
|
|
33
|
+
|
|
34
|
+
(assignment_expression
|
|
35
|
+
left: (identifier) @function
|
|
36
|
+
right: [(function_expression) (arrow_function)])
|
|
37
|
+
|
|
38
|
+
; Function and method calls
|
|
39
|
+
;--------------------------
|
|
40
|
+
|
|
41
|
+
(call_expression
|
|
42
|
+
function: (identifier) @function)
|
|
43
|
+
|
|
44
|
+
(call_expression
|
|
45
|
+
function: (member_expression
|
|
46
|
+
property: (property_identifier) @function.method))
|
|
47
|
+
|
|
48
|
+
; Special identifiers
|
|
49
|
+
;--------------------
|
|
50
|
+
|
|
51
|
+
((identifier) @constructor
|
|
52
|
+
(#match? @constructor "^[A-Z]"))
|
|
53
|
+
|
|
54
|
+
([
|
|
55
|
+
(identifier)
|
|
56
|
+
(shorthand_property_identifier)
|
|
57
|
+
(shorthand_property_identifier_pattern)
|
|
58
|
+
] @constant
|
|
59
|
+
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
|
|
60
|
+
|
|
61
|
+
((identifier) @variable.builtin
|
|
62
|
+
(#match? @variable.builtin "^(arguments|module|console|window|document)$")
|
|
63
|
+
(#is-not? local))
|
|
64
|
+
|
|
65
|
+
((identifier) @function.builtin
|
|
66
|
+
(#eq? @function.builtin "require")
|
|
67
|
+
(#is-not? local))
|
|
68
|
+
|
|
69
|
+
; Literals
|
|
70
|
+
;---------
|
|
71
|
+
|
|
72
|
+
(this) @variable.builtin
|
|
73
|
+
(super) @variable.builtin
|
|
74
|
+
|
|
75
|
+
[
|
|
76
|
+
(true)
|
|
77
|
+
(false)
|
|
78
|
+
(null)
|
|
79
|
+
(undefined)
|
|
80
|
+
] @constant.builtin
|
|
81
|
+
|
|
82
|
+
(comment) @comment
|
|
83
|
+
|
|
84
|
+
[
|
|
85
|
+
(string)
|
|
86
|
+
(template_string)
|
|
87
|
+
] @string
|
|
88
|
+
|
|
89
|
+
(regex) @string.special
|
|
90
|
+
(number) @number
|
|
91
|
+
|
|
92
|
+
; Tokens
|
|
93
|
+
;-------
|
|
94
|
+
|
|
95
|
+
[
|
|
96
|
+
";"
|
|
97
|
+
(optional_chain)
|
|
98
|
+
"."
|
|
99
|
+
","
|
|
100
|
+
] @punctuation.delimiter
|
|
101
|
+
|
|
102
|
+
[
|
|
103
|
+
"-"
|
|
104
|
+
"--"
|
|
105
|
+
"-="
|
|
106
|
+
"+"
|
|
107
|
+
"++"
|
|
108
|
+
"+="
|
|
109
|
+
"*"
|
|
110
|
+
"*="
|
|
111
|
+
"**"
|
|
112
|
+
"**="
|
|
113
|
+
"/"
|
|
114
|
+
"/="
|
|
115
|
+
"%"
|
|
116
|
+
"%="
|
|
117
|
+
"<"
|
|
118
|
+
"<="
|
|
119
|
+
"<<"
|
|
120
|
+
"<<="
|
|
121
|
+
"="
|
|
122
|
+
"=="
|
|
123
|
+
"==="
|
|
124
|
+
"!"
|
|
125
|
+
"!="
|
|
126
|
+
"!=="
|
|
127
|
+
"=>"
|
|
128
|
+
">"
|
|
129
|
+
">="
|
|
130
|
+
">>"
|
|
131
|
+
">>="
|
|
132
|
+
">>>"
|
|
133
|
+
">>>="
|
|
134
|
+
"~"
|
|
135
|
+
"^"
|
|
136
|
+
"&"
|
|
137
|
+
"|"
|
|
138
|
+
"^="
|
|
139
|
+
"&="
|
|
140
|
+
"|="
|
|
141
|
+
"&&"
|
|
142
|
+
"||"
|
|
143
|
+
"??"
|
|
144
|
+
"&&="
|
|
145
|
+
"||="
|
|
146
|
+
"??="
|
|
147
|
+
] @operator
|
|
148
|
+
|
|
149
|
+
[
|
|
150
|
+
"("
|
|
151
|
+
")"
|
|
152
|
+
"["
|
|
153
|
+
"]"
|
|
154
|
+
"{"
|
|
155
|
+
"}"
|
|
156
|
+
] @punctuation.bracket
|
|
157
|
+
|
|
158
|
+
(template_substitution
|
|
159
|
+
"${" @punctuation.special
|
|
160
|
+
"}" @punctuation.special) @embedded
|
|
161
|
+
|
|
162
|
+
[
|
|
163
|
+
"as"
|
|
164
|
+
"async"
|
|
165
|
+
"await"
|
|
166
|
+
"break"
|
|
167
|
+
"case"
|
|
168
|
+
"catch"
|
|
169
|
+
"class"
|
|
170
|
+
"const"
|
|
171
|
+
"continue"
|
|
172
|
+
"debugger"
|
|
173
|
+
"default"
|
|
174
|
+
"delete"
|
|
175
|
+
"do"
|
|
176
|
+
"else"
|
|
177
|
+
"export"
|
|
178
|
+
"extends"
|
|
179
|
+
"finally"
|
|
180
|
+
"for"
|
|
181
|
+
"from"
|
|
182
|
+
"function"
|
|
183
|
+
"get"
|
|
184
|
+
"if"
|
|
185
|
+
"import"
|
|
186
|
+
"in"
|
|
187
|
+
"instanceof"
|
|
188
|
+
"let"
|
|
189
|
+
"new"
|
|
190
|
+
"of"
|
|
191
|
+
"return"
|
|
192
|
+
"set"
|
|
193
|
+
"static"
|
|
194
|
+
"switch"
|
|
195
|
+
"target"
|
|
196
|
+
"throw"
|
|
197
|
+
"try"
|
|
198
|
+
"typeof"
|
|
199
|
+
"var"
|
|
200
|
+
"void"
|
|
201
|
+
"while"
|
|
202
|
+
"with"
|
|
203
|
+
"yield"
|
|
204
|
+
] @keyword
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
; Parse the contents of tagged template literals using
|
|
2
|
+
; a language inferred from the tag.
|
|
3
|
+
|
|
4
|
+
(call_expression
|
|
5
|
+
function: [
|
|
6
|
+
(identifier) @injection.language
|
|
7
|
+
(member_expression
|
|
8
|
+
property: (property_identifier) @injection.language)
|
|
9
|
+
]
|
|
10
|
+
arguments: (template_string (string_fragment) @injection.content)
|
|
11
|
+
(#set! injection.combined)
|
|
12
|
+
(#set! injection.include-children))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
; Parse regex syntax within regex literals
|
|
16
|
+
|
|
17
|
+
((regex_pattern) @injection.content
|
|
18
|
+
(#set! injection.language "regex"))
|
|
19
|
+
|
|
20
|
+
; Parse JSDoc annotations in comments
|
|
21
|
+
|
|
22
|
+
((comment) @injection.content
|
|
23
|
+
(#set! injection.language "jsdoc"))
|
|
24
|
+
|
|
25
|
+
; Parse Ember/Glimmer/Handlebars/HTMLBars/etc. template literals
|
|
26
|
+
; e.g.: await render(hbs`<SomeComponent />`)
|
|
27
|
+
(call_expression
|
|
28
|
+
function: ((identifier) @_name
|
|
29
|
+
(#eq? @_name "hbs"))
|
|
30
|
+
arguments: ((template_string) @glimmer
|
|
31
|
+
(#offset! @glimmer 0 1 0 -1)))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
; Scopes
|
|
2
|
+
;-------
|
|
3
|
+
|
|
4
|
+
[
|
|
5
|
+
(statement_block)
|
|
6
|
+
(function_expression)
|
|
7
|
+
(arrow_function)
|
|
8
|
+
(function_declaration)
|
|
9
|
+
(method_definition)
|
|
10
|
+
] @local.scope
|
|
11
|
+
|
|
12
|
+
; Definitions
|
|
13
|
+
;------------
|
|
14
|
+
|
|
15
|
+
(pattern/identifier) @local.definition
|
|
16
|
+
|
|
17
|
+
(variable_declarator
|
|
18
|
+
name: (identifier) @local.definition)
|
|
19
|
+
|
|
20
|
+
; References
|
|
21
|
+
;------------
|
|
22
|
+
|
|
23
|
+
(identifier) @local.reference
|
package/queries/tags.scm
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
(
|
|
2
|
+
(comment)* @doc
|
|
3
|
+
.
|
|
4
|
+
(method_definition
|
|
5
|
+
name: (property_identifier) @name) @definition.method
|
|
6
|
+
(#not-eq? @name "constructor")
|
|
7
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
8
|
+
(#select-adjacent! @doc @definition.method)
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
(
|
|
12
|
+
(comment)* @doc
|
|
13
|
+
.
|
|
14
|
+
[
|
|
15
|
+
(class
|
|
16
|
+
name: (_) @name)
|
|
17
|
+
(class_declaration
|
|
18
|
+
name: (_) @name)
|
|
19
|
+
] @definition.class
|
|
20
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
21
|
+
(#select-adjacent! @doc @definition.class)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
(
|
|
25
|
+
(comment)* @doc
|
|
26
|
+
.
|
|
27
|
+
[
|
|
28
|
+
(function_expression
|
|
29
|
+
name: (identifier) @name)
|
|
30
|
+
(function_declaration
|
|
31
|
+
name: (identifier) @name)
|
|
32
|
+
(generator_function
|
|
33
|
+
name: (identifier) @name)
|
|
34
|
+
(generator_function_declaration
|
|
35
|
+
name: (identifier) @name)
|
|
36
|
+
] @definition.function
|
|
37
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
38
|
+
(#select-adjacent! @doc @definition.function)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
(
|
|
42
|
+
(comment)* @doc
|
|
43
|
+
.
|
|
44
|
+
(lexical_declaration
|
|
45
|
+
(variable_declarator
|
|
46
|
+
name: (identifier) @name
|
|
47
|
+
value: [(arrow_function) (function_expression)]) @definition.function)
|
|
48
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
49
|
+
(#select-adjacent! @doc @definition.function)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
(
|
|
53
|
+
(comment)* @doc
|
|
54
|
+
.
|
|
55
|
+
(variable_declaration
|
|
56
|
+
(variable_declarator
|
|
57
|
+
name: (identifier) @name
|
|
58
|
+
value: [(arrow_function) (function_expression)]) @definition.function)
|
|
59
|
+
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
|
60
|
+
(#select-adjacent! @doc @definition.function)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
(assignment_expression
|
|
64
|
+
left: [
|
|
65
|
+
(identifier) @name
|
|
66
|
+
(member_expression
|
|
67
|
+
property: (property_identifier) @name)
|
|
68
|
+
]
|
|
69
|
+
right: [(arrow_function) (function_expression)]
|
|
70
|
+
) @definition.function
|
|
71
|
+
|
|
72
|
+
(pair
|
|
73
|
+
key: (property_identifier) @name
|
|
74
|
+
value: [(arrow_function) (function_expression)]) @definition.function
|
|
75
|
+
|
|
76
|
+
(
|
|
77
|
+
(call_expression
|
|
78
|
+
function: (identifier) @name) @reference.call
|
|
79
|
+
(#not-match? @name "^(require)$")
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
(call_expression
|
|
83
|
+
function: (member_expression
|
|
84
|
+
property: (property_identifier) @name)
|
|
85
|
+
arguments: (_) @reference.call)
|
|
86
|
+
|
|
87
|
+
(new_expression
|
|
88
|
+
constructor: (_) @name) @reference.class
|
|
89
|
+
|
|
90
|
+
(export_statement value: (assignment_expression left: (identifier) @name right: ([
|
|
91
|
+
(number)
|
|
92
|
+
(string)
|
|
93
|
+
(identifier)
|
|
94
|
+
(undefined)
|
|
95
|
+
(null)
|
|
96
|
+
(new_expression)
|
|
97
|
+
(binary_expression)
|
|
98
|
+
(call_expression)
|
|
99
|
+
]))) @definition.constant
|