Skip to content

Commit b683171

Browse files
authored
fix: support TSModuleDeclaration (#44)
1 parent 2ab03fc commit b683171

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

.changeset/fresh-nails-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'esrap': patch
3+
---
4+
5+
fix: support `TSModuleDeclaration`

src/handlers.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,22 @@ const handlers = {
15061506
state.commands.push(dedent, newline, '}', newline);
15071507
},
15081508

1509+
TSModuleBlock(node, state) {
1510+
state.commands.push(' {', indent, newline);
1511+
sequence(node.body, state, false, handle);
1512+
state.commands.push(dedent, newline, '}');
1513+
},
1514+
1515+
TSModuleDeclaration(node, state) {
1516+
if (node.declare) state.commands.push('declare ');
1517+
else state.commands.push('namespace ');
1518+
1519+
handle(node.id, state);
1520+
1521+
if (!node.body) return;
1522+
handle(node.body, state);
1523+
},
1524+
15091525
TSNonNullExpression(node, state) {
15101526
handle(node.expression, state);
15111527
state.commands.push('!');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare global {
2+
namespace App {
3+
interface Error {}
4+
}
5+
}
6+
7+
export {};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 3,
3+
"names": [],
4+
"sources": [
5+
"input.js"
6+
],
7+
"sourcesContent": [
8+
"declare global {\n\tnamespace App {\n\t\tinterface Error {}\n\t}\n}\n\nexport {};\n"
9+
],
10+
"mappings": "QAAQ,MAAM;WACH,GAAG;YACF,KAAK;;;;"
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare global {
2+
namespace App {
3+
interface Error {}
4+
}
5+
}
6+
7+
export {};

0 commit comments

Comments
 (0)