fix(vscode-extension): allow Tailwind-style characters in property binding names

The property binding grammar only allowed [-_a-zA-Z0-9.$] in binding
names, so Tailwind class bindings such as `[class.hover:flex]`,
`[class.!p-4]` or `[class.bg-primary/30]` did not match and fell back
to plain HTML attribute highlighting. The compiler is deliberately
lenient about the characters between the square brackets of a bound
attribute name, so allow `:`, `!`, `/` and `@` in the grammar as well.

Also removes the nested quantifier from the binding name regexes
((?:A+|B)* -> (?:A|B)*), which could trigger super-linear backtracking
on lines with an unterminated binding. The recognized language is
unchanged: the snapshot goldens are identical.

Fixes #67679
This commit is contained in:
aparziale
2026-09-25 16:00:56 -07:00
committed by Andrew Scott
parent 3c5ed06456
commit 6f7f66503d
4 changed files with 97 additions and 4 deletions
@@ -25,7 +25,7 @@ export const TemplateTag: GrammarDefinition = {
name: 'template.tag.leading-space',
},
propertyBinding: {
begin: /(\[\s*@?(?:[-_a-zA-Z0-9.$]+|\[[^\[\]]*]|\([^()]*\))*%?\s*])(=)(["'])/,
begin: /(\[\s*@?(?:[-_a-zA-Z0-9.$:!\/@]|\[[^\[\]]*]|\([^()]*\))*%?\s*])(=)(["'])/,
beginCaptures: {
1: {
name: 'entity.other.attribute-name.html entity.other.ng-binding-name.property.html',
@@ -108,7 +108,7 @@ export const TemplateTag: GrammarDefinition = {
patterns: [
{
match:
/([\[\(]{1,2}|\*)(?:\s*)(@?(?:[-_a-zA-Z0-9.$]+|\[[^\[\]]*]|\([^()]*\))*%?)(?:\s*)([\]\)]{1,2})?/,
/([\[\(]{1,2}|\*)(?:\s*)(@?(?:[-_a-zA-Z0-9.$:!\/@]|\[[^\[\]]*]|\([^()]*\))*%?)(?:\s*)([\]\)]{1,2})?/,
captures: {
1: {name: 'punctuation.definition.ng-binding-name.begin.html'},
2: {
@@ -27,7 +27,7 @@
"name": "template.tag.leading-space"
},
"propertyBinding": {
"begin": "(\\[\\s*@?(?:[-_a-zA-Z0-9.$]+|\\[[^\\[\\]]*]|\\([^()]*\\))*%?\\s*])(=)([\"'])",
"begin": "(\\[\\s*@?(?:[-_a-zA-Z0-9.$:!\\/@]|\\[[^\\[\\]]*]|\\([^()]*\\))*%?\\s*])(=)([\"'])",
"beginCaptures": {
"1": {
"name": "entity.other.attribute-name.html entity.other.ng-binding-name.property.html",
@@ -157,7 +157,7 @@
"bindingKey": {
"patterns": [
{
"match": "([\\[\\(]{1,2}|\\*)(?:\\s*)(@?(?:[-_a-zA-Z0-9.$]+|\\[[^\\[\\]]*]|\\([^()]*\\))*%?)(?:\\s*)([\\]\\)]{1,2})?",
"match": "([\\[\\(]{1,2}|\\*)(?:\\s*)(@?(?:[-_a-zA-Z0-9.$:!\\/@]|\\[[^\\[\\]]*]|\\([^()]*\\))*%?)(?:\\s*)([\\]\\)]{1,2})?",
"captures": {
"1": {
"name": "punctuation.definition.ng-binding-name.begin.html"
@@ -14,6 +14,13 @@
<div [%invalidProperty]="val"></div>
<div [invalidProperty)="val"></div>
<div [class.min-h-[calc(100vh-var(--header-height))]]="val"></div>
<div [class.hover:flex]="val"></div>
<div [class.!p-4]="val"></div>
<div [class.bg-primary/30]="val"></div>
<div [class.@md:flex]="val"></div>
<div [class.px-3.5]="val"></div>
<div [class.sm:hover:!bg-red-500/75]="val"></div>
<img [attr.xlink:href]="val" />
<!-- Event binding test -->
<button (click)="onClick($event)"></button>
@@ -139,6 +139,92 @@
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.hover:flex]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.hover:flex.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.hover:flex.html punctuation.accessor.html
# ^^^^^^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.hover:flex.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.!p-4]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.!p-4.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.!p-4.html punctuation.accessor.html
# ^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.!p-4.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.bg-primary/30]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.bg-primary/30.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.bg-primary/30.html punctuation.accessor.html
# ^^^^^^^^^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.bg-primary/30.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.@md:flex]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.@md:flex.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.@md:flex.html punctuation.accessor.html
# ^^^^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.@md:flex.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.px-3.5]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.px-3.5.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.px-3.5.html punctuation.accessor.html
# ^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.px-3.5.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.px-3.5.html punctuation.accessor.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.px-3.5.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><div [class.sm:hover:!bg-red-500/75]="val"></div>
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.sm:hover:!bg-red-500/75.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.sm:hover:!bg-red-500/75.html punctuation.accessor.html
# ^^^^^^^^^^^^^^^^^^^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.class.sm:hover:!bg-red-500/75.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^^^^^ template.tag.ng
><img [attr.xlink:href]="val" />
#^^^^^ template.tag.ng
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.begin.html
# ^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.attr.xlink:href.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.attr.xlink:href.html punctuation.accessor.html
# ^^^^^^^^^^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html entity.other.ng-binding-name.attr.xlink:href.html
# ^ template.tag.ng meta.ng-binding.property.html entity.other.attribute-name.html entity.other.ng-binding-name.property.html punctuation.definition.ng-binding-name.end.html
# ^ template.tag.ng meta.ng-binding.property.html punctuation.separator.key-value.html
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.begin.html
# ^^^ template.tag.ng meta.ng-binding.property.html expression.ng variable.other.readwrite.ts
# ^ template.tag.ng meta.ng-binding.property.html string.quoted.html punctuation.definition.string.end.html
# ^^^^ template.tag.ng
>
><!-- Event binding test -->
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.tag.ng