Skip to content

Commit 2f49366

Browse files
author
deathaxe
committed
Add meta scope to control flow statements
This commit scopes all control flow statements `meta.embedded.statement source.ngx.embedded.html`. to also apply proper `source.ngx` to angular expressions.
1 parent 4053d65 commit 2f49366

File tree

2 files changed

+79
-26
lines changed

2 files changed

+79
-26
lines changed

NgxHTML.sublime-syntax

+40-13
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ contexts:
177177

178178
ng-declarations:
179179
- match: (@)let{{ident_break}}
180-
scope: meta.let.ngx keyword.declaration.variable.ngx
180+
scope:
181+
meta.embedded.statement.ngx.html source.ngx.embedded.html
182+
meta.let.ngx keyword.declaration.variable.ngx
181183
captures:
182184
1: punctuation.definition.keyword.ngx
183185
push:
@@ -191,15 +193,21 @@ contexts:
191193
- include: else-pop
192194

193195
ng-let-assignment:
194-
- meta_content_scope: meta.let.identifier.ngx
196+
- meta_content_scope:
197+
meta.embedded.statement.ngx.html source.ngx.embedded.html
198+
meta.let.identifier.ngx
195199
- match: =
196-
scope: meta.let.ngx keyword.operator.assignment.ngx
200+
scope:
201+
meta.embedded.statement.ngx.html source.ngx.embedded.html
202+
meta.let.ngx keyword.operator.assignment.ngx
197203
set: ng-let-value
198204
- include: else-pop
199205

200206
ng-let-value:
201207
- meta_include_prototype: false
202-
- meta_content_scope: meta.let.value.ngx
208+
- meta_content_scope:
209+
meta.embedded.statement.ngx.html source.ngx.embedded.html
210+
meta.let.value.ngx
203211
- match: ';'
204212
scope: punctuation.terminator.expression.ngx
205213
pop: 1
@@ -211,60 +219,78 @@ contexts:
211219
# conditionals
212220
# https://angular.dev/guide/templates/control-flow#conditionally-display-content-with-if-else-if-and-else
213221
- match: (@)if{{ident_break}}
214-
scope: keyword.control.conditional.if.ngx
222+
scope:
223+
meta.embedded.statement.ngx.html source.ngx.embedded.html
224+
keyword.control.conditional.if.ngx
215225
captures:
216226
1: punctuation.definition.keyword.ngx
217227
push:
218228
- ng-block
219229
- ng-conditional-group
220230
- match: (@)else\s+if{{ident_break}}
221-
scope: keyword.control.conditional.elseif.ngx
231+
scope:
232+
meta.embedded.statement.ngx.html source.ngx.embedded.html
233+
keyword.control.conditional.elseif.ngx
222234
captures:
223235
1: punctuation.definition.keyword.ngx
224236
push:
225237
- ng-block
226238
- ng-conditional-group
227239
- match: (@)else{{ident_break}}
228-
scope: keyword.control.conditional.else.ngx
240+
scope:
241+
meta.embedded.statement.ngx.html source.ngx.embedded.html
242+
keyword.control.conditional.else.ngx
229243
captures:
230244
1: punctuation.definition.keyword.ngx
231245
push: ng-block
232246
# https://angular.dev/guide/templates/control-flow#conditionally-display-content-with-the-switch-block
233247
- match: (@)case{{ident_break}}
234-
scope: keyword.control.conditional.case.ngx
248+
scope:
249+
meta.embedded.statement.ngx.html source.ngx.embedded.html
250+
keyword.control.conditional.case.ngx
235251
captures:
236252
1: punctuation.definition.keyword.ngx
237253
push:
238254
- ng-block
239255
- ng-conditional-group
240256
- match: (@)default{{ident_break}}
241-
scope: keyword.control.conditional.case.ngx
257+
scope:
258+
meta.embedded.statement.ngx.html source.ngx.embedded.html
259+
keyword.control.conditional.case.ngx
242260
captures:
243261
1: punctuation.definition.keyword.ngx
244262
push: ng-block
245263
- match: (@)switch{{ident_break}}
246-
scope: keyword.control.conditional.switch.ngx
264+
scope:
265+
meta.embedded.statement.ngx.html source.ngx.embedded.html
266+
keyword.control.conditional.switch.ngx
247267
captures:
248268
1: punctuation.definition.keyword.ngx
249269
push:
250270
- ng-block
251271
- ng-conditional-group
252272
# https://angular.dev/guide/templates/control-flow#providing-a-fallback-for-for-blocks-with-the-empty-block
253273
- match: (@)for{{ident_break}}
254-
scope: keyword.control.loop.for.ngx
274+
scope:
275+
meta.embedded.statement.ngx.html source.ngx.embedded.html
276+
keyword.control.loop.for.ngx
255277
captures:
256278
1: punctuation.definition.keyword.ngx
257279
push:
258280
- ng-block
259281
- ng-for-group
260282
- match: (@)empty{{ident_break}}
261-
scope: keyword.control.loop.else.ngx
283+
scope:
284+
meta.embedded.statement.ngx.html source.ngx.embedded.html
285+
keyword.control.loop.else.ngx
262286
captures:
263287
1: punctuation.definition.keyword.ngx
264288
push: ng-block
265289
# https://angular.dev/guide/templates/defer
266290
- match: (@)(?:defer|error|loading|placeholder){{ident_break}}
267-
scope: keyword.control.flow.ngx
291+
scope:
292+
meta.embedded.statement.ngx.html source.ngx.embedded.html
293+
keyword.control.flow.ngx
268294
captures:
269295
1: punctuation.definition.keyword.ngx
270296
push:
@@ -273,6 +299,7 @@ contexts:
273299

