handle expression after return keyword explicitly

Fixes #823
This commit is contained in:
Sheetal Nandi 2020-11-05 14:52:28 -08:00
Родитель 15b157d42e
Коммит 59b62cbc62
14 изменённых файлов: 124 добавлений и 21 удалений

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

@ -190,8 +190,12 @@ repository:
'2': { name: entity.name.label.ts }
- name: keyword.control.loop.ts
match: '{{startOfIdentifier}}(break|continue|do|goto|while){{endOfIdentifier}}'
- name: keyword.control.flow.ts
match: '{{startOfIdentifier}}(return){{endOfIdentifier}}'
- begin: '{{startOfIdentifier}}(return){{endOfIdentifier}}'
beginCaptures:
'0': { name: keyword.control.flow.ts }
end: (?=[;}]|$|{{endOfStatement}})
patterns:
- include: '#expression'
- name: keyword.control.switch.ts
match: '{{startOfIdentifier}}(case|default|switch){{endOfIdentifier}}'
- include: '#if-statement'

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

@ -184,10 +184,25 @@
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(break|continue|do|goto|while)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
<dict>
<key>name</key>
<string>keyword.control.flow.ts</string>
<key>match</key>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(return)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.flow.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=[;}]|$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#expression</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>

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

@ -184,10 +184,25 @@
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(break|continue|do|goto|while)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
</dict>
<dict>
<key>name</key>
<string>keyword.control.flow.tsx</string>
<key>match</key>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(return)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.flow.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=[;}]|$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#expression</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>

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

@ -123,7 +123,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^
@ -184,7 +184,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^
@ -1027,7 +1027,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
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 meta.objectliteral.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.objectliteral.ts punctuation.definition.block.ts
^
@ -1086,7 +1086,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
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 meta.objectliteral.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.objectliteral.ts punctuation.definition.block.ts
^

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

@ -139,7 +139,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.class.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.class.ts meta.block.ts meta.objectliteral.ts
source.ts meta.class.ts meta.block.ts
^
source.ts meta.class.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^
@ -202,7 +202,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.class.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.class.ts meta.block.ts meta.objectliteral.ts
source.ts meta.class.ts meta.block.ts
^
source.ts meta.class.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^

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

@ -87,7 +87,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
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 meta.objectliteral.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.objectliteral.ts punctuation.definition.block.ts
> [

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

@ -51,7 +51,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^

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

@ -50,7 +50,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^

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

@ -58,7 +58,7 @@ Grammar: TypeScript.tmLanguage
^
source.ts meta.function.ts meta.block.ts keyword.operator.ternary.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^

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

@ -0,0 +1,66 @@
original file
-----------------------------------
function test(type, obj) {
return type in obj && 'broken';
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>function test(type, obj) {
^^^^^^^^
source.ts meta.function.ts storage.type.function.ts
^
source.ts meta.function.ts
^^^^
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^
source.ts meta.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.separator.parameter.ts
^
source.ts meta.function.ts meta.parameters.ts
^^^
source.ts meta.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.function.ts
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
> return type in obj && 'broken';
^^
source.ts meta.function.ts meta.block.ts
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts
^^^^
source.ts meta.function.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.function.ts meta.block.ts
^^
source.ts meta.function.ts meta.block.ts keyword.operator.expression.in.ts
^
source.ts meta.function.ts meta.block.ts
^^^
source.ts meta.function.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.function.ts meta.block.ts
^^
source.ts meta.function.ts meta.block.ts keyword.operator.logical.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^^^^^^
source.ts meta.function.ts meta.block.ts string.quoted.single.ts
^
source.ts meta.function.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.function.ts meta.block.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts

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

@ -70,7 +70,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
> x: {

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

@ -443,7 +443,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^

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

@ -66,7 +66,7 @@ Grammar: TypeScript.tmLanguage
^^^^^^
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
> x: {

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

@ -0,0 +1,3 @@
function test(type, obj) {
return type in obj && 'broken';
}