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

Add support for dynamic import() syntax in TS types #380

Merged
merged 1 commit into from
Dec 29, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/parser/plugins/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,24 @@ function tsParseThisTypeNode(): void {

function tsParseTypeQuery(): void {
expect(tt._typeof);
tsParseEntityName();
if (match(tt._import)) {
tsParseImportType();
} else {
tsParseEntityName();
}
}

function tsParseImportType(): void {
expect(tt._import);
expect(tt.parenL);
expect(tt.string);
expect(tt.parenR);
if (eat(tt.dot)) {
tsParseEntityName();
}
if (match(tt.lessThan)) {
tsParseTypeArguments();
}
}

function tsParseTypeParameter(): void {
Expand Down Expand Up @@ -411,6 +428,9 @@ function tsParseNonArrayType(): void {
case tt._typeof:
tsParseTypeQuery();
return;
case tt._import:
tsParseImportType();
return;
case tt.braceL:
if (tsLookaheadIsStartOfMappedType()) {
tsParseMappedType();
Expand Down
17 changes: 17 additions & 0 deletions test/typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,23 @@ describe("typescript transform", () => {
let T = 3, b = 4, c = 5, d = 6;
console.log(T, b, c, d);
}
`,
);
});

it("handles import() types", () => {
assertTypeScriptESMResult(
`
type T1 = import("./foo");
type T2 = typeof import("./bar");
type T3 = import("./bar").Point;
type T4 = import("./utils").HashTable<number>;
`,
`




`,
);
});
Expand Down