Skip to content

Commit 9e5c4c2

Browse files
committed
Do not treat namespace as namespace declaration if it doesnt follow with the name
Fixes #380
1 parent 3ee427b commit 9e5c4c2

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ repository:
303303

304304
namespace-declaration:
305305
name: meta.namespace.declaration.ts
306-
begin: (?<!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+
306+
begin: (?<!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+(?=[_$[:alpha:]"'`])
307307
beginCaptures:
308308
'1': { name: keyword.control.export.ts }
309309
'2': { name: storage.type.namespace.ts }

TypeScript.tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@
924924
<key>name</key>
925925
<string>meta.namespace.declaration.ts</string>
926926
<key>begin</key>
927-
<string>(?&lt;!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+</string>
927+
<string>(?&lt;!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+(?=[_$[:alpha:]"'`])</string>
928928
<key>beginCaptures</key>
929929
<dict>
930930
<key>1</key>

TypeScriptReact.tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@
928928
<key>name</key>
929929
<string>meta.namespace.declaration.tsx</string>
930930
<key>begin</key>
931-
<string>(?&lt;!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+</string>
931+
<string>(?&lt;!\.|\$)(?:(\bexport)\s+)?\b(namespace|module)\s+(?=[_$[:alpha:]"'`])</string>
932932
<key>beginCaptures</key>
933933
<dict>
934934
<key>1</key>

tests/baselines/Issue380.baseline.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
original file
2+
-----------------------------------
3+
let namespace;
4+
namespace = `${"a"}`;
5+
6+
let x = 1
7+
-----------------------------------
8+
9+
Grammar: TypeScript.tmLanguage
10+
-----------------------------------
11+
>let namespace;
12+
^^^
13+
source.ts meta.var.expr.ts storage.type.ts
14+
^
15+
source.ts meta.var.expr.ts
16+
^^^^^^^^^
17+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
18+
^
19+
source.ts punctuation.terminator.statement.ts
20+
^^
21+
source.ts
22+
>namespace = `${"a"}`;
23+
^^^^^^^^^
24+
source.ts variable.other.readwrite.ts
25+
^
26+
source.ts
27+
^
28+
source.ts keyword.operator.assignment.ts
29+
^
30+
source.ts
31+
^
32+
source.ts string.template.ts punctuation.definition.string.template.begin.ts
33+
^^
34+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.begin.ts
35+
^
36+
source.ts string.template.ts meta.template.expression.ts string.quoted.double.ts punctuation.definition.string.begin.ts
37+
^
38+
source.ts string.template.ts meta.template.expression.ts string.quoted.double.ts
39+
^
40+
source.ts string.template.ts meta.template.expression.ts string.quoted.double.ts punctuation.definition.string.end.ts
41+
^
42+
source.ts string.template.ts meta.template.expression.ts punctuation.definition.template-expression.end.ts
43+
^
44+
source.ts string.template.ts punctuation.definition.string.template.end.ts
45+
^
46+
source.ts punctuation.terminator.statement.ts
47+
^^
48+
source.ts
49+
>
50+
^^
51+
source.ts
52+
>let x = 1
53+
^^^
54+
source.ts meta.var.expr.ts storage.type.ts
55+
^
56+
source.ts meta.var.expr.ts
57+
^
58+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
59+
^
60+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
61+
^
62+
source.ts meta.var.expr.ts keyword.operator.assignment.ts
63+
^
64+
source.ts meta.var.expr.ts
65+
^
66+
source.ts meta.var.expr.ts constant.numeric.decimal.ts

tests/cases/Issue380.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let namespace;
2+
namespace = `${"a"}`;
3+
4+
let x = 1

0 commit comments

Comments
 (0)