diff options
author | 2021-05-18 13:49:23 -0700 | |
---|---|---|
committer | 2021-05-18 13:49:23 -0700 | |
commit | e0e32986c76abc18a51041ddf14e339ba1cd0eb0 (patch) | |
tree | 10250a55288f297a3468e68d83172f2854d9aadc | |
parent | 54730377e204e709739db20b22880d3f7e6a450e (diff) | |
download | bun-e0e32986c76abc18a51041ddf14e339ba1cd0eb0.tar.gz bun-e0e32986c76abc18a51041ddf14e339ba1cd0eb0.tar.zst bun-e0e32986c76abc18a51041ddf14e339ba1cd0eb0.zip |
Fix duplicate exports error
Former-commit-id: 957e871f4a464eec39d849bad1873ed5518cf540
-rw-r--r-- | .vscode/launch.json | 4 | ||||
-rw-r--r-- | src/ast/base.zig | 2 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 28 | ||||
-rw-r--r-- | src/test/fixtures/duplicate-exports-bug.js | 5 |
4 files changed, 19 insertions, 20 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 55f7f8a34..2cb4fc3e4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -37,8 +37,8 @@ "args": [ "--resolve=disable", "--cwd", - "/Users/jarredsumner/Code/esdev/src/test/fixtures/", - "in-keyword.js" + "/Users/jarredsumner/Code/esdev/src/test/fixtures", + "duplicate-exports-bug.js" ], "cwd": "${workspaceFolder}", "console": "internalConsole" diff --git a/src/ast/base.zig b/src/ast/base.zig index 8e2635004..92f15f983 100644 --- a/src/ast/base.zig +++ b/src/ast/base.zig @@ -34,7 +34,7 @@ pub const Ref = packed struct { .source_index = std.math.maxInt(Ref.Int), }; pub fn toInt(int: anytype) Int { - return std.math.lossyCast(Ref.Int, int); + return @intCast(Int, int); } pub fn isNull(self: *const Ref) bool { return self.source_index == std.math.maxInt(Ref.Int) and self.inner_index == std.math.maxInt(Ref.Int); diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index e95d93bf0..a60765c47 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -2656,11 +2656,10 @@ pub const P = struct { if (name) |*name_| { const kind = if (is_generator or is_async) Symbol.Kind.generator_or_async_function else Symbol.Kind.hoisted_function; name_.ref = try p.declareSymbol(kind, name_.loc, nameText); + func.name = name_.*; } - func.name = name; func.flags.has_if_scope = hasIfScope; - func.flags.is_export = opts.is_export; // Balance the fake block scope introduced above @@ -4692,9 +4691,9 @@ pub const P = struct { pub fn parseExportClause(p: *P) !ExportClauseResult { var items = List(js_ast.ClauseItem).initCapacity(p.allocator, 1) catch unreachable; - var first_keyword_item_loc = logger.Loc{}; try p.lexer.expect(.t_open_brace); var is_single_line = !p.lexer.has_newline_before; + var first_non_identifier_loc = logger.Loc{ .start = 0 }; while (p.lexer.token != .t_close_brace) { var alias = try p.parseClauseAlias("export"); @@ -4716,16 +4715,9 @@ pub const P = struct { // // This is a syntax error // export { default } // - if (p.lexer.token != .t_identifier) { - if (!p.lexer.isIdentifierOrKeyword()) { - try p.lexer.expect(.t_identifier); - } - if (first_keyword_item_loc.start < 0) { - first_keyword_item_loc = p.lexer.loc(); - } + if (p.lexer.token != .t_identifier and first_non_identifier_loc.start == 0) { + first_non_identifier_loc = p.lexer.loc(); } - - p.checkForNonBMPCodePoint(alias_loc, alias); try p.lexer.next(); if (p.lexer.isContextualKeyword("as")) { @@ -4764,13 +4756,13 @@ pub const P = struct { // Throw an error here if we found a keyword earlier and this isn't an // "export from" statement after all - if (first_keyword_item_loc.start > -1 and !p.lexer.isContextualKeyword("from")) { - const r = js_lexer.rangeOfIdentifier(p.source, first_keyword_item_loc); + if (first_non_identifier_loc.start != 0 and !p.lexer.isContextualKeyword("from")) { + const r = js_lexer.rangeOfIdentifier(p.source, first_non_identifier_loc); try p.lexer.addRangeError(r, "Expected identifier but found \"{s}\"", .{p.source.textForRange(r)}, true); } return ExportClauseResult{ - .clauses = items.toOwnedSlice(), + .clauses = items.items, .is_single_line = is_single_line, }; } @@ -4793,7 +4785,8 @@ pub const P = struct { // TODO: pub fn checkForNonBMPCodePoint(p: *P, loc: logger.Loc, name: string) void {} - pub fn parseStmtsUpTo(p: *P, eend: js_lexer.T, opts: *ParseStatementOptions) ![]Stmt { + pub fn parseStmtsUpTo(p: *P, eend: js_lexer.T, _opts: *ParseStatementOptions) ![]Stmt { + var opts = _opts.*; var stmts = StmtList.init(p.allocator); var returnWithoutSemicolonStart: i32 = -1; @@ -4811,7 +4804,8 @@ pub const P = struct { break; } - var stmt = try p.parseStmt(opts); + var current_opts = opts; + var stmt = try p.parseStmt(¤t_opts); // Skip TypeScript types entirely if (p.options.ts) { diff --git a/src/test/fixtures/duplicate-exports-bug.js b/src/test/fixtures/duplicate-exports-bug.js new file mode 100644 index 000000000..c92e18601 --- /dev/null +++ b/src/test/fixtures/duplicate-exports-bug.js @@ -0,0 +1,5 @@ +export function boop() {} + +var UniformsUtils; + +export { UniformsUtils }; |