Skip to content

Commit dd9ca07

Browse files
authored
Fix script/style/template indentation (#10)
This commit 1. removes special treatment of html comments wrapping template content as this is supported by browsers primarily for legacy code. 2. makes syntax tests more lazy to avoid them fail across various ST versions. Vue completely relies on ST's indentation rules, which means it works best as of ST4180.
1 parent dfdc1ba commit dd9ca07

File tree

4 files changed

+168
-174
lines changed

4 files changed

+168
-174
lines changed

Vue Component.sublime-syntax

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ file_extensions:
1212
- wpy
1313

1414
variables:
15+
# CSS specific variables
16+
# ======================
17+
1518
# Embedded script and style syntaxes may be wrapped into html comments for
1619
# historical reasons. The following patterns match them, while maintaining
1720
# correct boundaries of embedded source scopes. That's required to enable
@@ -44,14 +47,12 @@ variables:
4447
# or standalone html comment end punctuation in a line
4548
| ^ (\s*) (-->) \s* $
4649
)
47-
template_content_begin: '{{script_content_begin}}'
48-
template_content_end: |-
49-
(?x:
50-
# optional html comment end punctuation followed by </template> tag
51-
(?: (\s*) (-->) \s* )? (?=</(?i:template){{tag_name_break_char}})
52-
# or standalone html comment end punctuation in a line
53-
| ^ (\s*) (-->) \s* $
54-
)
50+
51+
# Vue specific variables
52+
# ======================
53+
54+
template_content_begin: ^|(?=[{{ascii_space}}]*\S)
55+
template_content_end: (?=(?:^\s*)?</(?i:template){{tag_name_break}})
5556

5657
contexts:
5758

@@ -608,17 +609,10 @@ contexts:
608609

609610
template-jade-content:
610611
- match: '{{template_content_begin}}'
611-
captures:
612-
1: comment.block.html punctuation.definition.comment.begin.html
613-
pop: 1
614612
embed: scope:text.jade
615613
embed_scope: text.jade.embedded.html
616614
escape: '{{template_content_end}}'
617-
escape_captures:
618-
1: text.jade.embedded.html
619-
2: comment.block.html punctuation.definition.comment.end.html
620-
3: text.jade.embedded.html
621-
4: comment.block.html punctuation.definition.comment.end.html
615+
pop: 1
622616

623617
template-mustache:
624618
- meta_scope: meta.tag.template.begin.html
@@ -634,17 +628,10 @@ contexts:
634628

635629
template-pug-content:
636630
- match: '{{template_content_begin}}'
637-
captures:
638-
1: comment.block.html punctuation.definition.comment.begin.html
639-
pop: 1
640631
embed: scope:text.pug
641632
embed_scope: text.pug.embedded.html
642633
escape: '{{template_content_end}}'
643-
escape_captures:
644-
1: text.pug.embedded.html
645-
2: comment.block.html punctuation.definition.comment.end.html
646-
3: text.pug.embedded.html
647-
4: comment.block.html punctuation.definition.comment.end.html
634+
pop: 1
648635

649636
template-slim:
650637
- meta_scope: meta.tag.template.begin.html
@@ -655,17 +642,10 @@ contexts:
655642

656643
template-slim-content:
657644
- match: '{{template_content_begin}}'
658-
captures:
659-
1: comment.block.html punctuation.definition.comment.begin.html
660-
pop: 1
661645
embed: scope:text.slim
662646
embed_scope: text.slim.embedded.html
663647
escape: '{{template_content_end}}'
664-
escape_captures:
665-
1: text.slim.embedded.html
666-
2: comment.block.html punctuation.definition.comment.end.html
667-
3: text.slim.embedded.html
668-
4: comment.block.html punctuation.definition.comment.end.html
648+
pop: 1
669649

670650
###[ TAG ATTRIBUTES ]#########################################################
671651

tests/syntax_test_script.vue

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,18 @@
3838
var i = 0;
3939
// ^^^^^^^^^^^^ source.js.embedded.html - source source
4040
</script>
41-
// <- source.js.embedded.html - source source
42-
// ^ source.js.embedded.html - source source
4341
// ^^^^^^^^^ meta.tag - source
4442

