Skip to content

Commit d714adc

Browse files
ayazhafizKeen Yee Liau
authored andcommitted
feat: add textmate grammar for template property bindings
Adds syntax highlighting support for template property bindings. In particular, the expression in the bound property value is highlighted as JavaScript syntax. The screenshot attached to the PR for this commit demonstrates the change. Partially addresses #483 Closes #253
1 parent 5d640de commit d714adc

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

syntaxes/template.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"patterns": [
55
{
66
"include": "#interpolation"
7+
},
8+
{
9+
"include": "#propertyBinding"
710
}
811
],
912
"repository": {
@@ -26,6 +29,33 @@
2629
"include": "source.js"
2730
}
2831
]
32+
},
33+
34+
"propertyBinding": {
35+
"begin": "(\\[.*\\])(=)(\"|')",
36+
"beginCaptures": {
37+
"1": {
38+
"name": "entity.other.attribute-name.html"
39+
},
40+
"2": {
41+
"name": "punctuation.separator.key-value.html"
42+
},
43+
"3": {
44+
"name": "punctuation.definition.string.begin.html string.quoted.html"
45+
}
46+
},
47+
"end": "\\3",
48+
"endCaptures": {
49+
"0": {
50+
"name": "punctuation.definition.string.end.html string.quoted.html"
51+
}
52+
},
53+
"contentName": "source.js",
54+
"patterns": [
55+
{
56+
"include": "source.js"
57+
}
58+
]
2959
}
3060
}
3161
}

syntaxes/test/data/template.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
<!-- Interpolation test -->
22
<div>{{ call(1 + 2 + 3) }}</div>
3+
4+
<!-- Property binding test -->
5+
<div [ ngStyle ]="{'max-width.px': i * 2 + 5}"></div>

syntaxes/test/data/template.html.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@
66
# ^^^^^^^^^^^^^^^^^ template.ng source.js
77
# ^^ template.ng punctuation.definition.block.ts
88
# ^^^^^^^ template.ng
9+
>
10+
><!-- Property binding test -->
11+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
12+
><div [ ngStyle ]="{'max-width.px': i * 2 + 5}"></div>
13+
#^^^^^ template.ng
14+
# ^^^^^^^^^^^ template.ng entity.other.attribute-name.html
15+
# ^ template.ng punctuation.separator.key-value.html
16+
# ^ template.ng punctuation.definition.string.begin.html string.quoted.html
17+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng source.js
18+
# ^ template.ng punctuation.definition.string.end.html string.quoted.html
19+
# ^^^^^^^^ template.ng
920
>

0 commit comments

Comments
 (0)