react-native-codepad-lang-tsx 0.0.0-stage → 0.1.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/CodepadLangTsx.podspec +28 -0
- package/README.md +80 -2
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +61 -0
- package/android/consumer-rules.pro +1 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/assets/codepad-languages/tsx +1 -0
- package/android/src/main/cpp/lang.c +10 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/tsx/CodepadLangTsxPackage.kt +13 -0
- package/android/src/main/java/me/sectiontn/codepad/lang/tsx/TsxLanguage.kt +1046 -0
- package/grammar/LICENSE +21 -0
- package/grammar/common/scanner.h +347 -0
- package/grammar/tsx/src/parser.c +282955 -0
- package/grammar/tsx/src/scanner.c +13 -0
- package/grammar/tsx/src/tree_sitter/alloc.h +54 -0
- package/grammar/tsx/src/tree_sitter/array.h +290 -0
- package/grammar/tsx/src/tree_sitter/parser.h +266 -0
- package/ios/CPLangTsx.h +11 -0
- package/ios/CPLangTsx.swift +1039 -0
- package/package.json +40 -4
- package/queries/tsx/highlights.scm +762 -0
- package/queries/tsx/indents.scm +115 -0
- package/queries/tsx/injections.scm +263 -0
- package/queries/tsx/locals.scm +85 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
; inherited from typescript
|
|
2
|
+
; inherited from ecma
|
|
3
|
+
[
|
|
4
|
+
(arguments)
|
|
5
|
+
(array)
|
|
6
|
+
(binary_expression)
|
|
7
|
+
(class_body)
|
|
8
|
+
(export_clause)
|
|
9
|
+
(formal_parameters)
|
|
10
|
+
(named_imports)
|
|
11
|
+
(object)
|
|
12
|
+
(object_pattern)
|
|
13
|
+
(parenthesized_expression)
|
|
14
|
+
(return_statement)
|
|
15
|
+
(statement_block)
|
|
16
|
+
(switch_case)
|
|
17
|
+
(switch_default)
|
|
18
|
+
(switch_statement)
|
|
19
|
+
(template_substitution)
|
|
20
|
+
(ternary_expression)
|
|
21
|
+
] @indent.begin
|
|
22
|
+
|
|
23
|
+
(arguments
|
|
24
|
+
(call_expression) @indent.begin)
|
|
25
|
+
|
|
26
|
+
(binary_expression
|
|
27
|
+
(call_expression) @indent.begin)
|
|
28
|
+
|
|
29
|
+
(expression_statement
|
|
30
|
+
(call_expression) @indent.begin)
|
|
31
|
+
|
|
32
|
+
(arrow_function
|
|
33
|
+
body: (_) @_body
|
|
34
|
+
(#not-kind-eq? @_body "statement_block")) @indent.begin
|
|
35
|
+
|
|
36
|
+
(assignment_expression
|
|
37
|
+
right: (_) @_right
|
|
38
|
+
(#not-kind-eq? @_right "arrow_function")) @indent.begin
|
|
39
|
+
|
|
40
|
+
(variable_declarator
|
|
41
|
+
value: (_) @_value
|
|
42
|
+
(#not-kind-eq? @_value "arrow_function" "call_expression")) @indent.begin
|
|
43
|
+
|
|
44
|
+
(arguments
|
|
45
|
+
")" @indent.end)
|
|
46
|
+
|
|
47
|
+
(object
|
|
48
|
+
"}" @indent.end)
|
|
49
|
+
|
|
50
|
+
(statement_block
|
|
51
|
+
"}" @indent.end)
|
|
52
|
+
|
|
53
|
+
[
|
|
54
|
+
(arguments
|
|
55
|
+
(object))
|
|
56
|
+
")"
|
|
57
|
+
"}"
|
|
58
|
+
"]"
|
|
59
|
+
] @indent.branch
|
|
60
|
+
|
|
61
|
+
(statement_block
|
|
62
|
+
"{" @indent.branch)
|
|
63
|
+
|
|
64
|
+
((parenthesized_expression
|
|
65
|
+
"("
|
|
66
|
+
(_)
|
|
67
|
+
")" @indent.end) @_outer
|
|
68
|
+
(#not-has-parent? @_outer if_statement))
|
|
69
|
+
|
|
70
|
+
[
|
|
71
|
+
"}"
|
|
72
|
+
"]"
|
|
73
|
+
] @indent.end
|
|
74
|
+
|
|
75
|
+
(template_string) @indent.ignore
|
|
76
|
+
|
|
77
|
+
[
|
|
78
|
+
(comment)
|
|
79
|
+
(ERROR)
|
|
80
|
+
] @indent.auto
|
|
81
|
+
|
|
82
|
+
(if_statement
|
|
83
|
+
consequence: (_) @indent.dedent
|
|
84
|
+
(#not-kind-eq? @indent.dedent statement_block)) @indent.begin
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
[
|
|
88
|
+
(enum_declaration)
|
|
89
|
+
(interface_declaration)
|
|
90
|
+
(object_type)
|
|
91
|
+
] @indent.begin
|
|
92
|
+
|
|
93
|
+
; inherited from jsx
|
|
94
|
+
[
|
|
95
|
+
(jsx_element)
|
|
96
|
+
(jsx_self_closing_element)
|
|
97
|
+
(jsx_expression)
|
|
98
|
+
] @indent.begin
|
|
99
|
+
|
|
100
|
+
(jsx_closing_element
|
|
101
|
+
">" @indent.end)
|
|
102
|
+
|
|
103
|
+
(jsx_self_closing_element
|
|
104
|
+
"/>" @indent.end)
|
|
105
|
+
|
|
106
|
+
[
|
|
107
|
+
(jsx_closing_element)
|
|
108
|
+
">"
|
|
109
|
+
] @indent.branch
|
|
110
|
+
|
|
111
|
+
; <button
|
|
112
|
+
; />
|
|
113
|
+
(jsx_self_closing_element
|
|
114
|
+
"/>" @indent.branch)
|
|
115
|
+
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
; inherited from typescript
|
|
2
|
+
; inherited from ecma
|
|
3
|
+
(((comment) @_jsdoc_comment
|
|
4
|
+
(#match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content
|
|
5
|
+
(#set! injection.language "jsdoc"))
|
|
6
|
+
|
|
7
|
+
((comment) @injection.content
|
|
8
|
+
(#set! injection.language "comment"))
|
|
9
|
+
|
|
10
|
+
; html(`...`), html`...`, sql(`...`), etc.
|
|
11
|
+
(call_expression
|
|
12
|
+
function: (identifier) @injection.language
|
|
13
|
+
arguments: [
|
|
14
|
+
(arguments
|
|
15
|
+
(template_string) @injection.content)
|
|
16
|
+
(template_string) @injection.content
|
|
17
|
+
]
|
|
18
|
+
(#match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
|
|
19
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
20
|
+
(#set! injection.include-children)
|
|
21
|
+
; Languages excluded from auto-injection due to special rules
|
|
22
|
+
; - svg uses the html parser
|
|
23
|
+
; - css uses the styled parser
|
|
24
|
+
(#not-any-of? @injection.language "svg" "css"))
|
|
25
|
+
|
|
26
|
+
; svg`...` or svg(`...`)
|
|
27
|
+
(call_expression
|
|
28
|
+
function: (identifier) @_name
|
|
29
|
+
(#eq? @_name "svg")
|
|
30
|
+
arguments: [
|
|
31
|
+
(arguments
|
|
32
|
+
(template_string) @injection.content)
|
|
33
|
+
(template_string) @injection.content
|
|
34
|
+
]
|
|
35
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
36
|
+
(#set! injection.include-children)
|
|
37
|
+
(#set! injection.language "html"))
|
|
38
|
+
|
|
39
|
+
; Vercel PostgreSQL
|
|
40
|
+
; foo.sql`...` or foo.sql(`...`)
|
|
41
|
+
(call_expression
|
|
42
|
+
function: (member_expression
|
|
43
|
+
property: (property_identifier) @injection.language)
|
|
44
|
+
arguments: [
|
|
45
|
+
(arguments
|
|
46
|
+
(template_string) @injection.content)
|
|
47
|
+
(template_string) @injection.content
|
|
48
|
+
]
|
|
49
|
+
(#eq? @injection.language "sql")
|
|
50
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
51
|
+
(#set! injection.include-children))
|
|
52
|
+
|
|
53
|
+
; Sanity CMS GROQ query
|
|
54
|
+
; defineQuery(`...`)
|
|
55
|
+
(call_expression
|
|
56
|
+
function: (identifier) @_name
|
|
57
|
+
(#eq? @_name "defineQuery")
|
|
58
|
+
arguments: (arguments
|
|
59
|
+
(template_string) @injection.content)
|
|
60
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
61
|
+
(#set! injection.include-children)
|
|
62
|
+
(#set! injection.language "groq"))
|
|
63
|
+
|
|
64
|
+
; gql`...` or gql(`...`)
|
|
65
|
+
(call_expression
|
|
66
|
+
function: (identifier) @_name
|
|
67
|
+
(#eq? @_name "gql")
|
|
68
|
+
arguments: [
|
|
69
|
+
(arguments
|
|
70
|
+
(template_string) @injection.content)
|
|
71
|
+
(template_string) @injection.content
|
|
72
|
+
]
|
|
73
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
74
|
+
(#set! injection.include-children)
|
|
75
|
+
(#set! injection.language "graphql"))
|
|
76
|
+
|
|
77
|
+
(call_expression
|
|
78
|
+
function: (identifier) @_name
|
|
79
|
+
(#eq? @_name "hbs")
|
|
80
|
+
arguments: (template_string) @injection.content
|
|
81
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
82
|
+
(#set! injection.include-children)
|
|
83
|
+
(#set! injection.language "glimmer"))
|
|
84
|
+
|
|
85
|
+
; css`<css>`, keyframes`<css>`
|
|
86
|
+
(call_expression
|
|
87
|
+
function: (identifier) @_name
|
|
88
|
+
(#any-of? @_name "css" "keyframes")
|
|
89
|
+
arguments: (template_string) @injection.content
|
|
90
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
91
|
+
(#set! injection.include-children)
|
|
92
|
+
(#set! injection.language "styled"))
|
|
93
|
+
|
|
94
|
+
; styled.div`<css>`
|
|
95
|
+
(call_expression
|
|
96
|
+
function: (member_expression
|
|
97
|
+
object: (identifier) @_name
|
|
98
|
+
(#eq? @_name "styled"))
|
|
99
|
+
arguments: ((template_string) @injection.content
|
|
100
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
101
|
+
(#set! injection.include-children)
|
|
102
|
+
(#set! injection.language "styled")))
|
|
103
|
+
|
|
104
|
+
; styled(Component)`<css>`
|
|
105
|
+
(call_expression
|
|
106
|
+
function: (call_expression
|
|
107
|
+
function: (identifier) @_name
|
|
108
|
+
(#eq? @_name "styled"))
|
|
109
|
+
arguments: ((template_string) @injection.content
|
|
110
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
111
|
+
(#set! injection.include-children)
|
|
112
|
+
(#set! injection.language "styled")))
|
|
113
|
+
|
|
114
|
+
; styled.div.attrs({ prop: "foo" })`<css>`
|
|
115
|
+
(call_expression
|
|
116
|
+
function: (call_expression
|
|
117
|
+
function: (member_expression
|
|
118
|
+
object: (member_expression
|
|
119
|
+
object: (identifier) @_name
|
|
120
|
+
(#eq? @_name "styled"))))
|
|
121
|
+
arguments: ((template_string) @injection.content
|
|
122
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
123
|
+
(#set! injection.include-children)
|
|
124
|
+
(#set! injection.language "styled")))
|
|
125
|
+
|
|
126
|
+
; styled(Component).attrs({ prop: "foo" })`<css>`
|
|
127
|
+
(call_expression
|
|
128
|
+
function: (call_expression
|
|
129
|
+
function: (member_expression
|
|
130
|
+
object: (call_expression
|
|
131
|
+
function: (identifier) @_name
|
|
132
|
+
(#eq? @_name "styled"))))
|
|
133
|
+
arguments: ((template_string) @injection.content
|
|
134
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
135
|
+
(#set! injection.include-children)
|
|
136
|
+
(#set! injection.language "styled")))
|
|
137
|
+
|
|
138
|
+
((regex_pattern) @injection.content
|
|
139
|
+
(#set! injection.language "regex"))
|
|
140
|
+
|
|
141
|
+
; ((comment) @_gql_comment
|
|
142
|
+
; (#eq? @_gql_comment "/* GraphQL */")
|
|
143
|
+
; (template_string) @injection.content
|
|
144
|
+
; (#set! injection.language "graphql"))
|
|
145
|
+
((template_string) @injection.content
|
|
146
|
+
(#match? @injection.content "^`#graphql")
|
|
147
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
148
|
+
(#set! injection.include-children)
|
|
149
|
+
(#set! injection.language "graphql"))
|
|
150
|
+
|
|
151
|
+
; el.innerHTML = `<html>`
|
|
152
|
+
(assignment_expression
|
|
153
|
+
left: (member_expression
|
|
154
|
+
property: (property_identifier) @_prop
|
|
155
|
+
(#any-of? @_prop "outerHTML" "innerHTML"))
|
|
156
|
+
right: (template_string) @injection.content
|
|
157
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
158
|
+
(#set! injection.include-children)
|
|
159
|
+
(#set! injection.language "html"))
|
|
160
|
+
|
|
161
|
+
; el.innerHTML = '<html>'
|
|
162
|
+
(assignment_expression
|
|
163
|
+
left: (member_expression
|
|
164
|
+
property: (property_identifier) @_prop
|
|
165
|
+
(#any-of? @_prop "outerHTML" "innerHTML"))
|
|
166
|
+
right: (string
|
|
167
|
+
(string_fragment) @injection.content)
|
|
168
|
+
(#set! injection.language "html"))
|
|
169
|
+
|
|
170
|
+
;---- Angular injections -----
|
|
171
|
+
; @Component({
|
|
172
|
+
; template: `<html>`
|
|
173
|
+
; })
|
|
174
|
+
(decorator
|
|
175
|
+
(call_expression
|
|
176
|
+
function: ((identifier) @_name
|
|
177
|
+
(#eq? @_name "Component"))
|
|
178
|
+
arguments: (arguments
|
|
179
|
+
(object
|
|
180
|
+
(pair
|
|
181
|
+
key: ((property_identifier) @_prop
|
|
182
|
+
(#eq? @_prop "template"))
|
|
183
|
+
value: ((template_string) @injection.content
|
|
184
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
185
|
+
(#set! injection.include-children)
|
|
186
|
+
(#set! injection.language "angular")))))))
|
|
187
|
+
|
|
188
|
+
; @Component({
|
|
189
|
+
; styles: [`<css>`]
|
|
190
|
+
; })
|
|
191
|
+
(decorator
|
|
192
|
+
(call_expression
|
|
193
|
+
function: ((identifier) @_name
|
|
194
|
+
(#eq? @_name "Component"))
|
|
195
|
+
arguments: (arguments
|
|
196
|
+
(object
|
|
197
|
+
(pair
|
|
198
|
+
key: ((property_identifier) @_prop
|
|
199
|
+
(#eq? @_prop "styles"))
|
|
200
|
+
value: (array
|
|
201
|
+
((template_string) @injection.content
|
|
202
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
203
|
+
(#set! injection.include-children)
|
|
204
|
+
(#set! injection.language "css"))))))))
|
|
205
|
+
|
|
206
|
+
; @Component({
|
|
207
|
+
; styles: `<css>`
|
|
208
|
+
; })
|
|
209
|
+
(decorator
|
|
210
|
+
(call_expression
|
|
211
|
+
function: ((identifier) @_name
|
|
212
|
+
(#eq? @_name "Component"))
|
|
213
|
+
arguments: (arguments
|
|
214
|
+
(object
|
|
215
|
+
(pair
|
|
216
|
+
key: ((property_identifier) @_prop
|
|
217
|
+
(#eq? @_prop "styles"))
|
|
218
|
+
value: ((template_string) @injection.content
|
|
219
|
+
(#set! injection.include-children)
|
|
220
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
221
|
+
(#set! injection.language "css")))))))
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
; styled.div<{}>`<css>`
|
|
225
|
+
(call_expression
|
|
226
|
+
function: (non_null_expression
|
|
227
|
+
(instantiation_expression
|
|
228
|
+
(member_expression
|
|
229
|
+
object: (identifier) @_name
|
|
230
|
+
(#eq? @_name "styled")
|
|
231
|
+
property: (property_identifier))
|
|
232
|
+
type_arguments: (type_arguments)))
|
|
233
|
+
arguments: ((template_string) @injection.content
|
|
234
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
235
|
+
(#set! injection.include-children)
|
|
236
|
+
(#set! injection.language "styled")))
|
|
237
|
+
|
|
238
|
+
; styled.div<T>`<css>`
|
|
239
|
+
(binary_expression
|
|
240
|
+
left: (binary_expression
|
|
241
|
+
left: (member_expression
|
|
242
|
+
object: (identifier) @_name
|
|
243
|
+
(#eq? @_name "styled")
|
|
244
|
+
property: (property_identifier))
|
|
245
|
+
right: (identifier))
|
|
246
|
+
right: (template_string) @injection.content
|
|
247
|
+
(#offset! @injection.content 0 1 0 -1)
|
|
248
|
+
(#set! injection.include-children)
|
|
249
|
+
(#set! injection.language "styled"))
|
|
250
|
+
|
|
251
|
+
; inherited from jsx
|
|
252
|
+
; Styled Jsx <style jsx>
|
|
253
|
+
(jsx_element
|
|
254
|
+
(jsx_opening_element
|
|
255
|
+
(identifier) @_name
|
|
256
|
+
(#eq? @_name "style")
|
|
257
|
+
(jsx_attribute) @_attr
|
|
258
|
+
(#eq? @_attr "jsx"))
|
|
259
|
+
(jsx_expression
|
|
260
|
+
((template_string) @injection.content
|
|
261
|
+
(#set! injection.language "css"))
|
|
262
|
+
(#offset! @injection.content 0 1 0 -1)))
|
|
263
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
; inherited from typescript
|
|
2
|
+
; inherited from ecma
|
|
3
|
+
; Scopes
|
|
4
|
+
;-------
|
|
5
|
+
(statement_block) @local.scope
|
|
6
|
+
|
|
7
|
+
(function_expression) @local.scope
|
|
8
|
+
|
|
9
|
+
(arrow_function) @local.scope
|
|
10
|
+
|
|
11
|
+
(function_declaration) @local.scope
|
|
12
|
+
|
|
13
|
+
(method_definition) @local.scope
|
|
14
|
+
|
|
15
|
+
(for_statement) @local.scope
|
|
16
|
+
|
|
17
|
+
(for_in_statement) @local.scope
|
|
18
|
+
|
|
19
|
+
(catch_clause) @local.scope
|
|
20
|
+
|
|
21
|
+
; Definitions
|
|
22
|
+
;------------
|
|
23
|
+
(variable_declarator
|
|
24
|
+
name: (identifier) @local.definition.var)
|
|
25
|
+
|
|
26
|
+
(variable_declarator
|
|
27
|
+
name: (object_pattern
|
|
28
|
+
(shorthand_property_identifier_pattern) @local.definition.var))
|
|
29
|
+
|
|
30
|
+
(variable_declarator
|
|
31
|
+
(object_pattern
|
|
32
|
+
(pair_pattern
|
|
33
|
+
(identifier) @local.definition.var)))
|
|
34
|
+
|
|
35
|
+
(import_specifier
|
|
36
|
+
(identifier) @local.definition.import)
|
|
37
|
+
|
|
38
|
+
(namespace_import
|
|
39
|
+
(identifier) @local.definition.import)
|
|
40
|
+
|
|
41
|
+
(function_declaration
|
|
42
|
+
(identifier) @local.definition.function
|
|
43
|
+
(#set! definition.var.scope parent))
|
|
44
|
+
|
|
45
|
+
(method_definition
|
|
46
|
+
(property_identifier) @local.definition.function
|
|
47
|
+
(#set! definition.var.scope parent))
|
|
48
|
+
|
|
49
|
+
; References
|
|
50
|
+
;------------
|
|
51
|
+
(identifier) @local.reference
|
|
52
|
+
|
|
53
|
+
(shorthand_property_identifier) @local.reference
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
(required_parameter
|
|
57
|
+
(identifier) @local.definition)
|
|
58
|
+
|
|
59
|
+
(optional_parameter
|
|
60
|
+
(identifier) @local.definition)
|
|
61
|
+
|
|
62
|
+
; x => x
|
|
63
|
+
(arrow_function
|
|
64
|
+
parameter: (identifier) @local.definition.parameter)
|
|
65
|
+
|
|
66
|
+
; ({ a }) => null
|
|
67
|
+
(required_parameter
|
|
68
|
+
(object_pattern
|
|
69
|
+
(shorthand_property_identifier_pattern) @local.definition.parameter))
|
|
70
|
+
|
|
71
|
+
; ({ a: b }) => null
|
|
72
|
+
(required_parameter
|
|
73
|
+
(object_pattern
|
|
74
|
+
(pair_pattern
|
|
75
|
+
value: (identifier) @local.definition.parameter)))
|
|
76
|
+
|
|
77
|
+
; ([ a ]) => null
|
|
78
|
+
(required_parameter
|
|
79
|
+
(array_pattern
|
|
80
|
+
(identifier) @local.definition.parameter))
|
|
81
|
+
|
|
82
|
+
(required_parameter
|
|
83
|
+
(rest_pattern
|
|
84
|
+
(identifier) @local.definition.parameter))
|
|
85
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const tsx = 'tsx' as const;
|