Skip to content

Commit bf14f62

Browse files
committed
Update the ternary expression : operator to consume leading white spaces
Fixes #579
1 parent 0c8c091 commit bf14f62

File tree

5 files changed

+138
-6
lines changed

5 files changed

+138
-6
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,9 +1095,9 @@ repository:
10951095
begin: (?!\?\.\s*[^[:digit:]])(\?)
10961096
beginCaptures:
10971097
'1': { name: keyword.operator.ternary.ts }
1098-
end: (:)
1098+
end: \s*(:)
10991099
endCaptures:
1100-
'0': { name: keyword.operator.ternary.ts }
1100+
'1': { name: keyword.operator.ternary.ts }
11011101
patterns:
11021102
- include: '#expression'
11031103

TypeScript.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,10 +3427,10 @@
34273427
</dict>
34283428
</dict>
34293429
<key>end</key>
3430-
<string>(:)</string>
3430+
<string>\s*(:)</string>
34313431
<key>endCaptures</key>
34323432
<dict>
3433-
<key>0</key>
3433+
<key>1</key>
34343434
<dict>
34353435
<key>name</key>
34363436
<string>keyword.operator.ternary.ts</string>

TypeScriptReact.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,10 +3431,10 @@
34313431
</dict>
34323432
</dict>
34333433
<key>end</key>
3434-
<string>(:)</string>
3434+
<string>\s*(:)</string>
34353435
<key>endCaptures</key>
34363436
<dict>
3437-
<key>0</key>
3437+
<key>1</key>
34383438
<dict>
34393439
<key>name</key>
34403440
<string>keyword.operator.ternary.tsx</string>

tests/baselines/Issue579.baseline.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
original file
2+
-----------------------------------
3+
function f(): (x: number) => any {
4+
return true ? x => f() : x => 0;
5+
}
6+
const x = 0; // no highlight in rest of file
7+
-----------------------------------
8+
9+
Grammar: TypeScript.tmLanguage
10+
-----------------------------------
11+
>function f(): (x: number) => any {
12+
^^^^^^^^
13+
source.ts meta.function.ts storage.type.function.ts
14+
^
15+
source.ts meta.function.ts
16+
^
17+
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
18+
^
19+
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
20+
^
21+
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
22+
^
23+
source.ts meta.function.ts meta.return.type.ts keyword.operator.type.annotation.ts
24+
^
25+
source.ts meta.function.ts meta.return.type.ts
26+
^
27+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
28+
^
29+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts variable.parameter.ts
30+
^
31+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
32+
^
33+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts
34+
^^^^^^
35+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
36+
^
37+
source.ts meta.function.ts meta.return.type.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
38+
^
39+
source.ts meta.function.ts meta.return.type.ts
40+
^^
41+
source.ts meta.function.ts meta.return.type.ts meta.type.function.return.ts storage.type.function.arrow.ts
42+
^
43+
source.ts meta.function.ts meta.return.type.ts meta.type.function.return.ts
44+
^^^
45+
source.ts meta.function.ts meta.return.type.ts meta.type.function.return.ts support.type.primitive.ts
46+
^
47+
source.ts meta.function.ts meta.return.type.ts meta.type.function.return.ts
48+
^
49+
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
50+
^^
51+
source.ts meta.function.ts meta.block.ts
52+
> return true ? x => f() : x => 0;
53+
^^^^
54+
source.ts meta.function.ts meta.block.ts
55+
^^^^^^
56+
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
57+
^
58+
source.ts meta.function.ts meta.block.ts
59+
^^^^
60+
source.ts meta.function.ts meta.block.ts constant.language.boolean.true.ts
61+
^
62+
source.ts meta.function.ts meta.block.ts
63+
^
64+
source.ts meta.function.ts meta.block.ts keyword.operator.ternary.ts
65+
^
66+
source.ts meta.function.ts meta.block.ts
67+
^
68+
source.ts meta.function.ts meta.block.ts meta.arrow.ts variable.parameter.ts
69+
^
70+
source.ts meta.function.ts meta.block.ts meta.arrow.ts
71+
^^
72+
source.ts meta.function.ts meta.block.ts meta.arrow.ts storage.type.function.arrow.ts
73+
^
74+
source.ts meta.function.ts meta.block.ts meta.arrow.ts
75+
^
76+
source.ts meta.function.ts meta.block.ts meta.function-call.ts entity.name.function.ts
77+
^
78+
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
79+
^
80+
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
81+
^
82+
source.ts meta.function.ts meta.block.ts
83+
^
84+
source.ts meta.function.ts meta.block.ts keyword.operator.ternary.ts
85+
^
86+
source.ts meta.function.ts meta.block.ts
87+
^
88+
source.ts meta.function.ts meta.block.ts meta.arrow.ts variable.parameter.ts
89+
^
90+
source.ts meta.function.ts meta.block.ts meta.arrow.ts
91+
^^
92+
source.ts meta.function.ts meta.block.ts meta.arrow.ts storage.type.function.arrow.ts
93+
^
94+
source.ts meta.function.ts meta.block.ts meta.arrow.ts
95+
^
96+
source.ts meta.function.ts meta.block.ts constant.numeric.decimal.ts
97+
^
98+
source.ts meta.function.ts meta.block.ts punctuation.terminator.statement.ts
99+
^^
100+
source.ts meta.function.ts meta.block.ts
101+
>}
102+
^
103+
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
104+
^^
105+
source.ts
106+
>const x = 0; // no highlight in rest of file
107+
^^^^^
108+
source.ts meta.var.expr.ts storage.type.ts
109+
^
110+
source.ts meta.var.expr.ts
111+
^
112+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
113+
^
114+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
115+
^
116+
source.ts meta.var.expr.ts keyword.operator.assignment.ts
117+
^
118+
source.ts meta.var.expr.ts
119+
^
120+
source.ts meta.var.expr.ts constant.numeric.decimal.ts
121+
^
122+
source.ts punctuation.terminator.statement.ts
123+
^
124+
source.ts
125+
^^
126+
source.ts comment.line.double-slash.ts punctuation.definition.comment.ts
127+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128+
source.ts comment.line.double-slash.ts

tests/cases/Issue579.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function f(): (x: number) => any {
2+
return true ? x => f() : x => 0;
3+
}
4+
const x = 0; // no highlight in rest of file

0 commit comments

Comments
 (0)