diff options
-rw-r--r-- | integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js | 2 | ||||
-rw-r--r-- | integration/snapshots/export.debug.js | 14 | ||||
-rw-r--r-- | integration/snapshots/export.hmr.debug.js | 6 | ||||
-rw-r--r-- | integration/snapshots/string-escapes.debug.js | 2 | ||||
-rw-r--r-- | integration/snapshots/unicode-identifiers.debug.js | 2 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 114 |
6 files changed, 114 insertions, 26 deletions
diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js index 30348f9a0..d4472a8de 100644 --- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js +++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.debug.js @@ -4,7 +4,7 @@ import * as _loginReally from "http://localhost:8080/_login.js"; import * as _loginReally2 from "http://localhost:8080/_login.js"; import * as _authReally from "http://localhost:8080/_auth.js"; -export {_login as login}; +export { _login as login }; export function test() { return testDone(import.meta.url); diff --git a/integration/snapshots/export.debug.js b/integration/snapshots/export.debug.js index 184c92455..330e3bae0 100644 --- a/integration/snapshots/export.debug.js +++ b/integration/snapshots/export.debug.js @@ -1,7 +1,7 @@ import what from "http://localhost:8080/_auth.js"; -export {default as auth} from "http://localhost:8080/_auth.js"; +export { default as auth } from "http://localhost:8080/_auth.js"; -export {default as login} from "http://localhost:8080/_login.js"; +export { default as login } from "http://localhost:8080/_login.js"; export * from "http://localhost:8080/_bacon.js"; export let yoyoyo = "yoyoyo"; export default function hey() { @@ -12,14 +12,14 @@ export const foo = () => { export var bar = 100; export let powerLevel = Symbol("9001"); -export {what}; -export {what as when, what as whence}; -export {} from "http://localhost:8080/_bacon.js"; +export { what }; +export { what as when, what as whence }; +export { } from "http://localhost:8080/_bacon.js"; import * as where from "http://localhost:8080/_auth.js"; -export {where}; +export { where }; -export {bar as booop}; +export { bar as booop }; export function test() { hey(); foo(); diff --git a/integration/snapshots/export.hmr.debug.js b/integration/snapshots/export.hmr.debug.js index 5f75251f8..c76642f26 100644 --- a/integration/snapshots/export.hmr.debug.js +++ b/integration/snapshots/export.hmr.debug.js @@ -71,7 +71,7 @@ export { $$hmr_booop as booop, $$hmr_test as test }; -export {default as auth} from "http://localhost:8080/_auth.js"; -export {default as login} from "http://localhost:8080/_login.js"; +export { default as auth } from "http://localhost:8080/_auth.js"; +export { default as login } from "http://localhost:8080/_login.js"; export * from "http://localhost:8080/_bacon.js"; -export {} from "http://localhost:8080/_bacon.js"; +export { } from "http://localhost:8080/_bacon.js"; diff --git a/integration/snapshots/string-escapes.debug.js b/integration/snapshots/string-escapes.debug.js index 82dbc76e0..3fe3b5f4d 100644 --- a/integration/snapshots/string-escapes.debug.js +++ b/integration/snapshots/string-escapes.debug.js @@ -450,7 +450,7 @@ const Bar = foo("a", { const carriage = obj["\r\n"]; const newline = obj["\n"]; -export {obj}; +export { obj }; export function test() { console.assert(carriage === "\r\n"); console.assert(newline === "\n"); diff --git a/integration/snapshots/unicode-identifiers.debug.js b/integration/snapshots/unicode-identifiers.debug.js index 6e23e2929..375d2b995 100644 --- a/integration/snapshots/unicode-identifiers.debug.js +++ b/integration/snapshots/unicode-identifiers.debug.js @@ -7,7 +7,7 @@ var halfπ = π / 2; var d3_radians = π / 180; var d3_degrees = 180 / π; -export {d3_radians}; +export { d3_radians }; export function test() { console.assert(ε === 0.000001); return testDone(import.meta.url); diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index f8e782b65..dba43632b 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -7696,7 +7696,7 @@ fn NewParser_( p.declareBinding(kind, &local, opts) catch unreachable; // Skip over types - if (is_typescript_enabled) { + if (comptime is_typescript_enabled) { // "let foo!" var is_definite_assignment_assertion = p.lexer.token == .t_exclamation; if (is_definite_assignment_assertion) { @@ -7877,20 +7877,108 @@ fn NewParser_( } try p.lexer.next(); - if (p.lexer.isContextualKeyword("as")) { - try p.lexer.next(); - alias = try p.parseClauseAlias("export"); - alias_loc = p.lexer.loc(); + if (comptime is_typescript_enabled) { + if (strings.eqlComptime(alias, "type") and p.lexer.token != .t_comma and p.lexer.token != .t_close_brace) { + if (p.lexer.isContextualKeyword("as")) { + try p.lexer.next(); - try p.lexer.next(); - } + if (p.lexer.isContextualKeyword("as")) { + alias = try p.parseClauseAlias("export"); + alias_loc = p.lexer.loc(); + try p.lexer.next(); - items.append(js_ast.ClauseItem{ - .alias = alias, - .alias_loc = alias_loc, - .name = name, - .original_name = original_name, - }) catch unreachable; + if (p.lexer.token != .t_comma and p.lexer.token != .t_close_brace) { + // "export { type as as as }" + // "export { type as as foo }" + // "export { type as as 'foo' }" + _ = p.parseClauseAlias("export") catch ""; + try p.lexer.next(); + } else { + // "export { type as as }" + items.append(js_ast.ClauseItem{ + .alias = alias, + .alias_loc = alias_loc, + .name = name, + .original_name = original_name, + }) catch unreachable; + } + } else if (p.lexer.token != .t_comma and p.lexer.token != .t_close_brace) { + // "export { type as xxx }" + // "export { type as 'xxx' }" + alias = try p.parseClauseAlias("export"); + alias_loc = p.lexer.loc(); + try p.lexer.next(); + + items.append(js_ast.ClauseItem{ + .alias = alias, + .alias_loc = alias_loc, + .name = name, + .original_name = original_name, + }) catch unreachable; + } + } else { + // The name can actually be a keyword if we're really an "export from" + // statement. However, we won't know until later. Allow keywords as + // identifiers for now and throw an error later if there's no "from". + // + // // This is fine + // export { default } from 'path' + // + // // This is a syntax error + // export { default } + // + if (p.lexer.token != .t_identifier and first_non_identifier_loc.start == 0) { + first_non_identifier_loc = p.lexer.loc(); + } + + // "export { type xx }" + // "export { type xx as yy }" + // "export { type xx as if }" + // "export { type default } from 'path'" + // "export { type default as if } from 'path'" + // "export { type xx as 'yy' }" + // "export { type 'xx' } from 'mod'" + _ = p.parseClauseAlias("export") catch ""; + try p.lexer.next(); + + if (p.lexer.isContextualKeyword("as")) { + try p.lexer.next(); + _ = p.parseClauseAlias("export") catch ""; + try p.lexer.next(); + } + } + } else { + if (p.lexer.isContextualKeyword("as")) { + try p.lexer.next(); + alias = try p.parseClauseAlias("export"); + alias_loc = p.lexer.loc(); + + try p.lexer.next(); + } + + items.append(js_ast.ClauseItem{ + .alias = alias, + .alias_loc = alias_loc, + .name = name, + .original_name = original_name, + }) catch unreachable; + } + } else { + if (p.lexer.isContextualKeyword("as")) { + try p.lexer.next(); + alias = try p.parseClauseAlias("export"); + alias_loc = p.lexer.loc(); + + try p.lexer.next(); + } + + items.append(js_ast.ClauseItem{ + .alias = alias, + .alias_loc = alias_loc, + .name = name, + .original_name = original_name, + }) catch unreachable; + } // we're done if there's no comma if (p.lexer.token != .t_comma) { |