4543

4644
<script>
4745
<!--
4846
//^^^^^^ - meta.tag - source
4947
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
50-
// ^ source.js.embedded.html - source source - meta.tag - comment
5148
var i = 0;
5249
// ^^^^^^^^^^^^ source.js.embedded.html - source source - meta.tag
5350
-->
54-
//^^ source.js.embedded.html - meta.tag - comment
55-
// ^^^^ - source - meta.tag
56-
// ^^^ comment.block.html punctuation.definition.comment.end.html
51+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
52+
// ^ - comment - source
5753
var i = 0;
5854
// ^^^^^^^^^^^^ - source
5955
</script>
@@ -68,7 +64,6 @@
6864
// ^ punctuation.definition.tag.end.html
6965
// ^ - meta.tag - comment
7066
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
71-
// ^ source.js.embedded.html - source source
7267
7368
var foo = 100;
7469
// <- source.js.embedded.html - source source
@@ -77,12 +72,9 @@
7772
// ^^^ source.js.embedded.html keyword.operator - comment
7873
7974
--> </script>
80-
// ^ source.js.embedded.html - source source
81-
// ^^^^^^^^^^^^^^ - source
82-
// ^ - meta.tag - comment
83-
// ^^^^^^^^^ meta.tag
84-
// ^ - meta.tag
85-
// ^^^ comment.block.html punctuation.definition.comment.end.html
75+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
76+
// ^ - comment - meta.tag - source
77+
// ^^^^^^^^^ meta.tag - comment - source
8678
// ^^ punctuation.definition.tag.begin.html
8779
// ^^^^^^ entity.name.tag
8880
// ^ punctuation.definition.tag.end.html
@@ -98,7 +90,6 @@
9890
// ^ punctuation.separator.key-value.html
9991
// ^^^^^^^^^^^^^^^^^ string.quoted.double.html
10092
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
101-
// ^ source.js.embedded.html
10293
10394
var foo = 100;
10495
// <- source.js.embedded.html - source source
@@ -107,12 +98,9 @@
10798
// ^^^ source.js.embedded.html keyword.operator - comment
10899
109100
--> </script>
110-
// ^ source.js.embedded.html - source source
111-
// ^^^^^^^^^^^^^^ - source
112-
// ^ - meta.tag - comment
113-
// ^^^^^^^^^ meta.tag
114-
// ^ - meta.tag
115-
// ^^^ comment.block.html punctuation.definition.comment.end.html
101+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
102+
// ^ - comment - meta.tag - source
103+
// ^^^^^^^^^ meta.tag - comment - source
116104
// ^^ punctuation.definition.tag.begin.html
117105
// ^^^^^^ entity.name.tag
118106
// ^ punctuation.definition.tag.end.html
@@ -128,10 +116,13 @@
128116
// <- source.js.embedded.html - source source
129117
// ^^^^^^^^^^^^^^^^ source.js.embedded.html - source source
130118
</script>
131-
// <- source.js.embedded.html - source source
132-
// ^ source.js.embedded.html - source source
133119
// ^^^^^^^^^ meta.tag - source
134120

