Handle NonNullOperator with arrow function

Fixes #453
This commit is contained in:
Sheetal Nandi 2017-05-18 10:22:47 -07:00
Родитель 632a9db349
Коммит 54fc3e4ee4
5 изменённых файлов: 238 добавлений и 3 удалений

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

@ -1662,7 +1662,7 @@ repository:
(?:
(?<!\.|\$)(\basync)
)?
((?<![})\]])\s*
((?<![})!\]])\s*
(?=
# sure shot arrow functions even if => is on new line
(

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

@ -4562,7 +4562,7 @@
<key>begin</key>
<string>(?x) (?:
(?&lt;!\.|\$)(\basync)
)? ((?&lt;![})\]])\s*
)? ((?&lt;![})!\]])\s*
(?=
# sure shot arrow functions even if =&gt; is on new line
(

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

@ -4508,7 +4508,7 @@
<key>begin</key>
<string>(?x) (?:
(?&lt;!\.|\$)(\basync)
)? ((?&lt;![})\]])\s*
)? ((?&lt;![})!\]])\s*
(?=
# sure shot arrow functions even if =&gt; is on new line
(

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

@ -0,0 +1,224 @@
original file
-----------------------------------
type Resolve = () => number;
class Test {
first(values: Map<string, Resolve>): number {
return values.has('a') ? values.get('a')!() : 0;
}
second(): string {
return 'foo';
}
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>type Resolve = () => number;
^^^^
source.ts meta.type.declaration.ts storage.type.type.ts
^
source.ts meta.type.declaration.ts
^^^^^^^
source.ts meta.type.declaration.ts entity.name.type.alias.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.type.declaration.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.type.declaration.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.type.declaration.ts
^^
source.ts meta.type.declaration.ts meta.type.function.return.ts storage.type.function.arrow.ts
^
source.ts meta.type.declaration.ts meta.type.function.return.ts
^^^^^^
source.ts meta.type.declaration.ts meta.type.function.return.ts support.type.primitive.ts
^
source.ts punctuation.terminator.statement.ts
^^
source.ts
>
^^
source.ts
>class Test {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
> first(values: Map<string, Resolve>): number {
^^
source.ts meta.class.ts
^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.separator.comma.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts
^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
> return values.has('a') ? values.get('a')!() : 0;
^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts variable.other.object.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts support.function.dom.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.operator.ternary.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts variable.other.object.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.function-call.ts support.function.dom.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.operator.logical.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.operator.ternary.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.terminator.statement.ts
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
> }
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
>
^^
source.ts meta.class.ts
> second(): string {
^^
source.ts meta.class.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts support.type.primitive.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
> return 'foo';
^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.terminator.statement.ts
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
> }
^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.class.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts

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

@ -0,0 +1,11 @@
type Resolve = () => number;
class Test {
first(values: Map<string, Resolve>): number {
return values.has('a') ? values.get('a')!() : 0;
}
second(): string {
return 'foo';
}
}