Skip to content

Commit c09e75e

Browse files
authored
fix(syntaxes): do not syntax highlight commented template properties (#472)
* fix(syntaxes): do not syntax highlight commented template properties Prevents syntax highlighting inline templates by excluding the grammar injection on decorators with comments. The grammar test framework does not currently support specifying grammar rule exclusions (PanAeon/vscode-tmgrammar-test#6), so instead the test cases are moved to snapshot tests that demonstrate that no other grammars are added on excluded cases. * fixup! fix(syntaxes): do not syntax highlight commented template properties * fixup! fix(syntaxes): do not syntax highlight commented template properties * fixup! fix(syntaxes): do not syntax highlight commented template properties
1 parent 3ee3c14 commit c09e75e

File tree

4 files changed

+121
-20
lines changed

4 files changed

+121
-20
lines changed

scripts/syntax.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#!/usr/bin/env bash
2+
# Usage:
3+
# scripts/syntax.sh [-u]
4+
#
5+
# Arguments:
6+
# -u update snapshot files
27

38
set -ex -o pipefail
49

510
DUMMY_GRAMMARS=$(find syntaxes/test -name '*-dummy.json' -exec echo "-g {}" \; | tr '\n' ' ')
11+
ARGS=$(cat<<ARGS
12+
-s template.ng
13+
-g syntaxes/template.ng.json $DUMMY_GRAMMARS
14+
-t syntaxes/test/**/*.ts
15+
ARGS
16+
)
617

7-
# Template syntax tests
8-
yarn vscode-tmgrammar-test \
9-
-s template.ng \
10-
-g syntaxes/template.ng.json $DUMMY_GRAMMARS \
11-
-t "syntaxes/test/**/*.ts"
18+
# Snapshot tests
19+
yarn vscode-tmgrammar-snap $ARGS "$@"

syntaxes/template.ng.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scopeName": "template.ng",
3-
"injectionSelector": "L:meta.decorator.ts",
3+
"injectionSelector": "L:meta.decorator.ts -comment",
44
"patterns": [
55
{
66
"include": "#ts-decorator"

syntaxes/test/inline_template.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@
44
@Component({
55
//// Property key/value test
66
template: '<div></div>',
7-
//^^^^^^^^^ meta.object-literal.key.ts
8-
// ^^^^^^^^^^^ template.ng (fake grammar token)
97

108
//// String delimiter tests
119
template: `<div></div>`,
12-
// ^ string
13-
// ^ string
1410
template: "<div></div>",
15-
// ^ string
16-
// ^ string
1711
template: '<div></div>',
18-
// ^ string
19-
// ^ string
2012

2113
//// Parenthesization tests
2214
template: ( (( '<div></div>' )) ),
23-
// ^ meta.brace.round.ts
24-
// ^^ meta.brace.round.ts
25-
// ^ string
26-
// ^ string
27-
// ^^ meta.brace.round.ts
28-
// ^ meta.brace.round.ts
15+
16+
//// Comments tests
17+
// template: '<div></div>'
18+
/*
19+
* template: '<div></div>'
20+
*/
21+
/**
22+
* template: '<div></div>'
23+
*/
2924
})
3025
export class TMComponent{}

syntaxes/test/inline_template.ts.snap

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
>// SYNTAX TEST "template.ng"
2+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
3+
>/* clang-format off */
4+
#^^^^^^^^^^^^^^^^^^^^^^^ template.ng
5+
>
6+
>@Component({
7+
#^^^^^^^^^^^^^ template.ng
8+
>//// Property key/value test
9+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
10+
> template: '<div></div>',
11+
#^^ template.ng
12+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
13+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
14+
# ^ template.ng
15+
# ^ template.ng string
16+
# ^^^^^^^^^^^ template.ng
17+
# ^ template.ng string
18+
# ^^ template.ng
19+
>
20+
>//// String delimiter tests
21+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
22+
> template: `<div></div>`,
23+
#^^ template.ng
24+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
25+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
26+
# ^ template.ng
27+
# ^ template.ng string
28+
# ^^^^^^^^^^^ template.ng
29+
# ^ template.ng string
30+
# ^^ template.ng
31+
> template: "<div></div>",
32+
#^^ template.ng
33+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
34+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
35+
# ^ template.ng
36+
# ^ template.ng string
37+
# ^^^^^^^^^^^ template.ng
38+
# ^ template.ng string
39+
# ^^ template.ng
40+
> template: '<div></div>',
41+
#^^ template.ng
42+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
43+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
44+
# ^ template.ng
45+
# ^ template.ng string
46+
# ^^^^^^^^^^^ template.ng
47+
# ^ template.ng string
48+
# ^^ template.ng
49+
>
50+
>//// Parenthesization tests
51+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
52+
> template: ( (( '<div></div>' )) ),
53+
#^^ template.ng
54+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
55+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
56+
# ^ template.ng
57+
# ^ template.ng meta.brace.round.ts
58+
# ^ template.ng
59+
# ^ template.ng meta.brace.round.ts
60+
# ^ template.ng meta.brace.round.ts
61+
# ^ template.ng
62+
# ^ template.ng string
63+
# ^^^^^^^^^^^ template.ng
64+
# ^ template.ng string
65+
# ^ template.ng
66+
# ^ template.ng meta.brace.round.ts
67+
# ^ template.ng meta.brace.round.ts
68+
# ^ template.ng
69+
# ^ template.ng meta.brace.round.ts
70+
# ^^ template.ng
71+
>
72+
>//// Comments tests
73+
#^^^^^^^^^^^^^^^^^^^^ template.ng
74+
> // template: '<div></div>'
75+
#^^^^^ template.ng
76+
# ^^^^^^^^ template.ng meta.object-literal.key.ts
77+
# ^ template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
78+
# ^ template.ng
79+
# ^ template.ng string
80+
# ^^^^^^^^^^^ template.ng
81+
# ^ template.ng string
82+
> /*
83+
#^^^^^ template.ng
84+
> * template: '<div></div>'
85+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
86+
> */
87+
#^^^^^^ template.ng
88+
> /**
89+
#^^^^^^ template.ng
90+
> * template: '<div></div>'
91+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
92+
> */
93+
#^^^^^^ template.ng
94+
>})
95+
#^^^ template.ng
96+
>export class TMComponent{}
97+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^ template.ng
98+
>

0 commit comments

Comments
 (0)