From acfcf35297c242a4a1caf7cb601159b526731bd6 Mon Sep 17 00:00:00 2001 From: Alan Pierce Date: Sat, 29 Dec 2018 13:16:28 -0800 Subject: [PATCH] Add support for dynamic import() syntax in TS types Turns out this didn't work before, and I tried to use it when setting up code splitting in the playground. --- src/parser/plugins/typescript.ts | 6 ++++++ test/typescript-test.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/parser/plugins/typescript.ts b/src/parser/plugins/typescript.ts index 8f0a1e4f..b8bf6fb6 100644 --- a/src/parser/plugins/typescript.ts +++ b/src/parser/plugins/typescript.ts @@ -411,6 +411,12 @@ function tsParseNonArrayType(): void { case tt._typeof: tsParseTypeQuery(); return; + case tt._import: + next(); + expect(tt.parenL); + expect(tt.string); + expect(tt.parenR); + return; case tt.braceL: if (tsLookaheadIsStartOfMappedType()) { tsParseMappedType(); diff --git a/test/typescript-test.ts b/test/typescript-test.ts index b14c79da..faad7eb2 100644 --- a/test/typescript-test.ts +++ b/test/typescript-test.ts @@ -1324,4 +1324,15 @@ describe("typescript transform", () => { `, ); }); + + it("handles import() types", () => { + assertTypeScriptESMResult( + ` + type T = import("./foo"); + `, + ` + + `, + ); + }); });