274300
ng-block:
275301
- meta_include_prototype: false
302+
- meta_content_scope: meta.embedded.statement.ngx.html source.ngx.embedded.html
276303
- match: \{
277304
scope: punctuation.section.block.begin.ngx
278305
set: ng-block-body

tests/syntax_test_scopes.component.html

+39-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-->
77

88
@let name = user.name;
9+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html meta.let.ngx keyword.declaration.variable.ngx punctuation.definition.keyword.ngx -->
10+
<!--^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
911
<!--^^^^^^ meta.let.identifier.ngx -->
1012
<!-- ^^^^ variable.other.readwrite.ngx -->
1113
<!-- ^ meta.let.ngx keyword.operator.assignment.ngx -->
@@ -16,6 +18,7 @@
1618
<!-- ^ punctuation.terminator.expression.ngx -->
1719

1820
@let func = user.func();
21+
<!--^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
1922
<!--^^^^^^ meta.let.identifier.ngx -->
2023
<!-- ^^^^ variable.other.readwrite.ngx -->
2124
<!-- ^ meta.let.ngx keyword.operator.assignment.ngx -->
@@ -29,6 +32,7 @@
2932
<!-- ^ punctuation.terminator.expression.ngx -->
3033

3134
@let greeting = 'Hello, ' + name;
35+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
3236
<!--^^^^^^^^^^ meta.let.identifier.ngx -->
3337
<!-- ^^^^^^^^ variable.other.readwrite.ngx -->
3438
<!-- ^ meta.let.ngx keyword.operator.assignment.ngx -->
@@ -41,6 +45,7 @@
4145
<!-- ^ punctuation.terminator.expression.ngx -->
4246

4347
@let data = data$ | async;
48+
<!--^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
4449
<!--^^^^^^ meta.let.identifier.ngx -->
4550
<!-- ^ meta.let.ngx -->
4651
<!-- ^^^^^^^ meta.let.value.ngx - meta.filter -->
@@ -53,6 +58,7 @@
5358
<!-- ^ punctuation.terminator.expression.ngx -->
5459

5560
@let item = var[10]['bar'];
61+
<!--^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
5662
<!--^^^^^^ meta.let.identifier.ngx -->
5763
<!-- ^ meta.let.ngx -->
5864
<!-- ^^^^^^^^^^^^^^^ meta.let.value.ngx -->
@@ -71,6 +77,7 @@
7177

7278
<!-- qualified property with missing leading object in incomplete ternary expression -->
7379
@let path = .foo?.bar? ;
80+
<!--^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
7481
<!--^^^^^^ meta.let.identifier.ngx -->
7582
<!-- ^ meta.let.ngx -->
7683
<!-- ^ meta.let.value.ngx - meta.path -->
@@ -87,6 +94,7 @@
8794
<!-- ^ punctuation.terminator.expression.ngx -->
8895

8996
@let path = .orders.value()?.[0]?.$extra?.#currency.unit;
97+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
9098
<!--^^^^^^ meta.let.identifier.ngx -->
9199
<!-- ^ meta.let.ngx -->
92100
<!-- ^ meta.let.value.ngx - meta.path -->
@@ -116,6 +124,7 @@
116124
<!-- ^ punctuation.terminator.expression.ngx -->
117125

118126
@let path = orders.value()?.[0]?.$extra?.#currency.unit;
127+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
119128
<!--^^^^^^ meta.let.identifier.ngx -->
120129
<!-- ^ meta.let.ngx -->
121130
<!-- ^ meta.let.value.ngx - meta.path -->
@@ -149,9 +158,10 @@
149158
-->
150159

151160
@if (a > b) {
152-
<!-- <- keyword.control.conditional.if.ngx punctuation.definition.keyword.ngx -->
153-
<!-- <- keyword.control.conditional.if.ngx -->
154-
<!-- <- keyword.control.conditional.if.ngx -->
161+
<!--^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
162+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html keyword.control.conditional.if.ngx punctuation.definition.keyword.ngx -->
163+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html keyword.control.conditional.if.ngx -->
164+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html keyword.control.conditional.if.ngx -->
155165
<!--^^^^^^^ meta.group.ngx -->
156166
<!--^ punctuation.section.group.begin.ngx -->
157167
<!-- ^ variable.other.readwrite.ngx -->
@@ -173,6 +183,7 @@
173183
<!-- ^^ punctuation.section.embedded.end.ngx.html - source.ngx -->
174184
} @else if (b > a()) {
175185
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
186+
<!--^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
176187
<!--^^^^^^ keyword.control.conditional.elseif.ngx -->
177188
<!-- ^^^^^^^^^ meta.group.ngx -->
178189
<!-- ^ punctuation.section.group.begin.ngx -->
@@ -202,7 +213,8 @@
202213
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
203214
} @else {
204215
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
205-
<!-- <- keyword.control.conditional.else.ngx punctuation.definition.keyword.ngx -->
216+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html keyword.control.conditional.else.ngx punctuation.definition.keyword.ngx -->
217+
<!--^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
206218
<!--^^^ keyword.control.conditional.else.ngx -->
207219
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
208220
{{ a }} is equal to {{ b }}
@@ -250,14 +262,16 @@
250262
-->
251263

252264
@switch (accessLevel) {
265+
<!-- <- meta.embedded.statement.ngx.html source.ngx.embedded.html keyword.control.conditional.switch.ngx punctuation.definition.keyword.ngx -->
266+
<!--^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
253267
<!--^^^ keyword.control.conditional.switch.ngx -->
254268
<!-- ^^^^^^^^^^^^^ meta.group.ngx -->
255269
<!-- ^ punctuation.section.group.begin.ngx -->
256270
<!-- ^^^^^^^^^^^ variable.other.readwrite.ngx -->
257271
<!-- ^ punctuation.section.group.end.ngx -->
258272
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
259273
@case ('admin') {
260-
<!--^^^^^^^^^^^^^^^^ meta.block.ngx - meta.block meta.block -->
274+
<!--^^^^^^^^^^^^^^^^ meta.block.ngx meta.embedded.statement.ngx.html source.ngx.embedded.html - meta.block meta.block -->
261275
<!-- ^^ meta.block.ngx meta.block.ngx -->
262276
<!--^^^^^ keyword.control.conditional.case.ngx -->
263277
<!--^ punctuation.definition.keyword.ngx -->
@@ -277,7 +291,7 @@
277291
<!-- ^ meta.block.ngx - meta.block meta.block -->
278292

279293
@case {
280-
<!--^^^^^^ meta.block.ngx - meta.block meta.block -->
294+
<!--^^^^^^ meta.block.ngx meta.embedded.statement.ngx.html source.ngx.embedded.html - meta.block meta.block -->
281295
<!-- ^^ meta.block.ngx meta.block.ngx -->
282296
<!--^^^^^ keyword.control.conditional.case.ngx -->
283297
<!--^ punctuation.definition.keyword.ngx -->
@@ -292,7 +306,7 @@
292306
<!--^ meta.block.ngx meta.block.ngx punctuation.section.block.end.ngx -->
293307
<!-- ^ meta.block.ngx - meta.block meta.block -->
294308
@default {
295-
<!--^^^^^^^^^ meta.block.ngx - meta.block meta.block -->
309+
<!--^^^^^^^^^ meta.block.ngx meta.embedded.statement.ngx.html source.ngx.embedded.html - meta.block meta.block -->
296310
<!-- ^^ meta.block.ngx meta.block.ngx -->
297311
<!--^^^^^^^^ keyword.control.conditional.case.ngx -->
298312
<!--^ punctuation.definition.keyword.ngx -->
@@ -311,6 +325,8 @@
311325
-->
312326

313327
@for (user of users; track user.id) {
328+
<!-- <- meta.embedded.statement.ngx source.ngx.embedded.html keyword.control.loop.for.ngx punctuation.definition.keyword.ngx -->
329+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx source.ngx.embedded.html -->
314330
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.ngx -->
315331
<!-- ^ punctuation.section.group.begin.ngx -->
316332
<!-- ^^^^ variable.other.readwrite.ngx -->
@@ -326,14 +342,16 @@
326342
{{ user.name }}
327343
} @empty {
328344
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
329-
<!-- <- keyword.control.loop.else.ngx punctuation.definition.keyword.ngx -->
330-
<!--^^^^ keyword.control.loop.else.ngx -->
345+
<!-- <- meta.embedded.statement.ngx source.ngx.embedded.html keyword.control.loop.else.ngx punctuation.definition.keyword.ngx -->
346+
<!--^^^^ meta.embedded.statement.ngx source.ngx.embedded.html keyword.control.loop.else.ngx -->
347+
<!-- ^ meta.embedded.statement.ngx source.ngx.embedded.html - keyword - punctuation -->
331348
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
332349
Empty list of users
333-
}
334-
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
350+
.html}
351+
<!--.html <- meta.block.ngx punctuation.section.block.end.ngx -->
335352

336353
@for (item of items; track item.id; let idx = $index, e = $even) {
354+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx source.ngx.embedded.html -->
337355
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.ngx -->
338356
<!-- ^ punctuation.section.group.begin.ngx -->
339357
<!-- ^^^^ variable.other.readwrite.ngx -->
@@ -370,9 +388,11 @@
370388
<!-- ^^^^ variable.other.member.ngx -->
371389
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
372390
}
373-
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
391+
<!--.html <- meta.block.ngx punctuation.section.block.end.ngx -->
374392

375393
@if (users$ | async; as users) {
394+
<!-- <- meta.embedded.statement.ngx source.ngx.embedded.html keyword.control.conditional.if.ngx punctuation.definition.keyword.ngx -->
395+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx source.ngx.embedded.html -->
376396
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.ngx -->
377397
<!--^ punctuation.section.group.begin.ngx -->
378398
<!-- ^^^^^^ variable.other.readwrite.ngx -->
@@ -402,7 +422,7 @@
402422
<!-- ^ entity.name.tag.block.any.html -->
403423
<!-- ^ punctuation.definition.tag.end.html -->
404424
}
405-
<!-- <- meta.block.ngx punctuation.section.block.end.ngx -->
425+
<!--.html <- meta.block.ngx punctuation.section.block.end.ngx -->
406426

407427

408428
<!--
@@ -411,6 +431,7 @@
411431
-->
412432

413433
@defer { <comment-list /> }
434+
<!--^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
414435
<!--^^^^^^ keyword.control.flow.ngx -->
415436
<!--^ punctuation.definition.keyword.ngx -->
416437
<!-- ^^^^^^^^^^^^^^^^^^^^ meta.block.ngx -->
@@ -422,6 +443,7 @@
422443
<!-- ^ punctuation.section.block.end.ngx -->
423444

424445
@defer (on viewport) {
446+
<!--^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
425447
<!--^^^^^^ keyword.control.flow.ngx -->
426448
<!--^ punctuation.definition.keyword.ngx -->
427449
<!-- ^^^^^^^^^^^^^ meta.group.ngx -->
@@ -433,18 +455,21 @@
433455
<comment-list />
434456
} @loading {
435457
<!--^ meta.block.ngx punctuation.section.block.end.ngx -->
458+
<!-- ^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
436459
<!-- ^^^^^^^^ keyword.control.flow.ngx -->
437460
<!-- ^ punctuation.definition.keyword.ngx -->
438461
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
439462
Loading…
440463
} @error {
441464
<!--^ meta.block.ngx punctuation.section.block.end.ngx -->
465+
<!-- ^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
442466
<!-- ^^^^^^ keyword.control.flow.ngx -->
443467
<!-- ^ punctuation.definition.keyword.ngx -->
444468
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
445469
Loading failed :(
446470
} @placeholder {
447471
<!--^ meta.block.ngx punctuation.section.block.end.ngx -->
472+
<!-- ^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
448473
<!-- ^^^^^^^^^^^^ keyword.control.flow.ngx -->
449474
<!-- ^ punctuation.definition.keyword.ngx -->
450475
<!-- ^ meta.block.ngx punctuation.section.block.begin.ngx -->
@@ -454,6 +479,7 @@
454479
<!-- ^ - meta.block -->
455480

456481
@defer (on viewport; when $var prefetch on idle; prefetch when true) {
482+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.ngx.html source.ngx.embedded.html -->
457483
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.ngx -->
458484
<!-- ^ punctuation.section.group.begin.ngx -->
459485
<!-- ^^ keyword.control.flow.ngx -->

0 commit comments

Comments
 (0)