Skip to content

Commit acd7ef3

Browse files
committed
Fix script/style/template indentation
This commit backports sublimehq/Packages#4020 to ensure related indentation rules are correctly applied for ST4181+. Scope changes are backported primarily due to their effect on syntax tests and the goal to avoid a need to ship dedicated ST4181+ releases just due to failing syntax tests, which do otherwise not have any significant effect on highlighting.
1 parent 5e17853 commit acd7ef3

File tree

4 files changed

+263
-154
lines changed

4 files changed

+263
-154
lines changed

Vue Component.sublime-syntax

Lines changed: 28 additions & 11 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
@@ -20,37 +23,51 @@ variables:
2023
# see:
2124
# - https://github.com/sublimehq/Packages/issues/2322
2225
# - https://github.com/sublimehq/sublime_text/issues/4701
26+
#
27+
# Patterns backported from (required until ST4180):
28+
# - https://github.com/sublimehq/Packages/pull/4020
2329
script_content_begin: |-
2430
(?x:
25-
# whitespace followed by opening html comment begin punctuation
26-
\s*(<!--)
31+
# whitespace followed by opening html comment begin punctuation,
32+
# optionally followed by whitespeace until end of line
33+
\s*(<!--) (?:\s*\n)?
2734
# or any other non-whitespace character ahead
2835
| (?=\s*(?!<!--)\S)
2936
# or beginning of a line
3037
| ^
3138
)
3239
script_content_end: |-
3340
(?x:
34-
# optional html comment end punctuation followed by </script> tag
35-
(?: (\s*) (-->) \s* )? (?=</(?i:script){{tag_name_break_char}})
41+
# optional html comment end punctuation or any whitespace at beginning of
42+
# line followed by </script> tag
43+
(?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=</(?i:script){{tag_name_break_char}})
3644
# or standalone html comment end punctuation in a line
37-
| ^ (\s*) (-->) \s* $
45+
# note: Keep empty capture group for compatibility with existing 3rd-party syntaxes!
46+
| ^ \s* () (-->) \s* $
3847
)
3948
style_content_begin: '{{script_content_begin}}'
4049
style_content_end: |-
4150
(?x:
42-
# optional html comment end punctuation followed by </style> tag
43-
(?: (\s*) (-->) \s* )? (?=</(?i:style){{tag_name_break_char}})
51+
# optional html comment end punctuation or any whitespace at beginning of
52+
# line followed by </style> tag
53+
(?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=</(?i:style){{tag_name_break_char}})
4454
# or standalone html comment end punctuation in a line
45-
| ^ (\s*) (-->) \s* $
55+
# note: Keep empty capture group for compatibility with existing 3rd-party syntaxes!
56+
| ^ \s* () (-->) \s* $
4657
)
58+
59+
# Vue specific variables
60+
# ======================
61+
4762
template_content_begin: '{{script_content_begin}}'
4863
template_content_end: |-
4964
(?x:
50-
# optional html comment end punctuation followed by </template> tag
51-
(?: (\s*) (-->) \s* )? (?=</(?i:template){{tag_name_break_char}})
65+
# optional html comment end punctuation or any whitespace at beginning of
66+
# line followed by </style> tag
67+
(?: (?: ^ \s* | (\s*) ) (-->) \s* | ^ \s* )? (?=</(?i:template){{tag_name_break_char}})
5268
# or standalone html comment end punctuation in a line
53-
| ^ (\s*) (-->) \s* $
69+
# note: Keep empty capture group for compatibility with existing 3rd-party syntaxes!
70+
| ^ \s* () (-->) \s* $
5471
)
5572
5673
contexts:

tests/syntax_test_script.vue

Lines changed: 96 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,38 @@
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
41+
// <- - meta.tag - source
42+
//^^ - meta.tag - source
4343
// ^^^^^^^^^ meta.tag - source
4444

4545

4646
<script>
4747
<!--
48-
//^^^^^^ - meta.tag - source
48+
//^^^^^^^ - meta.tag - source
4949
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
50-
// ^ source.js.embedded.html - source source - meta.tag - comment
5150
var i = 0;
5251
// ^^^^^^^^^^^^ source.js.embedded.html - source source - meta.tag
5352
-->
54-
//^^ source.js.embedded.html - meta.tag - comment
55-
// ^^^^ - source - meta.tag
56-
// ^^^ comment.block.html punctuation.definition.comment.end.html
53+
// <- - comment - source
54+
//^^ - comment - source
55+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
56+
// ^ - comment - source
5757
var i = 0;
5858
// ^^^^^^^^^^^^ - source
5959
</script>
60+
// <- - meta.tag - source
61+
//^^ - meta.tag - source
6062
// ^^^^^^^^^ meta.tag - source
6163

