Skip to content

Commit c4930a9

Browse files
committed
Syntax highlighting for string method names
Attempt to fix #154
1 parent dcfc96b commit c4930a9

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
33
"editor.insertSpaces": true
4-
}
4+
}

TypeScript.YAML-tmLanguage

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ repository:
154154

155155
method-declaration:
156156
name: meta.method.declaration.ts
157-
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
157+
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:(\[*)(`|'|"*)(.*)(`|'|"*)(\]*)\s*(\??)))?\s*(?=\(|\<)'
158158
beginCaptures:
159159
'1': { name: storage.modifier.ts } # captures keyword (abstract)
160160
'2': { name: storage.modifier.ts } # captures keyword (public or private or protected)
161161
'3': { name: storage.modifier.ts } # captures keyword (async)
162162
'4': { name: storage.type.property.ts } # captures keyword (get|set)
163163
'5': { name: keyword.operator.ts } # captures keyword (new)
164164
'6': { name: storage.type.ts } # captures keyword (constructor)
165-
'7': { name: entity.name.function.ts } # captures method name ([a-zA-Z_$][\.\w$]*)
165+
'7': { name: entity.name.function.ts } # captures method name (\[*)(`|'|"*)([a-zA-Z_$][\.\w$]*)(`|'|"*)(\]*)
166166
'8': { name: keyword.operator.ts } # captures (\??)
167167
end: '(?=\}|;|,)|(?<=\})'
168168
patterns:

tests/baselines/Issue154.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[2, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
2+
[8, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.single.ts
3+
[14, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
4+
[20, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.double.ts
5+
[26, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
6+
[32, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts entity.name.function.ts

tests/cases/Issue154.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class TestCase0 {
2+
^^['123']() {
3+
this.registerComponent('foo-bar');
4+
}
5+
}
6+
7+
class TestCase1 {
8+
^^'$'() {
9+
this.registerComponent('foo-bar');
10+
}
11+
}
12+
13+
class TestCase2 {
14+
^^[`foo`]() {
15+
this.registerComponent('foo-bar');
16+
}
17+
}
18+
19+
class TestCase3 {
20+
^^"foo"() {
21+
this.registerComponent('foo-bar');
22+
}
23+
}
24+
25+
class TestCase4 {
26+
^^["foo"]() {
27+
this.registerComponent('foo-bar');
28+
}
29+
}
30+
31+
class TestCase5 {
32+
^^foo() {
33+
this.registerComponent('foo-bar');
34+
}
35+
}

tests/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ function addTestCase(file: string, generatedText: string, baselinesText: string)
2424
it('should be the same', () => {
2525
chai.expect(compareText(generatedText, baselinesText)).to.true;
2626
})
27-
})
28-
}
27+
})
28+
}

0 commit comments

Comments
 (0)