121+
122+
<!--
123+
-- CoffeeScript
124+
-->
125+
135126
<script language="coffeescript"> </script>
136127
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source
137128
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.lang.html - meta.attribute-with-value meta.attribute-with-value
@@ -148,109 +139,118 @@
148139
149140
// <- source.coffee.embedded.html - source source
150141
</script>
151-
// <- source.coffee.embedded.html - source source
152-
//^^ source.coffee.embedded.html - source source
153142
// ^^^^^^^^^ meta.tag - source
154143
155144
<script lang="coffee">
156145
<!--
157146
// ^^^^^^^^^ - source
158147
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
159-
// ^ source.coffee.embedded.html - source source
160148
-->
161-
// ^^^^^ source.coffee.embedded.html - source source
149+
// <- - comment
150+
//^^^^^^ - comment
162151
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
163-
// ^ - source - comment - meta.tag
152+
// ^ - comment - source
153+
var i = 0;
154+
// ^^^^^^^^^^^^ - source
164155
</script>
165-
// <- - source - comment - meta.tag
166-
//^^ - source - comment - meta.tag
167156
// ^^^^^^^^^ meta.tag - source
168157
158+
159+
<!--
160+
-- JSX
161+
-->
162+
169163
<script lang="jsx">
170164
171165
// <- source.jsx.embedded.html - source source
172166
</script>
173-
// <- source.jsx.embedded.html - source source
174-
//^^ source.jsx.embedded.html - source source
175167
// ^^^^^^^^^ meta.tag - source
176168
177169
<script lang="jsx">
178170
<!--
179171
// ^^^^^^^^^ - source
180172
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
181-
// ^ source.jsx.embedded.html - source source
182173
-->
183-
// ^^^^^ source.jsx.embedded.html - source source
174+
// <- - comment
175+
//^^^^^^ - comment
184176
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
185-
// ^ - source - comment - meta.tag
177+
// ^ - comment - source
178+
var i = 0;
179+
// ^^^^^^^^^^^^ - source
186180
</script>
187-
// <- - source - comment - meta.tag
188-
//^^ - source - comment - meta.tag
189181
// ^^^^^^^^^ meta.tag - source
190182
183+
184+
<!--
185+
-- LiveScript
186+
-->
187+
191188
<script lang="livescript">
192189
193190
// <- source.livescript.embedded.html - source source
194191
</script>
195-
// <- source.livescript.embedded.html - source source
196-
//^^ source.livescript.embedded.html - source source
197192
// ^^^^^^^^^ meta.tag - source
198193
199194
<script lang="livescript">
200195
<!--
201196
// ^^^^^^^^^ - source
202197
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
203-
// ^ source.livescript.embedded.html - source source
204198
-->
205-
// ^^^^^ source.livescript.embedded.html - source source
199+
// <- - comment
200+
//^^^^^^ - comment
206201
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
207-
// ^ - source - comment - meta.tag
202+
// ^ - comment - source
203+
var i = 0;
204+
// ^^^^^^^^^^^^ - source
208205
</script>
209-
// <- - source - comment - meta.tag
210-
//^^ - source - comment - meta.tag
211206
// ^^^^^^^^^ meta.tag - source
212207
213208
209+
<!--
210+
-- TypeScript
211+
-->
212+
214213
<script lang="ts">
215214
216215
// <- source.ts.embedded.html - source source
217216
</script>
218-
// <- source.ts.embedded.html - source source
219-
//^^ source.ts.embedded.html - source source
220217
// ^^^^^^^^^ meta.tag - source
221218
222219
<script lang="ts">
223220
<!--
224221
// ^^^^^^^^^ - source
225222
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
226-
// ^ source.ts.embedded.html - source source
227223
-->
228-
// ^^^^^ source.ts.embedded.html - source source
224+
// <- - comment
225+
//^^^^^^ - comment
229226
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
230-
// ^ - source - comment - meta.tag
227+
// ^ - comment - source
228+
var i = 0;
229+
// ^^^^^^^^^^^^ - source
231230
</script>
232-
// <- - source - comment - meta.tag
233-
//^^ - source - comment - meta.tag
234231
// ^^^^^^^^^ meta.tag - source
235232
233+
234+
<!--
235+
-- TSX
236+
-->
237+
236238
<script lang="tsx">
237239
238240
// <- source.tsx.embedded.html - source source
239241
</script>
240-
// <- source.tsx.embedded.html - source source
241-
//^^ source.tsx.embedded.html - source source
242242
// ^^^^^^^^^ meta.tag - source
243243
244244
<script lang="tsx">
245245
<!--
246246
// ^^^^^^^^^ - source
247247
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
248-
// ^ source.tsx.embedded.html - source source
249248
-->
250-
// ^^^^^ source.tsx.embedded.html - source source
249+
// <- - comment
250+
//^^^^^^ - comment
251251
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
252-
// ^ - source - comment - meta.tag
252+
// ^ - comment - source
253+
var i = 0;
254+
// ^^^^^^^^^^^^ - source
253255
</script>
254-
// <- - source - comment - meta.tag
255-
//^^ - source - comment - meta.tag
256256
// ^^^^^^^^^ meta.tag - source

0 commit comments

Comments
 (0)