6264

6365
<script> <!--
64-
// ^^^^^^^^^^^^^ - source
66+
// ^^^^^^^^^^^^^^ - source
6567
// ^^^^^^^^ meta.tag
6668
// ^ punctuation.definition.tag.begin.html
6769
// ^^^^^^ entity.name.tag
6870
// ^ punctuation.definition.tag.end.html
6971
// ^ - meta.tag - comment
7072
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
71-
// ^ source.js.embedded.html - source source
7273

7374
var foo = 100;
7475
// <- source.js.embedded.html - source source
@@ -77,12 +78,11 @@
7778
// ^^^ source.js.embedded.html keyword.operator - comment
7879

7980
--> </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
81+
// <- - comment - source
82+
//^^ - comment - source
83+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
84+
// ^ - comment - meta.tag - source
85+
// ^^^^^^^^^ meta.tag - comment - source
8686
// ^^ punctuation.definition.tag.begin.html
8787
// ^^^^^^ entity.name.tag
8888
// ^ punctuation.definition.tag.end.html
@@ -92,13 +92,12 @@
9292
// ^^^^^^^^ meta.tag - meta.attribute-with-value - source
9393
// ^^^^^^^^^^^^^^^^^^^^^^ meta.tag meta.attribute-with-value - meta.attribute-with-value meta.attribute-with-value - source
9494
// ^ meta.tag - meta.attribute-with-value - source
95-
// ^^^^^ - meta.tag - source
95+
// ^^^^^^ - meta.tag - source
9696
// ^^^^^^ entity.name.tag
9797
// ^^^^ entity.other.attribute-name.html
9898
// ^ punctuation.separator.key-value.html
9999
// ^^^^^^^^^^^^^^^^^ string.quoted.double.html
100100
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
101-
// ^ source.js.embedded.html
102101

103102
var foo = 100;
104103
// <- source.js.embedded.html - source source
@@ -107,12 +106,11 @@
107106
// ^^^ source.js.embedded.html keyword.operator - comment
108107

109108
--> </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
109+
// <- - comment - source
110+
//^^ - comment - source
111+
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
112+
// ^ - comment - meta.tag - source
113+
// ^^^^^^^^^ meta.tag - comment - source
116114
// ^^ punctuation.definition.tag.begin.html
117115
// ^^^^^^ entity.name.tag
118116
// ^ punctuation.definition.tag.end.html
@@ -128,10 +126,15 @@
128126
// <- source.js.embedded.html - source source
129127
// ^^^^^^^^^^^^^^^^ source.js.embedded.html - source source
130128
</script>
131-
// <- source.js.embedded.html - source source
132-
// ^ source.js.embedded.html - source source
129+
// <- - meta.tag - source
130+
//^^ - meta.tag - source
133131
// ^^^^^^^^^ meta.tag - source
134132

133+
134+
<!--
135+
-- CoffeeScript
136+
-->
137+
135138
<script language="coffeescript"> </script>
136139
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag - meta.tag meta.tag - source
137140
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.lang.html - meta.attribute-with-value meta.attribute-with-value
@@ -148,109 +151,137 @@
148151

149152
// <- source.coffee.embedded.html - source source
150153
</script>
151-
// <- source.coffee.embedded.html - source source
152-
//^^ source.coffee.embedded.html - source source
154+
// <- - source
153155
// ^^^^^^^^^ meta.tag - source
154156

155157
<script lang="coffee">
156158
<!--
157-
// ^^^^^^^^^ - source
159+
// ^^^^^^^^^^ - source
158160
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
159-
// ^ source.coffee.embedded.html - source source
160161
-->
161-
// ^^^^^ source.coffee.embedded.html - source source
162+
// <- - comment - source
163+
//^^^^^^ - comment - source
162164
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
163-
// ^ - source - comment - meta.tag
165+
// ^ - comment - source
166+
var i = 0;
167+
// ^^^^^^^^^^^^ - source
164168
</script>
165-
// <- - source - comment - meta.tag
166-
//^^ - source - comment - meta.tag
169+
// <- - meta.tag - source
170+
//^^ - meta.tag - source
167171
// ^^^^^^^^^ meta.tag - source
168172

173+
174+
<!--
175+
-- JSX
176+
-->
177+
169178
<script lang="jsx">
170179

171180
// <- source.jsx.embedded.html - source source
172181
</script>
173-
// <- source.jsx.embedded.html - source source
174-
//^^ source.jsx.embedded.html - source source
182+
// <- - meta.tag - source
183+
//^^ - meta.tag - source
175184
// ^^^^^^^^^ meta.tag - source
176185

