Skip to content

Commit 6a6eed9

Browse files
authored
fix: support TSImportType (#47)
1 parent af10b08 commit 6a6eed9

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

.changeset/fuzzy-keys-provide.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 `TSImportType`

src/handlers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,16 @@ function handle_type_annotation(node, state) {
605605
handle_type_annotation(node.indexType, state);
606606
state.commands.push(']');
607607
break;
608+
case 'TSImportType':
609+
state.commands.push('import(');
610+
handle(node.argument, state);
611+
state.commands.push(')');
612+
613+
if (node.qualifier) {
614+
state.commands.push('.');
615+
handle(node.qualifier, state);
616+
}
617+
break;
608618
default:
609619
throw new Error(`Not implemented type annotation ${node.type}`);
610620
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const foo: import('foo/bar') = 123;
2+
const bar: import('foo/bar').baz = 234;
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+
"const foo: import('foo/bar') = 123;\nconst bar: import('foo/bar').baz = 234;\n"
9+
],
10+
"mappings": "MAAM,GAAsB,SAAV,SAAS,IAAI,GAAG;MAC5B,GAA0B,SAAd,SAAS,EAAE,GAAG,GAAG,GAAG"
11+
}

test/samples/ts-import-type/input.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const foo: import('foo/bar') = 123;
2+
const bar: import('foo/bar').baz = 234;

0 commit comments

Comments
 (0)