Skip to content

Commit 47f2500

Browse files
committed
Handle new line after var/let/const
Fixes #638
1 parent 2742543 commit 47f2500

9 files changed

+385
-329
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ variables:
3333
# any use of property name needs to ignore line breaks in regular expression because of decimal number regex (maintained for readability)
3434
propertyName: ({{anyNumber}}|({{identifier}})|{{nonIdentifierPropertyName}})
3535
constantVar: ({{constantIdentifier}})(?![_$[:alnum:]])
36-
endOfStatement: ';|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b'
36+
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'
3737
nonPropertyLookBehind: '[^\._$[:alnum:]]'
3838
lookBehindReturn: '^return|{{nonPropertyLookBehind}}return'
3939
lookBehindThrow: '^throw|{{nonPropertyLookBehind}}throw'
4040
lookBehindYield: '^yield|{{nonPropertyLookBehind}}yield'
4141
lookBehindAwait: '^await|{{nonPropertyLookBehind}}await'
4242
lookBehindDefault: '^default|{{nonPropertyLookBehind}}default'
43+
lookBehindConst: '^const|{{nonPropertyLookBehind}}const'
44+
lookBehindLet: '^let|{{nonPropertyLookBehind}}let'
45+
lookBehindVar: '^var|{{nonPropertyLookBehind}}var'
4346
lookBehindIn: '^in|{{nonPropertyLookBehind}}in'
4447
lookBehindOf: '^of|{{nonPropertyLookBehind}}of'
4548
lookBehindTypeof: '^typeof|{{nonPropertyLookBehind}}typeof'
@@ -243,7 +246,7 @@ repository:
243246
beginCaptures:
244247
'1': { name: keyword.control.export.ts }
245248
'2': { name: storage.type.ts }
246-
end: (?=$|^|;|}|(\s+(of|in)\s+))
249+
end: ((?=;|}|(\s+(of|in)\s+)|^\s*$|{{endOfStatement}})|((?<=\S)(?<!{{lookBehindConst}}|{{lookBehindLet}}|{{lookBehindVar}})(?=\s*$)))
247250
patterns:
248251
- include: '#destructuring-variable'
249252
- include: '#var-single-variable'

TypeScript.tmLanguage

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
</dict>
424424
</dict>
425425
<key>end</key>
426-
<string>(?=$|^|;|}|(\s+(of|in)\s+))</string>
426+
<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|^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
427427
<key>patterns</key>
428428
<array>
429429
<dict>
@@ -2729,7 +2729,7 @@
27292729
</dict>
27302730
</dict>
27312731
<key>end</key>
2732-
<string>(?&lt;=\})|(?=;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2732+
<string>(?&lt;=\})|(?=;|^\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)</string>
27332733
<key>patterns</key>
27342734
<array>
27352735
<dict>
@@ -2781,7 +2781,7 @@
27812781
</dict>
27822782
</dict>
27832783
<key>end</key>
2784-
<string>(?=\}|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2784+
<string>(?=\}|;|^\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)</string>
27852785
<key>patterns</key>
27862786
<array>
27872787
<dict>
@@ -2804,7 +2804,7 @@
28042804
</dict>
28052805
</dict>
28062806
<key>end</key>
2807-
<string>(?=\}|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2807+
<string>(?=\}|;|^\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)</string>
28082808
<key>patterns</key>
28092809
<array>
28102810
<dict>
@@ -3060,7 +3060,7 @@
30603060
</dict>
30613061
</dict>
30623062
<key>end</key>
3063-
<string>(?=$|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
3063+
<string>(?=$|;|^\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)</string>
30643064
<key>patterns</key>
30653065
<array>
30663066
<dict>
@@ -3083,7 +3083,7 @@
30833083
</dict>
30843084
</dict>
30853085
<key>end</key>
3086-
<string>(?=$|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
3086+
<string>(?=$|;|^\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)</string>
30873087
<key>patterns</key>
30883088
<array>
30893089
<dict>

TypeScriptReact.tmLanguage

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427
</dict>
428428
</dict>
429429
<key>end</key>
430-
<string>(?=$|^|;|}|(\s+(of|in)\s+))</string>
430+
<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|^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))</string>
431431
<key>patterns</key>
432432
<array>
433433
<dict>
@@ -2733,7 +2733,7 @@
27332733
</dict>
27342734
</dict>
27352735
<key>end</key>
2736-
<string>(?&lt;=\})|(?=;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2736+
<string>(?&lt;=\})|(?=;|^\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)</string>
27372737
<key>patterns</key>
27382738
<array>
27392739
<dict>
@@ -2785,7 +2785,7 @@
27852785
</dict>
27862786
</dict>
27872787
<key>end</key>
2788-
<string>(?=\}|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2788+
<string>(?=\}|;|^\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)</string>
27892789
<key>patterns</key>
27902790
<array>
27912791
<dict>
@@ -2808,7 +2808,7 @@
28082808
</dict>
28092809
</dict>
28102810
<key>end</key>
2811-
<string>(?=\}|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
2811+
<string>(?=\}|;|^\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)</string>
28122812
<key>patterns</key>
28132813
<array>
28142814
<dict>
@@ -3064,7 +3064,7 @@
30643064
</dict>
30653065
</dict>
30663066
<key>end</key>
3067-
<string>(?=$|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
3067+
<string>(?=$|;|^\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)</string>
30683068
<key>patterns</key>
30693069
<array>
30703070
<dict>
@@ -3087,7 +3087,7 @@
30873087
</dict>
30883088
</dict>
30893089
<key>end</key>
3090-
<string>(?=$|;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\breturn\b|\btype\b|\bvar\b)</string>
3090+
<string>(?=$|;|^\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)</string>
30913091
<key>patterns</key>
30923092
<array>
30933093
<dict>

0 commit comments

Comments
 (0)