Skip to content

Commit

Permalink
Match anything following ternary ':' as expression in class body as f…
Browse files Browse the repository at this point in the history
…allback

Fixes #721 and #724
  • Loading branch information
sheetalkamat committed Mar 20, 2019
1 parent 6985226 commit 31b00a7
Show file tree
Hide file tree
Showing 7 changed files with 487 additions and 0 deletions.
5 changes: 5 additions & 0 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,11 @@ repository:
patterns:
- include: '#comment'
- include: '#decorator'
# The : could most probably be end of ternary expression so to avoid matching expression following it as field declaration, explicitly match it as expression
- begin: (?<=:)\s*
end: (?=\s|[;),}\]:\-\+]|{{endOfStatement}})
patterns:
- include: '#expression'
- include: '#method-declaration'
- include: '#indexer-declaration'
- include: '#field-declaration'
Expand Down
13 changes: 13 additions & 0 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3053,6 +3053,19 @@
<key>include</key>
<string>#decorator</string>
</dict>
<dict>
<key>begin</key>
<string>(?&lt;=:)\s*</string>
<key>end</key>
<string>(?=\s|[;),}\]:\-\+]|;|(?:^\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>include</key>
<string>#method-declaration</string>
Expand Down
13 changes: 13 additions & 0 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,19 @@
<key>include</key>
<string>#decorator</string>
</dict>
<dict>
<key>begin</key>
<string>(?&lt;=:)\s*</string>
<key>end</key>
<string>(?=\s|[;),}\]:\-\+]|;|(?:^\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>include</key>
<string>#method-declaration</string>
Expand Down
92 changes: 92 additions & 0 deletions tests/baselines/Issue721.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
original file
-----------------------------------
class Foo {
prop = () =>
this.condition
? fn(this.value)
: fn(this.value)
}
-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>class Foo {
^^^^^
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
> prop = () =>
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts storage.type.function.arrow.ts
> this.condition
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts punctuation.accessor.ts
^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.other.property.ts
> ? fn(this.value)
^^^^^^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.ternary.ts
^
source.ts meta.class.ts
^^
source.ts meta.class.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.class.ts meta.brace.round.ts
^^^^
source.ts meta.class.ts variable.language.this.ts
^
source.ts meta.class.ts punctuation.accessor.ts
^^^^^
source.ts meta.class.ts support.variable.property.dom.ts
^
source.ts meta.class.ts meta.brace.round.ts
> : fn(this.value)
^^^^^^
source.ts meta.class.ts
^
source.ts meta.class.ts keyword.operator.ternary.ts
^
source.ts meta.class.ts
^^
source.ts meta.class.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.class.ts meta.brace.round.ts
^^^^
source.ts meta.class.ts variable.language.this.ts
^
source.ts meta.class.ts punctuation.accessor.ts
^^^^^
source.ts meta.class.ts support.variable.property.dom.ts
^
source.ts meta.class.ts meta.brace.round.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts
Loading

0 comments on commit 31b00a7

Please sign in to comment.