react-native-codepad-lang-javascript 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,107 @@
1
+ ; inherited from ecma
2
+ [
3
+ (arguments)
4
+ (array)
5
+ (binary_expression)
6
+ (class_body)
7
+ (export_clause)
8
+ (formal_parameters)
9
+ (named_imports)
10
+ (object)
11
+ (object_pattern)
12
+ (parenthesized_expression)
13
+ (return_statement)
14
+ (statement_block)
15
+ (switch_case)
16
+ (switch_default)
17
+ (switch_statement)
18
+ (template_substitution)
19
+ (ternary_expression)
20
+ ] @indent.begin
21
+
22
+ (arguments
23
+ (call_expression) @indent.begin)
24
+
25
+ (binary_expression
26
+ (call_expression) @indent.begin)
27
+
28
+ (expression_statement
29
+ (call_expression) @indent.begin)
30
+
31
+ (arrow_function
32
+ body: (_) @_body
33
+ (#not-kind-eq? @_body "statement_block")) @indent.begin
34
+
35
+ (assignment_expression
36
+ right: (_) @_right
37
+ (#not-kind-eq? @_right "arrow_function")) @indent.begin
38
+
39
+ (variable_declarator
40
+ value: (_) @_value
41
+ (#not-kind-eq? @_value "arrow_function" "call_expression")) @indent.begin
42
+
43
+ (arguments
44
+ ")" @indent.end)
45
+
46
+ (object
47
+ "}" @indent.end)
48
+
49
+ (statement_block
50
+ "}" @indent.end)
51
+
52
+ [
53
+ (arguments
54
+ (object))
55
+ ")"
56
+ "}"
57
+ "]"
58
+ ] @indent.branch
59
+
60
+ (statement_block
61
+ "{" @indent.branch)
62
+
63
+ ((parenthesized_expression
64
+ "("
65
+ (_)
66
+ ")" @indent.end) @_outer
67
+ (#not-has-parent? @_outer if_statement))
68
+
69
+ [
70
+ "}"
71
+ "]"
72
+ ] @indent.end
73
+
74
+ (template_string) @indent.ignore
75
+
76
+ [
77
+ (comment)
78
+ (ERROR)
79
+ ] @indent.auto
80
+
81
+ (if_statement
82
+ consequence: (_) @indent.dedent
83
+ (#not-kind-eq? @indent.dedent statement_block)) @indent.begin
84
+
85
+ ; inherited from jsx
86
+ [
87
+ (jsx_element)
88
+ (jsx_self_closing_element)
89
+ (jsx_expression)
90
+ ] @indent.begin
91
+
92
+ (jsx_closing_element
93
+ ">" @indent.end)
94
+
95
+ (jsx_self_closing_element
96
+ "/>" @indent.end)
97
+
98
+ [
99
+ (jsx_closing_element)
100
+ ">"
101
+ ] @indent.branch
102
+
103
+ ; <button
104
+ ; />
105
+ (jsx_self_closing_element
106
+ "/>" @indent.branch)
107
+
@@ -0,0 +1,234 @@
1
+ ; inherited from ecma
2
+ (((comment) @_jsdoc_comment
3
+ (#match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content
4
+ (#set! injection.language "jsdoc"))
5
+
6
+ ((comment) @injection.content
7
+ (#set! injection.language "comment"))
8
+
9
+ ; html(`...`), html`...`, sql(`...`), etc.
10
+ (call_expression
11
+ function: (identifier) @injection.language
12
+ arguments: [
13
+ (arguments
14
+ (template_string) @injection.content)
15
+ (template_string) @injection.content
16
+ ]
17
+ (#match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
18
+ (#offset! @injection.content 0 1 0 -1)
19
+ (#set! injection.include-children)
20
+ ; Languages excluded from auto-injection due to special rules
21
+ ; - svg uses the html parser
22
+ ; - css uses the styled parser
23
+ (#not-any-of? @injection.language "svg" "css"))
24
+
25
+ ; svg`...` or svg(`...`)
26
+ (call_expression
27
+ function: (identifier) @_name
28
+ (#eq? @_name "svg")
29
+ arguments: [
30
+ (arguments
31
+ (template_string) @injection.content)
32
+ (template_string) @injection.content
33
+ ]
34
+ (#offset! @injection.content 0 1 0 -1)
35
+ (#set! injection.include-children)
36
+ (#set! injection.language "html"))
37
+
38
+ ; Vercel PostgreSQL
39
+ ; foo.sql`...` or foo.sql(`...`)
40
+ (call_expression
41
+ function: (member_expression
42
+ property: (property_identifier) @injection.language)
43
+ arguments: [
44
+ (arguments
45
+ (template_string) @injection.content)
46
+ (template_string) @injection.content
47
+ ]
48
+ (#eq? @injection.language "sql")
49
+ (#offset! @injection.content 0 1 0 -1)
50
+ (#set! injection.include-children))
51
+
52
+ ; Sanity CMS GROQ query
53
+ ; defineQuery(`...`)
54
+ (call_expression
55
+ function: (identifier) @_name
56
+ (#eq? @_name "defineQuery")
57
+ arguments: (arguments
58
+ (template_string) @injection.content)
59
+ (#offset! @injection.content 0 1 0 -1)
60
+ (#set! injection.include-children)
61
+ (#set! injection.language "groq"))
62
+
63
+ ; gql`...` or gql(`...`)
64
+ (call_expression
65
+ function: (identifier) @_name
66
+ (#eq? @_name "gql")
67
+ arguments: [
68
+ (arguments
69
+ (template_string) @injection.content)
70
+ (template_string) @injection.content
71
+ ]
72
+ (#offset! @injection.content 0 1 0 -1)
73
+ (#set! injection.include-children)
74
+ (#set! injection.language "graphql"))
75
+
76
+ (call_expression
77
+ function: (identifier) @_name
78
+ (#eq? @_name "hbs")
79
+ arguments: (template_string) @injection.content
80
+ (#offset! @injection.content 0 1 0 -1)
81
+ (#set! injection.include-children)
82
+ (#set! injection.language "glimmer"))
83
+
84
+ ; css`<css>`, keyframes`<css>`
85
+ (call_expression
86
+ function: (identifier) @_name
87
+ (#any-of? @_name "css" "keyframes")
88
+ arguments: (template_string) @injection.content
89
+ (#offset! @injection.content 0 1 0 -1)
90
+ (#set! injection.include-children)
91
+ (#set! injection.language "styled"))
92
+
93
+ ; styled.div`<css>`
94
+ (call_expression
95
+ function: (member_expression
96
+ object: (identifier) @_name
97
+ (#eq? @_name "styled"))
98
+ arguments: ((template_string) @injection.content
99
+ (#offset! @injection.content 0 1 0 -1)
100
+ (#set! injection.include-children)
101
+ (#set! injection.language "styled")))
102
+
103
+ ; styled(Component)`<css>`
104
+ (call_expression
105
+ function: (call_expression
106
+ function: (identifier) @_name
107
+ (#eq? @_name "styled"))
108
+ arguments: ((template_string) @injection.content
109
+ (#offset! @injection.content 0 1 0 -1)
110
+ (#set! injection.include-children)
111
+ (#set! injection.language "styled")))
112
+
113
+ ; styled.div.attrs({ prop: "foo" })`<css>`
114
+ (call_expression
115
+ function: (call_expression
116
+ function: (member_expression
117
+ object: (member_expression
118
+ object: (identifier) @_name
119
+ (#eq? @_name "styled"))))
120
+ arguments: ((template_string) @injection.content
121
+ (#offset! @injection.content 0 1 0 -1)
122
+ (#set! injection.include-children)
123
+ (#set! injection.language "styled")))
124
+
125
+ ; styled(Component).attrs({ prop: "foo" })`<css>`
126
+ (call_expression
127
+ function: (call_expression
128
+ function: (member_expression
129
+ object: (call_expression
130
+ function: (identifier) @_name
131
+ (#eq? @_name "styled"))))
132
+ arguments: ((template_string) @injection.content
133
+ (#offset! @injection.content 0 1 0 -1)
134
+ (#set! injection.include-children)
135
+ (#set! injection.language "styled")))
136
+
137
+ ((regex_pattern) @injection.content
138
+ (#set! injection.language "regex"))
139
+
140
+ ; ((comment) @_gql_comment
141
+ ; (#eq? @_gql_comment "/* GraphQL */")
142
+ ; (template_string) @injection.content
143
+ ; (#set! injection.language "graphql"))
144
+ ((template_string) @injection.content
145
+ (#match? @injection.content "^`#graphql")
146
+ (#offset! @injection.content 0 1 0 -1)
147
+ (#set! injection.include-children)
148
+ (#set! injection.language "graphql"))
149
+
150
+ ; el.innerHTML = `<html>`
151
+ (assignment_expression
152
+ left: (member_expression
153
+ property: (property_identifier) @_prop
154
+ (#any-of? @_prop "outerHTML" "innerHTML"))
155
+ right: (template_string) @injection.content
156
+ (#offset! @injection.content 0 1 0 -1)
157
+ (#set! injection.include-children)
158
+ (#set! injection.language "html"))
159
+
160
+ ; el.innerHTML = '<html>'
161
+ (assignment_expression
162
+ left: (member_expression
163
+ property: (property_identifier) @_prop
164
+ (#any-of? @_prop "outerHTML" "innerHTML"))
165
+ right: (string
166
+ (string_fragment) @injection.content)
167
+ (#set! injection.language "html"))
168
+
169
+ ;---- Angular injections -----
170
+ ; @Component({
171
+ ; template: `<html>`
172
+ ; })
173
+ (decorator
174
+ (call_expression
175
+ function: ((identifier) @_name
176
+ (#eq? @_name "Component"))
177
+ arguments: (arguments
178
+ (object
179
+ (pair
180
+ key: ((property_identifier) @_prop
181
+ (#eq? @_prop "template"))
182
+ value: ((template_string) @injection.content
183
+ (#offset! @injection.content 0 1 0 -1)
184
+ (#set! injection.include-children)
185
+ (#set! injection.language "angular")))))))
186
+
187
+ ; @Component({
188
+ ; styles: [`<css>`]
189
+ ; })
190
+ (decorator
191
+ (call_expression
192
+ function: ((identifier) @_name
193
+ (#eq? @_name "Component"))
194
+ arguments: (arguments
195
+ (object
196
+ (pair
197
+ key: ((property_identifier) @_prop
198
+ (#eq? @_prop "styles"))
199
+ value: (array
200
+ ((template_string) @injection.content
201
+ (#offset! @injection.content 0 1 0 -1)
202
+ (#set! injection.include-children)
203
+ (#set! injection.language "css"))))))))
204
+
205
+ ; @Component({
206
+ ; styles: `<css>`
207
+ ; })
208
+ (decorator
209
+ (call_expression
210
+ function: ((identifier) @_name
211
+ (#eq? @_name "Component"))
212
+ arguments: (arguments
213
+ (object
214
+ (pair
215
+ key: ((property_identifier) @_prop
216
+ (#eq? @_prop "styles"))
217
+ value: ((template_string) @injection.content
218
+ (#set! injection.include-children)
219
+ (#offset! @injection.content 0 1 0 -1)
220
+ (#set! injection.language "css")))))))
221
+
222
+ ; inherited from jsx
223
+ ; Styled Jsx <style jsx>
224
+ (jsx_element
225
+ (jsx_opening_element
226
+ (identifier) @_name
227
+ (#eq? @_name "style")
228
+ (jsx_attribute) @_attr
229
+ (#eq? @_attr "jsx"))
230
+ (jsx_expression
231
+ ((template_string) @injection.content
232
+ (#set! injection.language "css"))
233
+ (#offset! @injection.content 0 1 0 -1)))
234
+
@@ -0,0 +1,121 @@
1
+ ; inherited from ecma
2
+ ; Scopes
3
+ ;-------
4
+ (statement_block) @local.scope
5
+
6
+ (function_expression) @local.scope
7
+
8
+ (arrow_function) @local.scope
9
+
10
+ (function_declaration) @local.scope
11
+
12
+ (method_definition) @local.scope
13
+
14
+ (for_statement) @local.scope
15
+
16
+ (for_in_statement) @local.scope
17
+
18
+ (catch_clause) @local.scope
19
+
20
+ ; Definitions
21
+ ;------------
22
+ (variable_declarator
23
+ name: (identifier) @local.definition.var)
24
+
25
+ (variable_declarator
26
+ name: (object_pattern
27
+ (shorthand_property_identifier_pattern) @local.definition.var))
28
+
29
+ (variable_declarator
30
+ (object_pattern
31
+ (pair_pattern
32
+ (identifier) @local.definition.var)))
33
+
34
+ (import_specifier
35
+ (identifier) @local.definition.import)
36
+
37
+ (namespace_import
38
+ (identifier) @local.definition.import)
39
+
40
+ (function_declaration
41
+ (identifier) @local.definition.function
42
+ (#set! definition.var.scope parent))
43
+
44
+ (method_definition
45
+ (property_identifier) @local.definition.function
46
+ (#set! definition.var.scope parent))
47
+
48
+ ; References
49
+ ;------------
50
+ (identifier) @local.reference
51
+
52
+ (shorthand_property_identifier) @local.reference
53
+
54
+
55
+ ; Both properties are matched here.
56
+ ;
57
+ ; class Foo {
58
+ ; this.#bar = "baz";
59
+ ; this.quuz = "qux";
60
+ ; }
61
+ (field_definition
62
+ property: [
63
+ (property_identifier)
64
+ (private_property_identifier)
65
+ ] @local.definition.var)
66
+
67
+ ; this.foo = "bar"
68
+ (assignment_expression
69
+ left: (member_expression
70
+ object: (this)
71
+ property: (property_identifier) @local.definition.var))
72
+
73
+ (formal_parameters
74
+ (identifier) @local.definition.parameter)
75
+
76
+ ; function(arg = []) {
77
+ (formal_parameters
78
+ (assignment_pattern
79
+ left: (identifier) @local.definition.parameter))
80
+
81
+ ; x => x
82
+ (arrow_function
83
+ parameter: (identifier) @local.definition.parameter)
84
+
85
+ ; ({ a }) => null
86
+ (formal_parameters
87
+ (object_pattern
88
+ (shorthand_property_identifier_pattern) @local.definition.parameter))
89
+
90
+ ; ({ a: b }) => null
91
+ (formal_parameters
92
+ (object_pattern
93
+ (pair_pattern
94
+ value: (identifier) @local.definition.parameter)))
95
+
96
+ ; ([ a ]) => null
97
+ (formal_parameters
98
+ (array_pattern
99
+ (identifier) @local.definition.parameter))
100
+
101
+ (formal_parameters
102
+ (rest_pattern
103
+ (identifier) @local.definition.parameter))
104
+
105
+ ; Both methods are matched here.
106
+ ;
107
+ ; class Foo {
108
+ ; #bar(x) { x }
109
+ ; baz(y) { y }
110
+ ; }
111
+ (method_definition
112
+ [
113
+ (property_identifier)
114
+ (private_property_identifier)
115
+ ] @local.definition.function
116
+ (#set! definition.var.scope parent))
117
+
118
+ ; this.foo()
119
+ (member_expression
120
+ object: (this)
121
+ property: (property_identifier) @local.reference)
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export const javascript = 'javascript' as const;