177186
<script lang="jsx">
178187
<!--
179-
// ^^^^^^^^^ - source
188+
// ^^^^^^^^^^ - source
180189
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
181-
// ^ source.jsx.embedded.html - source source
182190
-->
183-
// ^^^^^ source.jsx.embedded.html - source source
191+
// <- - comment - source
192+
//^^^^^^ - comment - source
184193
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
185-
// ^ - source - comment - meta.tag
194+
// ^ - comment - source
195+
var i = 0;
196+
// ^^^^^^^^^^^^ - source
186197
</script>
187-
// <- - source - comment - meta.tag
188-
//^^ - source - comment - meta.tag
198+
// <- - meta.tag - source
199+
//^^ - meta.tag - source
189200
// ^^^^^^^^^ meta.tag - source
190201

202+
203+
<!--
204+
-- LiveScript
205+
-->
206+
191207
<script lang="livescript">
192208

193209
// <- source.livescript.embedded.html - source source
194210
</script>
195-
// <- source.livescript.embedded.html - source source
196-
//^^ source.livescript.embedded.html - source source
211+
// <- - meta.tag - source
212+
//^^ - meta.tag - source
197213
// ^^^^^^^^^ meta.tag - source
198214

199215
<script lang="livescript">
200216
<!--
201-
// ^^^^^^^^^ - source
217+
// ^^^^^^^^^^ - source
202218
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
203-
// ^ source.livescript.embedded.html - source source
204219
-->
205-
// ^^^^^ source.livescript.embedded.html - source source
220+
// <- - comment - source
221+
//^^^^^^ - comment - source
206222
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
207-
// ^ - source - comment - meta.tag
223+
// ^ - comment - source
224+
var i = 0;
225+
// ^^^^^^^^^^^^ - source
208226
</script>
209-
// <- - source - comment - meta.tag
210-
//^^ - source - comment - meta.tag
227+
// <- - meta.tag - source
228+
//^^ - meta.tag - source
211229
// ^^^^^^^^^ meta.tag - source
212230

213231

232+
<!--
233+
-- TypeScript
234+
-->
235+
214236
<script lang="ts">
215237

216238
// <- source.ts.embedded.html - source source
217239
</script>
218-
// <- source.ts.embedded.html - source source
219-
//^^ source.ts.embedded.html - source source
240+
// <- - meta.tag - source
241+
//^^ - meta.tag - source
220242
// ^^^^^^^^^ meta.tag - source
221243

222244
<script lang="ts">
223245
<!--
224-
// ^^^^^^^^^ - source
246+
// ^^^^^^^^^^ - source
225247
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
226-
// ^ source.ts.embedded.html - source source
227248
-->
228-
// ^^^^^ source.ts.embedded.html - source source
249+
// <- - comment - source
250+
//^^^^^^ - comment - source
229251
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
230-
// ^ - source - comment - meta.tag
252+
// ^ - comment - source
253+
var i = 0;
254+
// ^^^^^^^^^^^^ - source
231255
</script>
232-
// <- - source - comment - meta.tag
233-
//^^ - source - comment - meta.tag
256+
// <- - meta.tag - source
257+
//^^ - meta.tag - source
234258
// ^^^^^^^^^ meta.tag - source
235259

260+
261+
<!--
262+
-- TSX
263+
-->
264+
236265
<script lang="tsx">
237266

238267
// <- source.tsx.embedded.html - source source
239268
</script>
240-
// <- source.tsx.embedded.html - source source
241-
//^^ source.tsx.embedded.html - source source
269+
// <- - meta.tag - source
270+
//^^ - meta.tag - source
242271
// ^^^^^^^^^ meta.tag - source
243272

244273
<script lang="tsx">
245274
<!--
246-
// ^^^^^^^^^ - source
275+
// ^^^^^^^^^^ - source
247276
// ^^^^ comment.block.html punctuation.definition.comment.begin.html
248-
// ^ source.tsx.embedded.html - source source
249277
-->
250-
// ^^^^^ source.tsx.embedded.html - source source
278+
// <- - comment - source
279+
//^^^^^^ - comment - source
251280
// ^^^ comment.block.html punctuation.definition.comment.end.html - source
252-
// ^ - source - comment - meta.tag
281+
// ^ - comment - source
282+
var i = 0;
283+
// ^^^^^^^^^^^^ - source
253284
</script>
254-
// <- - source - comment - meta.tag
255-
//^^ - source - comment - meta.tag
285+
// <- - meta.tag - source
286+
//^^ - meta.tag - source
256287
// ^^^^^^^^^ meta.tag - source

0 commit comments

Comments
 (0)