Skip to content

Commit

Permalink
Support TypeScript's export type * as Foo from 'bar' (#4125)
Browse files Browse the repository at this point in the history
* [TypeScript] Support `export type * as Foo from 'bar'`

* Update js_parser.zig

---------

Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner authored Aug 12, 2023
1 parent ccb9daf commit 43ebffe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/js_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9966,16 +9966,37 @@ fn NewParser_(
}

fn skipTypeScriptTypeStmt(p: *P, opts: *ParseStatementOptions) anyerror!void {
if (opts.is_export and p.lexer.token == .t_open_brace) {
// "export type {foo}"
// "export type {foo} from 'bar'"
_ = try p.parseExportClause();
if (p.lexer.isContextualKeyword("from")) {
try p.lexer.next();
_ = try p.parsePath();
if (opts.is_export) {
switch (p.lexer.token) {
.t_open_brace => {
// "export type {foo}"
// "export type {foo} from 'bar'"
_ = try p.parseExportClause();
if (p.lexer.isContextualKeyword("from")) {
try p.lexer.next();
_ = try p.parsePath();
}
try p.lexer.expectOrInsertSemicolon();
return;
},
.t_asterisk => {
// https://github.com/microsoft/TypeScript/pull/52217
// - export type * as Foo from 'bar';
// - export type Foo from 'bar';
try p.lexer.next();
if (p.lexer.isContextualKeyword("as")) {
// "export type * as ns from 'path'"
try p.lexer.next();
_ = try p.parseClauseAlias("export");
try p.lexer.next();
}
try p.lexer.expectContextualKeyword("from");
_ = try p.parsePath();
try p.lexer.expectOrInsertSemicolon();
return;
},
else => {},
}
try p.lexer.expectOrInsertSemicolon();
return;
}

const name = p.lexer.identifier;
Expand Down
12 changes: 12 additions & 0 deletions test/bundler/esbuild/ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,18 @@ describe("bundler", () => {
]);
},
});
itBundled("ts/ExportType*", {
files: {
"/entry.ts": /* ts */ `
export type * as Foo from "foo";
export type * from "foo";
console.log("hi");
`,
},
run: {
stdout: "hi\n",
},
});
itBundled("ts/ExportDefaultTypeESBuildIssue316", {
files: {
"/entry.ts": /* ts */ `
Expand Down

0 comments on commit 43ebffe

Please sign in to comment.