Skip to content

Commit a0cbcff

Browse files
deathaxeprincemaple
authored andcommitted
Fix qualified member access
This commit adds contexts for JavaScript specific of qualified variables. It uses branching to properly match all parts even across multiple lines.
1 parent 21bab87 commit a0cbcff

File tree

2 files changed

+239
-31
lines changed

2 files changed

+239
-31
lines changed

NgxHTML.sublime-syntax

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ variables:
2525
ident_start: (?:[_$\p{L}\p{Nl}]|{{ident_escape}})
2626
ident_part: (?:[_$\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]|{{ident_escape}})
2727

28+
dot_accessor: (?:\??\.(?!\.))
29+
2830
contexts:
2931

3032
###[ HTML CUSTOMIZATIONS ]#####################################################
@@ -431,7 +433,7 @@ contexts:
431433
scope: keyword.operator.assignment.ngx
432434
- match: \?\?
433435
scope: keyword.operator.null-coalescing.ngx
434-
- match: '\?'
436+
- match: \?(?!\.)
435437
scope: keyword.operator.ternary.ngx
436438
push: ng-ternary-expression
437439

@@ -538,46 +540,108 @@ contexts:
538540
###[ ANGULAR VARIABLES ]#######################################################
539541

540542
ng-variables:
541-
- match: ({{ident_name}})\s*(\??\.)
542-
captures:
543-
1: variable.other.object.ngx
544-
2: punctuation.accessor.ngx
545-
push: ng-members
543+
- match: (?={{ident_start}})
544+
branch_point: ng-variable
545+
branch:
546+
- ng-unqualified-variable
547+
- ng-qualified-variable
548+
- match: '{{dot_accessor}}'
549+
scope: punctuation.accessor.ngx
550+
push:
551+
- ng-accessor
552+
- ng-member
553+
554+
ng-unqualified-variable:
555+
- meta_include_prototype: false
546556
- match: '{{ident_name}}'
547557
scope: variable.other.readwrite.ngx
548-
push: ng-subscription
558+
set:
559+
- ng-variable-check
560+
- ng-subscription
561+
- include: immediately-pop
562+
563+
ng-variable-check:
564+
- match: (?={{dot_accessor}})
565+
fail: ng-variable
566+
- include: else-pop
567+
568+
ng-qualified-variable:
569+
- meta_include_prototype: false
570+
- match: '{{ident_name}}'
571+
scope: variable.other.object.ngx
572+
set:
573+
- ng-accessor
574+
- ng-subscription
575+
- include: immediately-pop
549576

