Skip to content

Commit 1697562

Browse files
committed
fix: ensure scope is entered correctly
1 parent eb4ec56 commit 1697562

File tree

5 files changed

+167
-6
lines changed

5 files changed

+167
-6
lines changed

.changeset/early-ties-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/acorn-typescript': patch
3+
---
4+
5+
fix: ensure scope is entered correctly

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ export function tsPlugin(options?: {
976976

977977
tsParseModuleBlock(): Node {
978978
const node = this.startNode();
979-
super.enterScope(TS_SCOPE_OTHER);
979+
this.enterScope(TS_SCOPE_OTHER);
980980
this.expect(tt.braceL);
981981
// Inside of a module block is considered "top-level", meaning it can have imports and exports.
982982
node.body = [];
@@ -1000,7 +1000,7 @@ export function tsPlugin(options?: {
10001000
this.unexpected();
10011001
}
10021002
if (this.match(tt.braceL)) {
1003-
super.enterScope(TS_SCOPE_TS_MODULE);
1003+
this.enterScope(TS_SCOPE_TS_MODULE);
10041004

10051005
node.body = this.tsParseModuleBlock();
10061006

@@ -2509,7 +2509,7 @@ export function tsPlugin(options?: {
25092509
// `global { }` (with no `declare`) may appear inside an ambient module declaration.
25102510
// Would like to use tsParseAmbientExternalModuleDeclaration here, but already ran past "global".
25112511
if (this.match(tt.braceL)) {
2512-
super.enterScope(TS_SCOPE_TS_MODULE);
2512+
this.enterScope(TS_SCOPE_TS_MODULE);
25132513
const mod = node;
25142514
mod.global = true;
25152515
mod.id = expr;
@@ -2599,7 +2599,7 @@ export function tsPlugin(options?: {
25992599
this.tsParseModuleOrNamespaceDeclaration(inner, true);
26002600
node.body = inner;
26012601
} else {
2602-
super.enterScope(TS_SCOPE_TS_MODULE);
2602+
this.enterScope(TS_SCOPE_TS_MODULE);
26032603

26042604
node.body = this.tsParseModuleBlock();
26052605

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"type": "Program",
3+
"start": 0,
4+
"end": 57,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 3,
12+
"column": 1
13+
}
14+
},
15+
"body": [
16+
{
17+
"type": "TSModuleDeclaration",
18+
"start": 0,
19+
"end": 57,
20+
"loc": {
21+
"start": {
22+
"line": 1,
23+
"column": 0
24+
},
25+
"end": {
26+
"line": 3,
27+
"column": 1
28+
}
29+
},
30+
"id": {
31+
"type": "Identifier",
32+
"start": 10,
33+
"end": 23,
34+
"loc": {
35+
"start": {
36+
"line": 1,
37+
"column": 10
38+
},
39+
"end": {
40+
"line": 1,
41+
"column": 23
42+
}
43+
},
44+
"name": "SomeNamespace"
45+
},
46+
"body": {
47+
"type": "TSModuleBlock",
48+
"start": 24,
49+
"end": 57,
50+
"loc": {
51+
"start": {
52+
"line": 1,
53+
"column": 24
54+
},
55+
"end": {
56+
"line": 3,
57+
"column": 1
58+
}
59+
},
60+
"body": [
61+
{
62+
"type": "ExportNamedDeclaration",
63+
"start": 31,
64+
"end": 54,
65+
"loc": {
66+
"start": {
67+
"line": 2,
68+
"column": 4
69+
},
70+
"end": {
71+
"line": 2,
72+
"column": 27
73+
}
74+
},
75+
"exportKind": "type",
76+
"declaration": {
77+
"type": "TSTypeAliasDeclaration",
78+
"start": 38,
79+
"end": 54,
80+
"loc": {
81+
"start": {
82+
"line": 2,
83+
"column": 11
84+
},
85+
"end": {
86+
"line": 2,
87+
"column": 27
88+
}
89+
},
90+
"id": {
91+
"type": "Identifier",
92+
"start": 43,
93+
"end": 46,
94+
"loc": {
95+
"start": {
96+
"line": 2,
97+
"column": 16
98+
},
99+
"end": {
100+
"line": 2,
101+
"column": 19
102+
}
103+
},
104+
"name": "Foo"
105+
},
106+
"typeAnnotation": {
107+
"type": "TSLiteralType",
108+
"start": 49,
109+
"end": 53,
110+
"loc": {
111+
"start": {
112+
"line": 2,
113+
"column": 22
114+
},
115+
"end": {
116+
"line": 2,
117+
"column": 26
118+
}
119+
},
120+
"literal": {
121+
"type": "Literal",
122+
"start": 49,
123+
"end": 53,
124+
"loc": {
125+
"start": {
126+
"line": 2,
127+
"column": 22
128+
},
129+
"end": {
130+
"line": 2,
131+
"column": 26
132+
}
133+
},
134+
"value": true,
135+
"raw": "true"
136+
}
137+
}
138+
},
139+
"specifiers": [],
140+
"source": null
141+
}
142+
]
143+
}
144+
}
145+
],
146+
"sourceType": "module"
147+
}

test/namespace_export_type/input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace SomeNamespace {
2+
export type Foo = true;
3+
}

test/run.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ describe('tests', () => {
1919
const expected_path = path.join(folder_path, 'expected.json');
2020
const error_path = path.join(folder_path, 'error.txt');
2121

22+
const _it = dirent.name.endsWith('.skip')
23+
? it.skip
24+
: dirent.name.endsWith('.only')
25+
? it.only
26+
: it;
27+
2228
if (fs.existsSync(expected_path)) {
23-
it(dirent.name, () => {
29+
_it(dirent.name, () => {
2430
const input_code = fs.readFileSync(input_path, 'utf-8');
2531
const expected_result = fs.readFileSync(expected_path, 'utf-8');
2632

@@ -45,7 +51,7 @@ describe('tests', () => {
4551
}
4652
});
4753
} else if (fs.existsSync(error_path)) {
48-
it(dirent.name, () => {
54+
_it(dirent.name, () => {
4955
const input_code = fs.readFileSync(input_path, 'utf-8');
5056
const error_message = fs.readFileSync(error_path, 'utf-8').trim();
5157

0 commit comments

Comments
 (0)