Skip to content

Commit f6cbb70

Browse files
committed
Fixes unnecessary indirection of single line comment which also fixes how the new line is handled
Fixes #459 and #460
1 parent 1acd630 commit f6cbb70

File tree

6 files changed

+56
-57
lines changed

6 files changed

+56
-57
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,16 +1996,12 @@ repository:
19961996
end: \*/
19971997
endCaptures:
19981998
'0': { name: punctuation.definition.comment.ts }
1999-
- begin: (^[ \t]+)?(?=//)
1999+
- begin: (^[ \t]+)?(//)
20002000
beginCaptures:
20012001
'1': { name: punctuation.whitespace.comment.leading.ts }
2002-
end: (?=^[^/][^/])
2003-
patterns:
2004-
- name: comment.line.double-slash.ts
2005-
begin: //
2006-
beginCaptures:
2007-
'0': { name: punctuation.definition.comment.ts }
2008-
end: (?=^)
2002+
'2': { name: comment.line.double-slash.ts punctuation.definition.comment.ts }
2003+
end: (?=^)
2004+
contentName: comment.line.double-slash.ts
20092005

20102006
directives:
20112007
name: comment.line.triple-slash.directive.ts

TypeScript.tmLanguage

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,36 +5495,24 @@
54955495
</dict>
54965496
<dict>
54975497
<key>begin</key>
5498-
<string>(^[ \t]+)?(?=//)</string>
5498+
<string>(^[ \t]+)?(//)</string>
54995499
<key>beginCaptures</key>
55005500
<dict>
55015501
<key>1</key>
55025502
<dict>
55035503
<key>name</key>
55045504
<string>punctuation.whitespace.comment.leading.ts</string>
55055505
</dict>
5506-
</dict>
5507-
<key>end</key>
5508-
<string>(?=^[^/][^/])</string>
5509-
<key>patterns</key>
5510-
<array>
5506+
<key>2</key>
55115507
<dict>
55125508
<key>name</key>
5513-
<string>comment.line.double-slash.ts</string>
5514-
<key>begin</key>
5515-
<string>//</string>
5516-
<key>beginCaptures</key>
5517-
<dict>
5518-
<key>0</key>
5519-
<dict>
5520-
<key>name</key>
5521-
<string>punctuation.definition.comment.ts</string>
5522-
</dict>
5523-
</dict>
5524-
<key>end</key>
5525-
<string>(?=^)</string>
5509+
<string>comment.line.double-slash.ts punctuation.definition.comment.ts</string>
55265510
</dict>
5527-
</array>
5511+
</dict>
5512+
<key>end</key>
5513+
<string>(?=^)</string>
5514+
<key>contentName</key>
5515+
<string>comment.line.double-slash.ts</string>
55285516
</dict>
55295517
</array>
55305518
</dict>

TypeScriptReact.tmLanguage

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,36 +5441,24 @@
54415441
</dict>
54425442
<dict>
54435443
<key>begin</key>
5444-
<string>(^[ \t]+)?(?=//)</string>
5444+
<string>(^[ \t]+)?(//)</string>
54455445
<key>beginCaptures</key>
54465446
<dict>
54475447
<key>1</key>
54485448
<dict>
54495449
<key>name</key>
54505450
<string>punctuation.whitespace.comment.leading.tsx</string>
54515451
</dict>
5452-
</dict>
5453-
<key>end</key>
5454-
<string>(?=^[^/][^/])</string>
5455-
<key>patterns</key>
5456-
<array>
5452+
<key>2</key>
54575453
<dict>
54585454
<key>name</key>
5459-
<string>comment.line.double-slash.tsx</string>
5460-
<key>begin</key>
5461-
<string>//</string>
5462-
<key>beginCaptures</key>
5463-
<dict>
5464-
<key>0</key>
5465-
<dict>
5466-
<key>name</key>
5467-
<string>punctuation.definition.comment.tsx</string>
5468-
</dict>
5469-
</dict>
5470-
<key>end</key>
5471-
<string>(?=^)</string>
5455+
<string>comment.line.double-slash.tsx punctuation.definition.comment.tsx</string>
54725456
</dict>
5473-
</array>
5457+
</dict>
5458+
<key>end</key>
5459+
<string>(?=^)</string>
5460+
<key>contentName</key>
5461+
<string>comment.line.double-slash.tsx</string>
54745462
</dict>
54755463
</array>
54765464
</dict>

build/build.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ function changeTsToTsx(str: string) {
1717
return str.replace(/\.ts/g, '.tsx');
1818
}
1919

20-
function fixGrammarScopeNames(rule: any) {
21-
if (typeof rule.name === 'string') {
22-
rule.name = changeTsToTsx(rule.name);
23-
}
24-
for (var property in rule) {
25-
var value = rule[property];
26-
if (typeof value === 'object') {
27-
fixGrammarScopeNames(value);
28-
}
20+
function fixRuleNames(rule: any, name: string) {
21+
if (typeof rule[name] === 'string') {
22+
rule[name] = changeTsToTsx(rule[name]);
23+
}
24+
}
25+
26+
function fixGrammarScopeNames(rule: any) {
27+
fixRuleNames(rule, "name");
28+
fixRuleNames(rule, "contentName");
29+
for (var property in rule) {
30+
var value = rule[property];
31+
if (typeof value === 'object') {
32+
fixGrammarScopeNames(value);
33+
}
2934
}
3035
}
3136

tests/baselines/Issue460.baseline.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
original file
2+
-----------------------------------
3+
// single-line comment
4+
/* multi-line comment */
5+
-----------------------------------
6+
7+
Grammar: TypeScript.tmLanguage
8+
-----------------------------------
9+
>// single-line comment
10+
^^
11+
source.ts comment.line.double-slash.ts punctuation.definition.comment.ts
12+
^^^^^^^^^^^^^^^^^^^^^^
13+
source.ts comment.line.double-slash.ts
14+
>/* multi-line comment */
15+
^^
16+
source.ts comment.block.ts punctuation.definition.comment.ts
17+
^^^^^^^^^^^^^^^^^^^^
18+
source.ts comment.block.ts
19+
^^
20+
source.ts comment.block.ts punctuation.definition.comment.ts

tests/cases/Issue460.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// single-line comment
2+
/* multi-line comment */

0 commit comments

Comments
 (0)