550-
ng-members:
551-
- match: ({{ident_name}})\s*(\??\.)
577+
ng-accessor:
578+
- meta_include_prototype: false
579+
- meta_scope: meta.path.ngx
580+
- match: \s*({{dot_accessor}})
552581
captures:
553-
1: variable.other.object.ngx
554-
2: punctuation.accessor.ngx
582+
1: punctuation.accessor.ngx
583+
push: ng-member
584+
- match: (?=\s*\S)
585+
pop: 1
586+
587+
ng-member:
555588
- match: (({{ident_name}})\s*)(\()
556589
captures:
557590
1: meta.function-call.identifier.ngx
558-
2: variable.function.ngx
591+
2: variable.function.method.ngx
559592
3: meta.function-call.arguments.ngx punctuation.section.arguments.begin.ngx
560-
set: ng-function-call-arguments
561-
- match: '{{ident_name}}'
562-
scope: variable.other.member.ngx
593+
set:
594+
- ng-subscription
595+
- ng-function-call-arguments
596+
- match: (?=[$#]?{{ident_start}})
597+
branch_point: ng-property
598+
branch:
599+
- ng-property
600+
- ng-object
601+
pop: 1
602+
- include: ng-subscription
603+
604+
ng-object:
605+
- match: ([$#]?){{ident_name}}
606+
scope: variable.other.object.ngx
607+
captures:
608+
1: punctuation.definition.variable.ngx
563609
set: ng-subscription
564-
- include: else-pop
610+
- include: immediately-pop
611+
612+
ng-property:
613+
- match: ([$#]?){{ident_name}}
614+
scope: variable.other.member.ngx
615+
captures:
616+
1: punctuation.definition.variable.ngx
617+
set:
618+
- ng-property-check
619+
- ng-subscription
620+
- include: immediately-pop
621+
622+
ng-property-check:
623+
- match: (?=\s*{{dot_accessor}})
624+
fail: ng-property
625+
- match: (?=\s*\S)
626+
pop: 1
565627

566628
ng-subscription:
567-
- match: \[
568-
scope: punctuation.section.subscription.begin.ngx
569-
push: ng-subscription-body
570-
- include: else-pop
629+
- match: \s*(\[)
630+
captures:
631+
1: meta.subscription.ngx punctuation.section.subscription.begin.ngx
632+
set: ng-subscription-body
633+
- match: (?=\s*\S)
634+
pop: 1
571635

572636
ng-subscription-body:
573-
- meta_scope: meta.subscription.ngx
637+
- meta_content_scope: meta.subscription.ngx
574638
- match: \]
575-
scope: punctuation.section.subscription.end.ngx
576-
pop: 1
639+
scope: meta.subscription.ngx punctuation.section.subscription.end.ngx
640+
set: ng-subscription
577641
- include: ng-expressions
578642

579643
###[ ANGULAR PROTOTYPES ]######################################################
580644

581645
ng-block-pop:
582-
- match: (?=[)}])
646+
- match: (?=[;)}])
583647
pop: 1

tests/syntax_test_scopes.component.html

Lines changed: 151 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
<!-- ^^^^ variable.other.member.ngx -->
1616
<!-- ^ punctuation.terminator.expression.ngx -->
1717

18+
@let func = user.func();
19+
<!--^^^^^^ meta.let.identifier.ngx -->
20+
<!-- ^^^^ variable.other.readwrite.ngx -->
21+
<!-- ^ meta.let.ngx keyword.operator.assignment.ngx -->
22+
<!-- ^ meta.let.value.ngx - meta.path -->
23+
<!-- ^^^^^^^^^^^ meta.let.value.ngx meta.path.ngx - meta.path meta.path -->
24+
<!-- ^^^^ variable.other.object.ngx -->
25+
<!-- ^ punctuation.accessor.ngx -->
26+
<!-- ^^^^ variable.function.method.ngx -->
27+
<!-- ^ punctuation.section.arguments.begin.ngx -->
28+
<!-- ^ punctuation.section.arguments.end.ngx -->
29+
<!-- ^ punctuation.terminator.expression.ngx -->
30+
1831
@let greeting = 'Hello, ' + name;
1932
<!--^^^^^^^^^^ meta.let.identifier.ngx -->
2033
<!-- ^^^^^^^^ variable.other.readwrite.ngx -->
@@ -39,6 +52,97 @@
3952
<!-- ^^^^^ meta.function-call.identifier.ngx variable.function.filter.ngx -->
4053
<!-- ^ punctuation.terminator.expression.ngx -->
4154

55+
@let item = var[10]['bar'];
56+
<!--^^^^^^ meta.let.identifier.ngx -->
57+
<!-- ^ meta.let.ngx -->
58+
<!-- ^^^^^^^^^^^^^^^ meta.let.value.ngx -->
59+
<!-- ^ - meta.let -->
60+
<!-- ^^^^ variable.other.readwrite.ngx -->
61+
<!-- ^ keyword.operator.assignment.ngx -->
62+
<!-- ^^^ variable.other.readwrite.ngx -->
63+
<!-- ^^^^^^^^^^^ meta.subscription.ngx -->
64+
<!-- ^ punctuation.section.subscription.begin.ngx -->
65+
<!-- ^^ meta.number.integer.decimal.ngx constant.numeric.value.ngx -->
66+
<!-- ^ punctuation.section.subscription.end.ngx -->
67+
<!-- ^ punctuation.section.subscription.begin.ngx -->
68+
<!-- ^^^^^ meta.string.ngx string.quoted.single.ngx -->
69+
<!-- ^ punctuation.section.subscription.end.ngx -->
70+
<!-- ^ punctuation.terminator.expression.ngx -->
71+
72+
<!-- qualified property with missing leading object in incomplete ternary expression -->
73+
@let path = .foo?.bar? ;
74+
<!--^^^^^^ meta.let.identifier.ngx -->
75+
<!-- ^ meta.let.ngx -->
76+
<!-- ^ meta.let.value.ngx - meta.path -->
77+
<!-- ^^^^^^^^^ meta.let.value.ngx meta.path.ngx - meta.path meta.path -->
78+
<!-- ^^ meta.let.value.ngx - meta.path -->
79+
<!-- ^ - meta.let -->
80+
<!-- ^^^^ variable.other.readwrite.ngx -->
81+
<!-- ^ keyword.operator.assignment.ngx -->
82+
<!-- ^ punctuation.accessor.ngx -->
83+
<!-- ^^^ variable.other.object.ngx -->
84+
<!-- ^^ punctuation.accessor.ngx -->
85+
<!-- ^^^ variable.other.member.ngx -->
86+
<!-- ^ keyword.operator.ternary.ngx -->
87+
<!-- ^ punctuation.terminator.expression.ngx -->
88+
89+
@let path = .orders.value()?.[0]?.$extra?.#currency.unit;
90+
<!--^^^^^^ meta.let.identifier.ngx -->
91+
<!-- ^ meta.let.ngx -->
92+
<!-- ^ meta.let.value.ngx - meta.path -->
93+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.let.value.ngx meta.path.ngx - meta.path meta.path -->
94+
<!-- ^^^^ variable.other.readwrite.ngx -->
95+
<!-- ^ keyword.operator.assignment.ngx -->
96+
<!-- ^ punctuation.accessor.ngx -->
97+
<!-- ^^^^^^ variable.other.object.ngx -->
98+
<!-- ^ punctuation.accessor.ngx -->
99+
<!-- ^^^^^ meta.function-call.identifier.ngx variable.function.method.ngx -->
100+
<!-- ^^ meta.function-call.arguments.ngx -->
101+
<!-- ^ punctuation.section.arguments.begin.ngx -->
102+
<!-- ^ punctuation.section.arguments.end.ngx -->
103+
<!-- ^^ punctuation.accessor.ngx -->
104+
<!-- ^^^ meta.subscription.ngx -->
105+
<!-- ^ punctuation.section.subscription.begin.ngx -->
106+
<!-- ^ meta.number.integer.decimal.ngx constant.numeric.value.ngx -->
107+
<!-- ^ punctuation.section.subscription.end.ngx -->
108+
<!-- ^^ punctuation.accessor.ngx -->
109+
<!-- ^^^^^^ variable.other.object.ngx -->
110+
<!-- ^ punctuation.definition.variable.ngx -->
111+
<!-- ^^ punctuation.accessor.ngx -->
112+
<!-- ^^^^^^^^^ variable.other.object.ngx -->
113+
<!-- ^ punctuation.definition.variable.ngx -->
114+
<!-- ^ punctuation.accessor.ngx -->
115+
<!-- ^^^^ variable.other.member.ngx -->
116+
<!-- ^ punctuation.terminator.expression.ngx -->
117+
118+
@let path = orders.value()?.[0]?.$extra?.#currency.unit;
119+
<!--^^^^^^ meta.let.identifier.ngx -->
120+
<!-- ^ meta.let.ngx -->
121+
<!-- ^ meta.let.value.ngx - meta.path -->
122+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.let.value.ngx meta.path.ngx - meta.path meta.path -->
123+
<!-- ^^^^ variable.other.readwrite.ngx -->
124+
<!-- ^ keyword.operator.assignment.ngx -->
125+
<!-- ^^^^^^ variable.other.object.ngx -->
126+
<!-- ^ punctuation.accessor.ngx -->
127+
<!-- ^^^^^ meta.function-call.identifier.ngx variable.function.method.ngx -->
128+
<!-- ^^ meta.function-call.arguments.ngx -->
129+
<!-- ^ punctuation.section.arguments.begin.ngx -->
130+
<!-- ^ punctuation.section.arguments.end.ngx -->
131+
<!-- ^^ punctuation.accessor.ngx -->
132+
<!-- ^^^ meta.subscription.ngx -->
133+
<!-- ^ punctuation.section.subscription.begin.ngx -->
134+
<!-- ^ meta.number.integer.decimal.ngx constant.numeric.value.ngx -->
135+
<!-- ^ punctuation.section.subscription.end.ngx -->
136+
<!-- ^^ punctuation.accessor.ngx -->
137+
<!-- ^^^^^^ variable.other.object.ngx -->
138+
<!-- ^ punctuation.definition.variable.ngx -->
139+
<!-- ^^ punctuation.accessor.ngx -->
140+
<!-- ^^^^^^^^^ variable.other.object.ngx -->
141+
<!-- ^ punctuation.definition.variable.ngx -->
142+
<!-- ^ punctuation.accessor.ngx -->
143+
<!-- ^^^^ variable.other.member.ngx -->
144+
<!-- ^ punctuation.terminator.expression.ngx -->
145+
42146
<!--
43147
Control Flow
44148
https://angular.dev/guide/templates/control-flow#conditionally-display-content-with-if-else-if-and-else
@@ -92,7 +196,7 @@
92196
<!-- ^^ punctuation.section.embedded.begin.ngx.html -->
93197
<!-- ^^^^^^^ source.ngx.embedded.html -->
94198
<!-- ^ variable.other.object.ngx -->
95-
<!-- ^ meta.function-call.identifier.ngx variable.function.ngx -->
199+
<!-- ^ meta.function-call.identifier.ngx variable.function.method.ngx -->
96200
<!-- ^ meta.function-call.arguments.ngx punctuation.section.arguments.begin.ngx -->
97201
<!-- ^ meta.function-call.arguments.ngx punctuation.section.arguments.end.ngx -->
98202
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
@@ -528,7 +632,7 @@
528632
<!-- property subscription -->
529633
{{ person['name'][0] = "Mirabel" }}
530634
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.ngx.html -->
531-
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ngx.embedded.html -->
635+
<!--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ngx.embedded.html - meta.path -->
532636
<!-- ^^^^^^ variable.other.readwrite.ngx -->
533637
<!-- ^^^^^^^^^^^ meta.subscription.ngx -->
534638
<!-- ^ punctuation.section.subscription.begin.ngx -->
@@ -546,24 +650,64 @@
546650
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
547651

548652
{{ obj?.member }}
549-
<!--^^^^^^^^^^^^^^^ meta.embedded.ngx.html -->
550-
<!--^^^^^^^^^^^^^ source.ngx.embedded.html -->
653+
<!--^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
654+
<!-- ^^^^^^^^^^^ meta.embedded.ngx.html source.ngx.embedded.html meta.path.ngx - meta.path meta.path -->
655+
<!-- ^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
656+
<!-- ^^ meta.embedded.ngx.html - source.ngx -->
551657
<!-- ^^^ variable.other.object.ngx -->
552658
<!-- ^^ punctuation.accessor.ngx -->
553659
<!-- ^^^^^^ variable.other.member.ngx -->
554660
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
555661

662+
{{ obj.member [5] }}
663+
<!--^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
664+
<!-- ^^^^^^^^^^^^^^ meta.embedded.ngx.html source.ngx.embedded.html meta.path.ngx - meta.path meta.path -->
665+
<!-- ^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
666+
<!-- ^^ meta.embedded.ngx.html - source.ngx -->
667+
<!-- ^^^ variable.other.object.ngx -->
668+
<!-- ^ punctuation.accessor.ngx -->
669+
<!-- ^^^^^^ variable.other.member.ngx -->
670+
<!-- ^ - meta.subscription - variable -->
671+
<!-- ^^^ meta.subscription.ngx -->
672+
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
673+
556674
{{ obj.method() }}
557-
<!--^^^^^^^^^^^^^^^^ meta.embedded.ngx.html -->
558-
<!--^^^^^^^^^^^^^^ source.ngx.embedded.html -->
675+
<!--^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
676+
<!-- ^^^^^^^^^^^^ meta.embedded.ngx.html source.ngx.embedded.html meta.path.ngx - meta.path meta.path -->
677+
<!-- ^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
678+
<!-- ^^ meta.embedded.ngx.html - source.ngx -->
559679
<!-- ^^^ variable.other.object.ngx -->
560680
<!-- ^ punctuation.accessor.ngx -->
561-
<!-- ^^^^^^ meta.function-call.identifier.ngx variable.function.ngx -->
681+
<!-- ^^^^^^ meta.function-call.identifier.ngx variable.function.method.ngx -->
562682
<!-- ^^ meta.function-call.arguments.ngx -->
563683
<!-- ^ punctuation.section.arguments.begin.ngx -->
564684
<!-- ^ punctuation.section.arguments.end.ngx -->
565685
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
566686

687+
{{ orders.value()?.[0]?.$extra?.#currency }}
688+
<!--^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
689+
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.ngx.html source.ngx.embedded.html meta.path.ngx - meta.path meta.path -->
690+
<!-- ^ meta.embedded.ngx.html source.ngx.embedded.html - meta.path -->
691+
<!-- ^^ meta.embedded.ngx.html - source.ngx -->
692+
<!-- ^^^^^^ variable.other.object.ngx -->
693+
<!-- ^ punctuation.accessor.ngx -->
694+
<!-- ^^^^^ meta.function-call.identifier.ngx variable.function.method.ngx -->
695+
<!-- ^^ meta.function-call.arguments.ngx -->
696+
<!-- ^ punctuation.section.arguments.begin.ngx -->
697+
<!-- ^ punctuation.section.arguments.end.ngx -->
698+
<!-- ^^ punctuation.accessor.ngx -->
699+
<!-- ^^^ meta.subscription.ngx -->
700+
<!-- ^ punctuation.section.subscription.begin.ngx -->
701+
<!-- ^ meta.number.integer.decimal.ngx constant.numeric.value.ngx -->
702+
<!-- ^ punctuation.section.subscription.end.ngx -->
703+
<!-- ^^ punctuation.accessor.ngx -->
704+
<!-- ^^^^^^ variable.other.object.ngx -->
705+
<!-- ^ punctuation.definition.variable.ngx -->
706+
<!-- ^^ punctuation.accessor.ngx -->
707+
<!-- ^^^^^^^^^ variable.other.member.ngx -->
708+
<!-- ^ punctuation.definition.variable.ngx -->
709+
<!-- ^^ punctuation.section.embedded.end.ngx.html -->
710+
567711
{{ func(arg, "value") }}
568712
<!--^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.ngx.html -->
569713
<!--^^^^^^^^^^^^^^^^^^^^ source.ngx.embedded.html -->

0 commit comments

Comments
 (0)