Skip to content

Commit

Permalink
fix: support TSImportType
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel3108 committed Feb 11, 2025
1 parent af10b08 commit e1ccd75
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-keys-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'esrap': patch
---

fix: support `TSImportType`
10 changes: 10 additions & 0 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,16 @@ function handle_type_annotation(node, state) {
handle_type_annotation(node.indexType, state);
state.commands.push(']');
break;
case 'TSImportType':
state.commands.push('import(');
handle(node.argument, state);
state.commands.push(')');

if (node.qualifier) {
state.commands.push('.');
handle(node.qualifier, state);
}
break;
default:
throw new Error(`Not implemented type annotation ${node.type}`);
}
Expand Down
2 changes: 2 additions & 0 deletions test/samples/ts-import-type/expected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const foo: import('foo/bar') = 123;
const bar: import('foo/bar').baz = 234;
11 changes: 11 additions & 0 deletions test/samples/ts-import-type/expected.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 3,
"names": [],
"sources": [
"input.js"
],
"sourcesContent": [
"const foo: import('foo/bar') = 123;\nconst bar: import('foo/bar').baz = 234;\n"
],
"mappings": "MAAM,GAAsB,SAAV,SAAS,IAAI,GAAG;MAC5B,GAA0B,SAAd,SAAS,EAAE,GAAG,GAAG,GAAG"
}
2 changes: 2 additions & 0 deletions test/samples/ts-import-type/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const foo: import('foo/bar') = 123;
const bar: import('foo/bar').baz = 234;

0 comments on commit e1ccd75

Please sign in to comment.