Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support TSModuleDeclaration #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-nails-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'esrap': patch
---

fix: support `TSModuleDeclaration`
16 changes: 16 additions & 0 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,22 @@ const handlers = {
state.commands.push(dedent, newline, '}', newline);
},

TSModuleBlock(node, state) {
state.commands.push(' {', indent, newline);
sequence(node.body, state, false, handle);
state.commands.push(dedent, newline, '}');
},

TSModuleDeclaration(node, state) {
if (node.declare) state.commands.push('declare ');
else state.commands.push('namespace ');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is a correct assumption, but I did not find any other way to extract that namspace from the AST


handle(node.id, state);

if (!node.body) return;
handle(node.body, state);
},

TSNonNullExpression(node, state) {
handle(node.expression, state);
state.commands.push('!');
Expand Down
7 changes: 7 additions & 0 deletions test/samples/ts-module-declaration/expected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare global {
namespace App {
interface Error {}
}
}

export {};
11 changes: 11 additions & 0 deletions test/samples/ts-module-declaration/expected.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"names": [],
"sources": [
"input.js"
],
"sourcesContent": [
"declare global {\n\tnamespace App {\n\t\tinterface Error {}\n\t}\n}\n\nexport {};\n"
],
"mappings": "QAAQ,MAAM;WACH,GAAG;YACF,KAAK;;;;"
}
7 changes: 7 additions & 0 deletions test/samples/ts-module-declaration/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare global {
namespace App {
interface Error {}
}
}

export {};