Skip to content

Commit ac0314e

Browse files
committed
Fix the cast expression detection logic to include few more expression locations that would be operator location
Fixes #450
1 parent d61f62a commit ac0314e

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ repository:
14851485
# If '<' is preceeded by 'return', 'throw', 'yield', or 'await', it's most likely a type assertion
14861486
# If '=', '(', ',', ':', or '>' are followed by a '<', it is also likely a type assertion as otherwise it would be a syntax error
14871487
# '<=' and '<<=' are cannot be type assertions, as they are assignment operators.
1488-
begin: (?:(?<=return|throw|yield|await|default|[=(,:>*]))\s*(<)(?!<?\=)
1488+
begin: (?:(?<=return|throw|yield|await|default|[=(,:>*?]))\s*(<)(?!<?\=)
14891489
beginCaptures:
14901490
'1': { name: meta.brace.angle.ts }
14911491
end: \>

TypeScript.tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@
40584058
<key>name</key>
40594059
<string>cast.expr.ts</string>
40604060
<key>begin</key>
4061-
<string>(?:(?&lt;=return|throw|yield|await|default|[=(,:&gt;*]))\s*(&lt;)(?!&lt;?\=)</string>
4061+
<string>(?:(?&lt;=return|throw|yield|await|default|[=(,:&gt;*?]))\s*(&lt;)(?!&lt;?\=)</string>
40624062
<key>beginCaptures</key>
40634063
<dict>
40644064
<key>1</key>

tests/baselines/Issue450.baseline.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
original file
2+
-----------------------------------
3+
// @onlyOwnGrammar - As this has type assertion
4+
let a = true ? <number>1 : <number>2;
5+
-----------------------------------
6+
7+
Grammar: TypeScript.tmLanguage
8+
-----------------------------------
9+
>// @onlyOwnGrammar - As this has type assertion
10+
^^
11+
source.ts comment.line.double-slash.ts punctuation.definition.comment.ts
12+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
source.ts comment.line.double-slash.ts
14+
>let a = true ? <number>1 : <number>2;
15+
^^^
16+
source.ts meta.var.expr.ts storage.type.ts
17+
^
18+
source.ts meta.var.expr.ts
19+
^
20+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
21+
^
22+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
23+
^
24+
source.ts meta.var.expr.ts keyword.operator.assignment.ts
25+
^
26+
source.ts meta.var.expr.ts
27+
^^^^
28+
source.ts meta.var.expr.ts constant.language.boolean.true.ts
29+
^
30+
source.ts meta.var.expr.ts
31+
^
32+
source.ts meta.var.expr.ts keyword.operator.ternary.ts
33+
^
34+
source.ts meta.var.expr.ts cast.expr.ts
35+
^
36+
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
37+
^^^^^^
38+
source.ts meta.var.expr.ts cast.expr.ts support.type.primitive.ts
39+
^
40+
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
41+
^
42+
source.ts meta.var.expr.ts constant.numeric.decimal.ts
43+
^
44+
source.ts meta.var.expr.ts
45+
^
46+
source.ts meta.var.expr.ts keyword.operator.ternary.ts
47+
^
48+
source.ts meta.var.expr.ts cast.expr.ts
49+
^
50+
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
51+
^^^^^^
52+
source.ts meta.var.expr.ts cast.expr.ts support.type.primitive.ts
53+
^
54+
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
55+
^
56+
source.ts meta.var.expr.ts constant.numeric.decimal.ts
57+
^
58+
source.ts punctuation.terminator.statement.ts

tests/cases/Issue450.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @onlyOwnGrammar - As this has type assertion
2+
let a = true ? <number>1 : <number>2;

0 commit comments

Comments
 (0)