Fix return type on new line of arrow function

Fixes #677
This commit is contained in:
Sheetal Nandi 2018-10-31 09:27:45 -07:00
Родитель 7a682de47e
Коммит 16c5fcb7aa
5 изменённых файлов: 306 добавлений и 3 удалений

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

@ -783,6 +783,7 @@ repository:
- include: '#function-parameters'
# return type of the arrow
- include: '#arrow-return-type'
- include: '#possibly-arrow-return-type'
# arrow operator
- name: meta.arrow.ts
begin: =>
@ -2033,7 +2034,7 @@ repository:
#This is the check if the exoression '): something =>'' can be matched as return type of arrow
possibly-arrow-return-type:
begin: (?<=\))\s*(:)(?={{returnTypeOfArrow}}\s*=>)
begin: (?<=\)|^)\s*(:)(?={{returnTypeOfArrow}}\s*=>)
beginCaptures:
'1': { name: meta.arrow.ts meta.return.type.arrow.ts keyword.operator.type.annotation.ts }
end: '{{arrowFunctionEnd}}'

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

@ -2510,6 +2510,10 @@
<key>include</key>
<string>#arrow-return-type</string>
</dict>
<dict>
<key>include</key>
<string>#possibly-arrow-return-type</string>
</dict>
</array>
</dict>
<dict>
@ -6037,7 +6041,7 @@
<key>possibly-arrow-return-type</key>
<dict>
<key>begin</key>
<string>(?&lt;=\))\s*(:)(?=\s*([^&lt;&gt;\(\)\{\}]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\)|\{[^\{\}]+\})+\s*=&gt;)</string>
<string>(?&lt;=\)|^)\s*(:)(?=\s*([^&lt;&gt;\(\)\{\}]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\)|\{[^\{\}]+\})+\s*=&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>

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

@ -2514,6 +2514,10 @@
<key>include</key>
<string>#arrow-return-type</string>
</dict>
<dict>
<key>include</key>
<string>#possibly-arrow-return-type</string>
</dict>
</array>
</dict>
<dict>
@ -5983,7 +5987,7 @@
<key>possibly-arrow-return-type</key>
<dict>
<key>begin</key>
<string>(?&lt;=\))\s*(:)(?=\s*([^&lt;&gt;\(\)\{\}]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\)|\{[^\{\}]+\})+\s*=&gt;)</string>
<string>(?&lt;=\)|^)\s*(:)(?=\s*([^&lt;&gt;\(\)\{\}]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\)|\{[^\{\}]+\})+\s*=&gt;)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>

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

@ -0,0 +1,280 @@
original file
-----------------------------------
const func2 = (url: string)
: Promise<any> => {
return new Promise((accept, reject) => {
const text = window.prompt();
accept(text);
});
}
const func2a = (url)
: Promise<any> => {
return new Promise((accept, reject) => {
const text = window.prompt();
accept(text);
});
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>const func2 = (url: string)
^^^^^
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.constant.ts entity.name.function.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 meta.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
>: Promise<any> => {
^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts keyword.operator.type.annotation.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts
^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts entity.name.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts support.type.primitive.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.arrow.ts meta.return.type.arrow.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts storage.type.function.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
> return new Promise((accept, reject) => {
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts keyword.operator.new.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts
^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts entity.name.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts storage.type.function.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
> const text = window.prompt();
^^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.constant.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts support.variable.dom.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts punctuation.accessor.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts support.function.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
> accept(text);
^^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
> });
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
>const func2a = (url)
^^^^^
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.constant.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 meta.brace.round.ts
^^^
source.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.brace.round.ts
>: Promise<any> => {
^
source.ts meta.arrow.ts meta.return.type.arrow.ts keyword.operator.type.annotation.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts
^^^^^^^
source.ts meta.arrow.ts meta.return.type.arrow.ts entity.name.type.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^
source.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts support.type.primitive.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.arrow.ts meta.return.type.arrow.ts
^^
source.ts meta.arrow.ts storage.type.function.arrow.ts
^
source.ts meta.arrow.ts
^
source.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
> return new Promise((accept, reject) => {
^^^^
source.ts meta.arrow.ts meta.block.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.arrow.ts meta.block.ts
^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts keyword.operator.new.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts
^^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts entity.name.type.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts
^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts storage.type.function.arrow.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
> const text = window.prompt();
^^^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.constant.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts support.variable.dom.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts punctuation.accessor.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.function-call.ts support.function.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.brace.round.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.brace.round.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
> accept(text);
^^^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^^^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
> });
^^^^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
^
source.ts meta.arrow.ts meta.block.ts new.expr.ts meta.brace.round.ts
^
source.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts

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

@ -0,0 +1,14 @@
const func2 = (url: string)
: Promise<any> => {
return new Promise((accept, reject) => {
const text = window.prompt();
accept(text);
});
}
const func2a = (url)
: Promise<any> => {
return new Promise((accept, reject) => {
const text = window.prompt();
accept(text);
});
}