Skip to content

Commit f3a2069

Browse files
committed
Correct the import/export matching to exclude \*|default from as clause.
Fixes #531
1 parent 4109ddc commit f3a2069

File tree

5 files changed

+65
-24
lines changed

5 files changed

+65
-24
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,17 +860,14 @@ repository:
860860
import-export-clause:
861861
patterns:
862862
- include: '#comment'
863-
- comment: (default|*|name) as alias
864-
match: |-
865-
(?x) (?: \b(default)\b | (\*) | ({{identifier}})) \s+
866-
(as) \s+ (?: (\b default \b | \*) | ({{identifier}}))
863+
#(default|*|name) as alias
864+
- match: (?<!\.|\$)(?:(\bdefault)|(\*)|(\b{{identifier}}))\s+(as)\s+(\b{{identifier}})
867865
captures:
868866
'1': { name: keyword.control.default.ts }
869867
'2': { name: constant.language.import-export-all.ts }
870868
'3': { name: variable.other.readwrite.ts }
871869
'4': { name: keyword.control.as.ts }
872-
'5': { name: invalid.illegal.ts }
873-
'6': { name: variable.other.readwrite.alias.ts }
870+
'5': { name: variable.other.readwrite.alias.ts }
874871
- include: '#punctuation-comma'
875872
- name: constant.language.import-export-all.ts
876873
match: \*

TypeScript.tmLanguage

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,11 +2703,8 @@
27032703
<string>#comment</string>
27042704
</dict>
27052705
<dict>
2706-
<key>comment</key>
2707-
<string>(default|*|name) as alias</string>
27082706
<key>match</key>
2709-
<string>(?x) (?: \b(default)\b | (\*) | ([_$[:alpha:]][_$[:alnum:]]*)) \s+
2710-
(as) \s+ (?: (\b default \b | \*) | ([_$[:alpha:]][_$[:alnum:]]*))</string>
2707+
<string>(?&lt;!\.|\$)(?:(\bdefault)|(\*)|(\b[_$[:alpha:]][_$[:alnum:]]*))\s+(as)\s+(\b[_$[:alpha:]][_$[:alnum:]]*)</string>
27112708
<key>captures</key>
27122709
<dict>
27132710
<key>1</key>
@@ -2731,11 +2728,6 @@
27312728
<string>keyword.control.as.ts</string>
27322729
</dict>
27332730
<key>5</key>
2734-
<dict>
2735-
<key>name</key>
2736-
<string>invalid.illegal.ts</string>
2737-
</dict>
2738-
<key>6</key>
27392731
<dict>
27402732
<key>name</key>
27412733
<string>variable.other.readwrite.alias.ts</string>

TypeScriptReact.tmLanguage

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,11 +2707,8 @@
27072707
<string>#comment</string>
27082708
</dict>
27092709
<dict>
2710-
<key>comment</key>
2711-
<string>(default|*|name) as alias</string>
27122710
<key>match</key>
2713-
<string>(?x) (?: \b(default)\b | (\*) | ([_$[:alpha:]][_$[:alnum:]]*)) \s+
2714-
(as) \s+ (?: (\b default \b | \*) | ([_$[:alpha:]][_$[:alnum:]]*))</string>
2711+
<string>(?&lt;!\.|\$)(?:(\bdefault)|(\*)|(\b[_$[:alpha:]][_$[:alnum:]]*))\s+(as)\s+(\b[_$[:alpha:]][_$[:alnum:]]*)</string>
27152712
<key>captures</key>
27162713
<dict>
27172714
<key>1</key>
@@ -2735,11 +2732,6 @@
27352732
<string>keyword.control.as.tsx</string>
27362733
</dict>
27372734
<key>5</key>
2738-
<dict>
2739-
<key>name</key>
2740-
<string>invalid.illegal.tsx</string>
2741-
</dict>
2742-
<key>6</key>
27432735
<dict>
27442736
<key>name</key>
27452737
<string>variable.other.readwrite.alias.tsx</string>

tests/baselines/Issue531.baseline.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
original file
2+
-----------------------------------
3+
class Test { }
4+
export {
5+
Test as default
6+
};
7+
-----------------------------------
8+
9+
Grammar: TypeScript.tmLanguage
10+
-----------------------------------
11+
>class Test { }
12+
^^^^^
13+
source.ts meta.class.ts storage.type.class.ts
14+
^
15+
source.ts meta.class.ts
16+
^^^^
17+
source.ts meta.class.ts entity.name.type.class.ts
18+
^
19+
source.ts meta.class.ts
20+
^
21+
source.ts meta.class.ts punctuation.definition.block.ts
22+
^
23+
source.ts meta.class.ts
24+
^
25+
source.ts meta.class.ts punctuation.definition.block.ts
26+
^^
27+
source.ts
28+
>export {
29+
^^^^^^
30+
source.ts meta.export.ts keyword.control.export.ts
31+
^
32+
source.ts meta.export.ts
33+
^
34+
source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
35+
^^
36+
source.ts meta.export.ts meta.block.ts
37+
> Test as default
38+
^
39+
source.ts meta.export.ts meta.block.ts
40+
^^^^
41+
source.ts meta.export.ts meta.block.ts variable.other.readwrite.ts
42+
^
43+
source.ts meta.export.ts meta.block.ts
44+
^^
45+
source.ts meta.export.ts meta.block.ts keyword.control.as.ts
46+
^
47+
source.ts meta.export.ts meta.block.ts
48+
^^^^^^^
49+
source.ts meta.export.ts meta.block.ts variable.other.readwrite.alias.ts
50+
^^
51+
source.ts meta.export.ts meta.block.ts
52+
>};
53+
^
54+
source.ts meta.export.ts meta.block.ts punctuation.definition.block.ts
55+
^
56+
source.ts punctuation.terminator.statement.ts

tests/cases/Issue531.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test { }
2+
export {
3+
Test as default
4+
};

0 commit comments

Comments
 (0)