Fix the cast expression detection logic to include few more expression locations that would be operator location

Fixes #450
This commit is contained in:
Sheetal Nandi 2017-05-08 10:04:22 -07:00
Родитель d61f62a8f2
Коммит ac0314e5fa
4 изменённых файлов: 62 добавлений и 2 удалений

Просмотреть файл

@ -1485,7 +1485,7 @@ repository:
# If '<' is preceeded by 'return', 'throw', 'yield', or 'await', it's most likely a type assertion
# If '=', '(', ',', ':', or '>' are followed by a '<', it is also likely a type assertion as otherwise it would be a syntax error
# '<=' and '<<=' are cannot be type assertions, as they are assignment operators.
begin: (?:(?<=return|throw|yield|await|default|[=(,:>*]))\s*(<)(?!<?\=)
begin: (?:(?<=return|throw|yield|await|default|[=(,:>*?]))\s*(<)(?!<?\=)
beginCaptures:
'1': { name: meta.brace.angle.ts }
end: \>

Просмотреть файл

@ -4058,7 +4058,7 @@
<key>name</key>
<string>cast.expr.ts</string>
<key>begin</key>
<string>(?:(?&lt;=return|throw|yield|await|default|[=(,:&gt;*]))\s*(&lt;)(?!&lt;?\=)</string>
<string>(?:(?&lt;=return|throw|yield|await|default|[=(,:&gt;*?]))\s*(&lt;)(?!&lt;?\=)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>

Просмотреть файл

@ -0,0 +1,58 @@
original file
-----------------------------------
// @onlyOwnGrammar - As this has type assertion
let a = true ? <number>1 : <number>2;
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>// @onlyOwnGrammar - As this has type assertion
^^
source.ts comment.line.double-slash.ts punctuation.definition.comment.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts comment.line.double-slash.ts
>let a = true ? <number>1 : <number>2;
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts constant.language.boolean.true.ts
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.ternary.ts
^
source.ts meta.var.expr.ts cast.expr.ts
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^^^^^^
source.ts meta.var.expr.ts cast.expr.ts support.type.primitive.ts
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^
source.ts meta.var.expr.ts constant.numeric.decimal.ts
^
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.ternary.ts
^
source.ts meta.var.expr.ts cast.expr.ts
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^^^^^^
source.ts meta.var.expr.ts cast.expr.ts support.type.primitive.ts
^
source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts
^
source.ts meta.var.expr.ts constant.numeric.decimal.ts
^
source.ts punctuation.terminator.statement.ts

2
tests/cases/Issue450.ts Normal file
Просмотреть файл

@ -0,0 +1,2 @@
// @onlyOwnGrammar - As this has type assertion
let a = true ? <number>1 : <number>2;