Handle declaration block with ternary operator and switch case statement better

Fixes #595
This commit is contained in:
Sheetal Nandi 2018-04-09 12:36:23 -07:00
Родитель 5c237f767c
Коммит de11c82f7c
5 изменённых файлов: 203 добавлений и 24 удалений

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

@ -982,11 +982,23 @@ repository:
begin: '{{startOfIdentifier}}(case|default(?=:)){{endOfIdentifier}}'
beginCaptures:
'1': { name: keyword.control.switch.ts }
end: ':'
endCaptures:
'0': { name: punctuation.definition.section.case-statement.ts }
end: (?=:)
patterns:
- include: '#expression'
# case block
- begin: (:)\s*(\{)
beginCaptures:
'1': { name: case-clause.expr.ts punctuation.definition.section.case-statement.ts }
'2': { name: meta.block.ts punctuation.definition.block.ts }
end: \}
endCaptures:
'0': { name: meta.block.ts punctuation.definition.block.ts }
contentName: meta.block.ts
patterns:
- include: '#statements'
- match: (:)
captures:
'0': { name: case-clause.expr.ts punctuation.definition.section.case-statement.ts }
- include: '#statements'
for-loop:
@ -1024,7 +1036,7 @@ repository:
#object literals
after-operator-block-as-object-literal:
name: meta.objectliteral.ts
begin: (?<!\+\+|--)(?<=[=(,\[?+!]|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindYield}}|{{lookBehindThrow}}|{{lookBehindIn}}|{{lookBehindOf}}|{{lookBehindTypeof}}|&&|\|\||\*)\s*(\{)
begin: (?<!\+\+|--)(?<=[:=(,\[?+!]|{{lookBehindAwait}}|{{lookBehindReturn}}|{{lookBehindYield}}|{{lookBehindThrow}}|{{lookBehindIn}}|{{lookBehindOf}}|{{lookBehindTypeof}}|&&|\|\||\*)\s*(\{)
beginCaptures:
'1': { name: punctuation.definition.block.ts }
end: \}

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

@ -3061,15 +3061,7 @@
</dict>
</dict>
<key>end</key>
<string>:</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.section.case-statement.ts</string>
</dict>
</dict>
<string>(?=:)</string>
<key>patterns</key>
<array>
<dict>
@ -3078,6 +3070,54 @@
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(:)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>case-clause.expr.ts punctuation.definition.section.case-statement.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>meta.block.ts punctuation.definition.block.ts</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>meta.block.ts punctuation.definition.block.ts</string>
</dict>
</dict>
<key>contentName</key>
<string>meta.block.ts</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#statements</string>
</dict>
</array>
</dict>
<dict>
<key>match</key>
<string>(:)</string>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>case-clause.expr.ts punctuation.definition.section.case-statement.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>include</key>
<string>#statements</string>
@ -3188,7 +3228,7 @@
<key>name</key>
<string>meta.objectliteral.ts</string>
<key>begin</key>
<string>(?&lt;!\+\+|--)(?&lt;=[=(,\[?+!]|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^yield|[^\._$[:alnum:]]yield|^throw|[^\._$[:alnum:]]throw|^in|[^\._$[:alnum:]]in|^of|[^\._$[:alnum:]]of|^typeof|[^\._$[:alnum:]]typeof|&amp;&amp;|\|\||\*)\s*(\{)</string>
<string>(?&lt;!\+\+|--)(?&lt;=[:=(,\[?+!]|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^yield|[^\._$[:alnum:]]yield|^throw|[^\._$[:alnum:]]throw|^in|[^\._$[:alnum:]]in|^of|[^\._$[:alnum:]]of|^typeof|[^\._$[:alnum:]]typeof|&amp;&amp;|\|\||\*)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>

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

@ -3065,15 +3065,7 @@
</dict>
</dict>
<key>end</key>
<string>:</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.section.case-statement.tsx</string>
</dict>
</dict>
<string>(?=:)</string>
<key>patterns</key>
<array>
<dict>
@ -3082,6 +3074,54 @@
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(:)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>case-clause.expr.tsx punctuation.definition.section.case-statement.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>meta.block.tsx punctuation.definition.block.tsx</string>
</dict>
</dict>
<key>end</key>
<string>\}</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>meta.block.tsx punctuation.definition.block.tsx</string>
</dict>
</dict>
<key>contentName</key>
<string>meta.block.tsx</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#statements</string>
</dict>
</array>
</dict>
<dict>
<key>match</key>
<string>(:)</string>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>case-clause.expr.tsx punctuation.definition.section.case-statement.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>include</key>
<string>#statements</string>
@ -3192,7 +3232,7 @@
<key>name</key>
<string>meta.objectliteral.tsx</string>
<key>begin</key>
<string>(?&lt;!\+\+|--)(?&lt;=[=(,\[?+!]|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^yield|[^\._$[:alnum:]]yield|^throw|[^\._$[:alnum:]]throw|^in|[^\._$[:alnum:]]in|^of|[^\._$[:alnum:]]of|^typeof|[^\._$[:alnum:]]typeof|&amp;&amp;|\|\||\*)\s*(\{)</string>
<string>(?&lt;!\+\+|--)(?&lt;=[:=(,\[?+!]|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^yield|[^\._$[:alnum:]]yield|^throw|[^\._$[:alnum:]]throw|^in|[^\._$[:alnum:]]in|^of|[^\._$[:alnum:]]of|^typeof|[^\._$[:alnum:]]typeof|&amp;&amp;|\|\||\*)\s*(\{)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>

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

@ -0,0 +1,84 @@
original file
-----------------------------------
function f() {
return foo ? { a: true } : { b: false }
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>function f() {
^^^^^^^^
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 punctuation.definition.parameters.end.ts
^
source.ts meta.function.ts
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
^^
source.ts meta.function.ts meta.block.ts
> return foo ? { a: true } : { b: false }
^^^^
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.ternary.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts meta.object-literal.key.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts meta.object-literal.key.ts punctuation.separator.key-value.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts
^^^^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts constant.language.boolean.true.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^
source.ts meta.function.ts meta.block.ts
^
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 meta.objectliteral.ts punctuation.definition.block.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts meta.object-literal.key.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts meta.object-literal.key.ts punctuation.separator.key-value.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts
^^^^^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts constant.language.boolean.false.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts meta.object.member.ts
^
source.ts meta.function.ts meta.block.ts meta.objectliteral.ts punctuation.definition.block.ts
^^
source.ts meta.function.ts meta.block.ts
>}
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts

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

@ -0,0 +1,3 @@
function f() {
return foo ? { a: true } : { b: false }
}