Skip to content

Commit

Permalink
Fix the line ending consumption of let and var expression
Browse files Browse the repository at this point in the history
Fixes #654
  • Loading branch information
sheetalkamat committed Aug 21, 2018
1 parent 94b95df commit b049043
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 70 deletions.
26 changes: 18 additions & 8 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ variables:
propertyName: ({{anyNumber}}|({{identifier}})|{{nonIdentifierPropertyName}})
constantVar: ({{constantIdentifier}})(?![_$[:alnum:]])
endOfStatement: ';|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b'
varExprStart: '{{startOfDeclaration}}\b(var|let){{endOfIdentifier}}'
constExprStart: '{{startOfDeclaration}}\b(const(?!\s+enum\b)){{endOfIdentifier}}'
nonPropertyLookBehind: '[^\._$[:alnum:]]'
lookBehindReturn: '^return|{{nonPropertyLookBehind}}return'
lookBehindThrow: '^throw|{{nonPropertyLookBehind}}throw'
Expand Down Expand Up @@ -245,13 +247,15 @@ repository:
patterns:
# let/var
- name: meta.var.expr.ts
begin: '{{startOfDeclaration}}\b(var|let){{endOfIdentifier}}'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: storage.type.ts }
end: ((?=;|}|(\s+(of|in)\s+)|^\s*$|{{endOfStatement}})|((?<=\S)(?<!{{lookBehindLet}}|{{lookBehindVar}})(?=\s*$)))
begin: (?={{varExprStart}})
end: (?!{{varExprStart}})((?=;|}|(\s+(of|in)\s+)|^\s*$|{{endOfStatement}})|((?<!{{lookBehindLet}}|{{lookBehindVar}})(?=\s*$)))
patterns:
- begin: '{{varExprStart}}\s*'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: storage.type.ts }
end: (?=\S)
- include: '#destructuring-variable'
- include: '#var-single-variable'
- include: '#variable-initializer'
Expand All @@ -269,13 +273,19 @@ repository:
- include: '#punctuation-comma'
# const
- name: meta.var.expr.ts
begin: '{{startOfDeclaration}}\b(const(?!\s+enum\b)){{endOfIdentifier}}'
begin: (?={{constExprStart}})
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: storage.type.ts }
end: ((?=;|}|(\s+(of|in)\s+)|^\s*$|{{endOfStatement}})|((?<=\S)(?<!{{lookBehindConst}})(?=\s*$)))
end: (?!{{constExprStart}})((?=;|}|(\s+(of|in)\s+)|^\s*$|{{endOfStatement}})|((?<!{{lookBehindConst}})(?=\s*$)))
patterns:
- begin: '{{constExprStart}}\s*'
beginCaptures:
'1': { name: keyword.control.export.ts }
'2': { name: storage.modifier.ts }
'3': { name: storage.type.ts }
end: (?=\S)
- include: '#destructuring-const'
- include: '#var-single-const'
- include: '#variable-initializer'
Expand Down
74 changes: 52 additions & 22 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,35 @@
<key>name</key>
<string>meta.var.expr.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.ts</string>
</dict>
</dict>
<string>(?=(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))</string>
<key>end</key>
<string>((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;=\S)(?&lt;!^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
<string>(?!(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;!^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=\S)</string>
</dict>
<dict>
<key>include</key>
<string>#destructuring-variable</string>
Expand Down Expand Up @@ -497,7 +503,7 @@
<key>name</key>
<string>meta.var.expr.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<string>(?=(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand All @@ -517,9 +523,33 @@
</dict>
</dict>
<key>end</key>
<string>((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;=\S)(?&lt;!^const|[^\._$[:alnum:]]const)(?=\s*$)))</string>
<string>(?!(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;!^const|[^\._$[:alnum:]]const)(?=\s*$)))</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.ts</string>
</dict>
</dict>
<key>end</key>
<string>(?=\S)</string>
</dict>
<dict>
<key>include</key>
<string>#destructuring-const</string>
Expand Down
74 changes: 52 additions & 22 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -415,29 +415,35 @@
<key>name</key>
<string>meta.var.expr.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.tsx</string>
</dict>
</dict>
<string>(?=(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))</string>
<key>end</key>
<string>((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;=\S)(?&lt;!^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
<string>(?!(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;!^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=\S)</string>
</dict>
<dict>
<key>include</key>
<string>#destructuring-variable</string>
Expand Down Expand Up @@ -501,7 +507,7 @@
<key>name</key>
<string>meta.var.expr.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))</string>
<string>(?=(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand All @@ -521,9 +527,33 @@
</dict>
</dict>
<key>end</key>
<string>((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;=\S)(?&lt;!^const|[^\._$[:alnum:]]const)(?=\s*$)))</string>
<string>(?!(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|(\s+(of|in)\s+)|^\s*$|;|^\s*abstract\b|^\s*async\b|^\s*class\b|^\s*const\b|^\s*declare\b|^\s*enum\b|^\s*export\b|^\s*function\b|^\s*import\b|^\s*interface\b|^\s*let\b|^\s*module\b|^\s*namespace\b|^\s*return\b|^\s*type\b|^\s*var\b)|((?&lt;!^const|[^\._$[:alnum:]]const)(?=\s*$)))</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.export.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>storage.modifier.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>storage.type.tsx</string>
</dict>
</dict>
<key>end</key>
<string>(?=\S)</string>
</dict>
<dict>
<key>include</key>
<string>#destructuring-const</string>
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/Issue203.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts punctuation.definition.binding-pattern.array.ts
^
Expand Down Expand Up @@ -73,7 +73,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts punctuation.definition.binding-pattern.array.ts
^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue219.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Grammar: TypeScript.tmLanguage
^^^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts
^^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue232.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts punctuation.definition.binding-pattern.array.ts
^
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue307.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Grammar: TypeScript.tmLanguage
^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts
> a
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/Issue445.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Grammar: TypeScript.tmLanguage
^^^^^
source.ts meta.function.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.function.ts meta.block.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts
source.ts meta.function.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.function.ts meta.block.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts
^
Expand Down
46 changes: 46 additions & 0 deletions tests/baselines/Issue654.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
original file
-----------------------------------
let app = 1
{
1 + 1
}
-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>let app = 1
^^^
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.readwrite.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 constant.numeric.decimal.ts
^
source.ts meta.var.expr.ts
>{
^
source.ts meta.block.ts punctuation.definition.block.ts
> 1 + 1
^
source.ts meta.block.ts
^
source.ts meta.block.ts constant.numeric.decimal.ts
^
source.ts meta.block.ts
^
source.ts meta.block.ts keyword.operator.arithmetic.ts
^
source.ts meta.block.ts
^
source.ts meta.block.ts constant.numeric.decimal.ts
>}
^
source.ts meta.block.ts punctuation.definition.block.ts
4 changes: 2 additions & 2 deletions tests/baselines/destructuringWithDefaults.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts
> check: isReportMode = false,
Expand Down Expand Up @@ -273,7 +273,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.array-binding-pattern-variable.ts punctuation.definition.binding-pattern.array.ts
> check2 = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Grammar: TypeScript.tmLanguage
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts
source.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts
^
Expand Down
Loading

0 comments on commit b049043

Please sign in to comment.