diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 59152f8698..5d353121d5 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -9353,12 +9353,12 @@ pub const P = struct { } switch (data.value) { - .expr => |*expr| { - const was_anonymous_named_expr = expr.isAnonymousNamed(); - data.value.expr = p.visitExpr(expr.*); + .expr => |expr| { + const was_anonymous_named_expr = p.isAnonymousNamedExpr(expr); + data.value.expr = p.visitExpr(expr); // // Optionally preserve the name - data.value.expr = p.maybeKeepExprSymbolName(expr.*, "default", was_anonymous_named_expr); + data.value.expr = p.maybeKeepExprSymbolName(expr, "default", was_anonymous_named_expr); // Discard type-only export default statements if (p.options.ts) { @@ -9395,10 +9395,13 @@ pub const P = struct { if (func.func.name != null and func.func.name.?.ref != null) { stmts.append(p.keepStmtSymbolName(func.func.name.?.loc, func.func.name.?.ref.?, name)) catch unreachable; } + // prevent doubling export default function name + return; }, .s_class => |class| { var shadow_ref = p.visitClass(s2.loc, &class.class); stmts.appendSlice(p.lowerClass(js_ast.StmtOrExpr{ .stmt = stmt.* }, shadow_ref)) catch unreachable; + return; }, else => {}, } diff --git a/src/js_printer.zig b/src/js_printer.zig index c858a45f2b..c658871d47 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -313,6 +313,7 @@ pub fn NewPrinter(comptime ascii_only: bool) type { p.printIndent(); p.print("}"); } + pub fn printDecls(p: *Printer, keyword: string, decls: []G.Decl, flags: ExprFlag) void { debug("\n {s}", .{decls}); defer debug("", .{}); diff --git a/src/test/fixtures/double-export-default-bug.jsx b/src/test/fixtures/double-export-default-bug.jsx new file mode 100644 index 0000000000..3db411bb06 --- /dev/null +++ b/src/test/fixtures/double-export-default-bug.jsx @@ -0,0 +1,72 @@ +import Head from "next/head"; +import Image from "next/image"; +import styles from "../styles/Home.module.css"; +import "../lib/api.ts"; + +// The bug: +// This function appears twice in the output. +export default function Home() { + return ( +
+ + Create Next App + + + + +
+

+ Welcome to Next.js! +

+ +

+ Get started by editing{" "} + pages/index.js +

+ +
+ +

Documentation →

+

Find in-depth information about Next.js features and API.

+
+ + +

Learn →

+

Learn about Next.js in an interactive course with quizzes!

+
+ + +

Examples →

+

Discover and deploy boilerplate example Next.js projects.

+
+ + +

Deploy →

+

+ Instantly deploy your Next.js site to a public URL with Vercel. +

+
+
+
+ + +
+ ); +} diff --git a/src/test/fixtures/function-scope-bug.jsx b/src/test/fixtures/function-scope-bug.jsx index 57c783d87e..6c76e8fac7 100644 --- a/src/test/fixtures/function-scope-bug.jsx +++ b/src/test/fixtures/function-scope-bug.jsx @@ -14,7 +14,10 @@ var Bar = () => { ); }; -// This is where it failed. +// It failed while parsing this function. +// The bug happened due to incorrectly modifying scopes_in_order +// The fix was using tombstoning instead of deleting +// The fix also resolved some performance issues. var Baz = () => { return (
diff --git a/src/test/fixtures/simple-150x.jsx b/src/test/fixtures/simple-150x.jsx index 920e84ea50..385d28bab8 100644 --- a/src/test/fixtures/simple-150x.jsx +++ b/src/test/fixtures/simple-150x.jsx @@ -21,6 +21,7 @@ import LoginGate, { LOGIN_STATUSES } from "../components/LoginGate"; import Divider from "../components/Divider"; import { SPACING } from "../helpers/styles"; +// This is not saved in git 150x over because I don't want this repo to be huge. (function () { const FeaturedProfile = ({ profile }) => { return (