Skip to content

Commit f6c23ea

Browse files
committed
Handle multiline import declaration
Fixes #586
1 parent 8610134 commit f6c23ea

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ variables:
2626
lookBehindOf: '^of|{{nonPropertyLookBehind}}of'
2727
lookBehindTypeof: '^typeof|{{nonPropertyLookBehind}}typeof'
2828
lookBehindCase: '^case|{{nonPropertyLookBehind}}case'
29+
lookBehindImport: '^import|{{nonPropertyLookBehind}}import'
2930
matchingParenthesis: (\(([^\(\)]|(\([^\(\)]*\)))*\))
3031
matchingBraces: (\{([^\{\}]|(\{[^\{\}]*\}))*\})
3132
matchingBrackets: (\[([^\[\]]|(\[[^\[\]]*\]))*\])
@@ -865,6 +866,14 @@ repository:
865866
'2': { name: keyword.control.import.ts }
866867
end: (?=;|$|^)
867868
patterns:
869+
- include: '#comment'
870+
- include: '#string'
871+
- begin: (?<={{lookBehindImport}})(?!\s*["'])
872+
end: \bfrom\b
873+
endCaptures:
874+
'0': { name: keyword.control.from.ts }
875+
patterns:
876+
- include: '#import-export-declaration'
868877
- include: '#import-export-declaration'
869878

870879
export-declaration:

TypeScript.tmLanguage

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,35 @@
26932693
<string>(?=;|$|^)</string>
26942694
<key>patterns</key>
26952695
<array>
2696+
<dict>
2697+
<key>include</key>
2698+
<string>#comment</string>
2699+
</dict>
2700+
<dict>
2701+
<key>include</key>
2702+
<string>#string</string>
2703+
</dict>
2704+
<dict>
2705+
<key>begin</key>
2706+
<string>(?&lt;=^import|[^\._$[:alnum:]]import)(?!\s*["'])</string>
2707+
<key>end</key>
2708+
<string>\bfrom\b</string>
2709+
<key>endCaptures</key>
2710+
<dict>
2711+
<key>0</key>
2712+
<dict>
2713+
<key>name</key>
2714+
<string>keyword.control.from.ts</string>
2715+
</dict>
2716+
</dict>
2717+
<key>patterns</key>
2718+
<array>
2719+
<dict>
2720+
<key>include</key>
2721+
<string>#import-export-declaration</string>
2722+
</dict>
2723+
</array>
2724+
</dict>
26962725
<dict>
26972726
<key>include</key>
26982727
<string>#import-export-declaration</string>

TypeScriptReact.tmLanguage

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,35 @@
26972697
<string>(?=;|$|^)</string>
26982698
<key>patterns</key>
26992699
<array>
2700+
<dict>
2701+
<key>include</key>
2702+
<string>#comment</string>
2703+
</dict>
2704+
<dict>
2705+
<key>include</key>
2706+
<string>#string</string>
2707+
</dict>
2708+
<dict>
2709+
<key>begin</key>
2710+
<string>(?&lt;=^import|[^\._$[:alnum:]]import)(?!\s*["'])</string>
2711+
<key>end</key>
2712+
<string>\bfrom\b</string>
2713+
<key>endCaptures</key>
2714+
<dict>
2715+
<key>0</key>
2716+
<dict>
2717+
<key>name</key>
2718+
<string>keyword.control.from.tsx</string>
2719+
</dict>
2720+
</dict>
2721+
<key>patterns</key>
2722+
<array>
2723+
<dict>
2724+
<key>include</key>
2725+
<string>#import-export-declaration</string>
2726+
</dict>
2727+
</array>
2728+
</dict>
27002729
<dict>
27012730
<key>include</key>
27022731
<string>#import-export-declaration</string>

tests/baselines/Issue586.baseline.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
original file
2+
-----------------------------------
3+
import a
4+
from b;
5+
-----------------------------------
6+
7+
Grammar: TypeScript.tmLanguage
8+
-----------------------------------
9+
>import a
10+
^^^^^^
11+
source.ts meta.import.ts keyword.control.import.ts
12+
^
13+
source.ts meta.import.ts
14+
^
15+
source.ts meta.import.ts variable.other.readwrite.alias.ts
16+
^^
17+
source.ts meta.import.ts
18+
> from b;
19+
^^^^
20+
source.ts meta.import.ts
21+
^^^^
22+
source.ts meta.import.ts keyword.control.from.ts
23+
^
24+
source.ts meta.import.ts
25+
^
26+
source.ts meta.import.ts variable.other.readwrite.alias.ts
27+
^
28+
source.ts punctuation.terminator.statement.ts

tests/cases/Issue586.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import a
2+
from b;

0 commit comments

Comments
 (0)