Skip to content

Commit 205abe7

Browse files
author
deathaxe
committed
Add support for JSX/TSX scripts
Resolves #3
1 parent c02d398 commit 205abe7

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

Vue Component.sublime-syntax

+56
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ contexts:
117117
- script-coffeescript
118118
- tag-lang-attribute-meta
119119
- tag-generic-attribute-value
120+
- match: (?i)(?=jsx{{unquoted_attribute_break}}|'jsx'|"jsx")
121+
set:
122+
- script-jsx
123+
- tag-lang-attribute-meta
124+
- tag-generic-attribute-value
120125
- match: (?i)(?=livescript{{unquoted_attribute_break}}|'livescript'|"livescript")
121126
set:
122127
- script-livescript
@@ -127,6 +132,11 @@ contexts:
127132
- script-typescript
128133
- tag-lang-attribute-meta
129134
- tag-generic-attribute-value
135+
- match: (?i)(?=tsx{{unquoted_attribute_break}}|'tsx'|"tsx")
136+
set:
137+
- script-tsx
138+
- tag-lang-attribute-meta
139+
- tag-generic-attribute-value
130140
- match: (?=\S)
131141
set:
132142
- script-javascript
@@ -203,6 +213,29 @@ contexts:
203213
3: source.js.embedded.html
204214
4: comment.block.html punctuation.definition.comment.end.html
205215

216+
script-jsx:
217+
- meta_include_prototype: false
218+
- meta_scope: meta.tag.script.begin.html
219+
- match: '>'
220+
scope: punctuation.definition.tag.end.html
221+
set: script-jsx-content
222+
- include: script-common
223+
224+
script-jsx-content:
225+
- meta_include_prototype: false
226+
- match: '{{script_content_begin}}'
227+
captures:
228+
1: comment.block.html punctuation.definition.comment.begin.html
229+
pop: 1 # make sure to match only once
230+
embed: scope:source.jsx
231+
embed_scope: source.jsx.embedded.html
232+
escape: '{{script_content_end}}'
233+
escape_captures:
234+
1: source.jsx.embedded.html
235+
2: comment.block.html punctuation.definition.comment.end.html
236+
3: source.jsx.embedded.html
237+
4: comment.block.html punctuation.definition.comment.end.html
238+
206239
script-livescript:
207240
- meta_include_prototype: false
208241
- meta_scope: meta.tag.script.begin.html
@@ -226,6 +259,29 @@ contexts:
226259
3: source.livescript.embedded.html
227260
4: comment.block.html punctuation.definition.comment.end.html
228261

262+
script-tsx:
263+
- meta_include_prototype: false
264+
- meta_scope: meta.tag.script.begin.html
265+
- match: '>'
266+
scope: punctuation.definition.tag.end.html
267+
set: script-tsx-content
268+
- include: script-common
269+
270+
script-tsx-content:
271+
- meta_include_prototype: false
272+
- match: '{{script_content_begin}}'
273+
captures:
274+
1: comment.block.html punctuation.definition.comment.begin.html
275+
pop: 1 # make sure to match only once
276+
embed: scope:source.tsx
277+
embed_scope: source.tsx.embedded.html
278+
escape: '{{script_content_end}}'
279+
escape_captures:
280+
1: source.tsx.embedded.html
281+
2: comment.block.html punctuation.definition.comment.end.html
282+
3: source.tsx.embedded.html
283+
4: comment.block.html punctuation.definition.comment.end.html
284+
229285
script-typescript:
230286
- meta_include_prototype: false
231287
- meta_scope: meta.tag.script.begin.html

tests/syntax_test_script.vue

+43
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,27 @@
166166
//^^ - source - comment - meta.tag
167167
// ^^^^^^^^^ meta.tag - source
168168

169+
<script lang="jsx">
170+
171+
// <- source.jsx.embedded.html - source source
172+
</script>
173+
// <- source.jsx.embedded.html - source source
174+
//^^ source.jsx.embedded.html - source source
175+
// ^^^^^^^^^ meta.tag - source
176+
177+
<script lang="jsx">
178+
<!--
179+
// ^^^^^^^^^ - source
180+
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
181+
// ^ source.jsx.embedded.html - source source
182+
-->
183+
// ^^^^^ source.jsx.embedded.html - source source
184+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
185+
// ^ - source - comment - meta.tag
186+
</script>
187+
// <- - source - comment - meta.tag
188+
//^^ - source - comment - meta.tag
189+
// ^^^^^^^^^ meta.tag - source
169190

170191
<script lang="livescript">
171192

@@ -210,4 +231,26 @@
210231
</script>
211232
// <- - source - comment - meta.tag
212233
//^^ - source - comment - meta.tag
234+
// ^^^^^^^^^ meta.tag - source
235+
236+
<script lang="tsx">
237+
238+
// <- source.tsx.embedded.html - source source
239+
</script>
240+
// <- source.tsx.embedded.html - source source
241+
//^^ source.tsx.embedded.html - source source
242+
// ^^^^^^^^^ meta.tag - source
243+
244+
<script lang="tsx">
245+
<!--
246+
// ^^^^^^^^^ - source
247+
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
248+
// ^ source.tsx.embedded.html - source source
249+
-->
250+
// ^^^^^ source.tsx.embedded.html - source source
251+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
252+
// ^ - source - comment - meta.tag
253+
</script>
254+
// <- - source - comment - meta.tag
255+
//^^ - source - comment - meta.tag
213256
// ^^^^^^^^^ meta.tag - source

0 commit comments

Comments
 (0)