aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js_parser/js_parser.zig11
-rw-r--r--src/js_printer.zig1
-rw-r--r--src/test/fixtures/double-export-default-bug.jsx72
-rw-r--r--src/test/fixtures/function-scope-bug.jsx5
-rw-r--r--src/test/fixtures/simple-150x.jsx1
5 files changed, 85 insertions, 5 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 59152f869..5d353121d 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 c858a45f2..c658871d4 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("<printDecls>\n {s}", .{decls});
defer debug("</printDecls>", .{});
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 000000000..3db411bb0
--- /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 (
+ <div className={styles.container}>
+ <Head>
+ <title>Create Next App</title>
+ <meta name="description" content="Generated by create next app" />
+ <link rel="icon" href="/favicon.ico" />
+ </Head>
+
+ <main className={styles.main}>
+ <h1 className={styles.title}>
+ Welcome to <a href="https://nextjs.org">Next.js!</a>
+ </h1>
+
+ <p className={styles.description}>
+ Get started by editing{" "}
+ <code className={styles.code}>pages/index.js</code>
+ </p>
+
+ <div className={styles.grid}>
+ <a href="https://nextjs.org/docs" className={styles.card}>
+ <h2>Documentation &rarr;</h2>
+ <p>Find in-depth information about Next.js features and API.</p>
+ </a>
+
+ <a href="https://nextjs.org/learn" className={styles.card}>
+ <h2>Learn &rarr;</h2>
+ <p>Learn about Next.js in an interactive course with quizzes!</p>
+ </a>
+
+ <a
+ href="https://github.com/vercel/next.js/tree/master/examples"
+ className={styles.card}
+ >
+ <h2>Examples &rarr;</h2>
+ <p>Discover and deploy boilerplate example Next.js projects.</p>
+ </a>
+
+ <a
+ href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
+ className={styles.card}
+ >
+ <h2>Deploy &rarr;</h2>
+ <p>
+ Instantly deploy your Next.js site to a public URL with Vercel.
+ </p>
+ </a>
+ </div>
+ </main>
+
+ <footer className={styles.footer}>
+ <a
+ href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ Powered by{" "}
+ <span className={styles.logo}>
+ <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
+ </span>
+ </a>
+ </footer>
+ </div>
+ );
+}
diff --git a/src/test/fixtures/function-scope-bug.jsx b/src/test/fixtures/function-scope-bug.jsx
index 57c783d87..6c76e8fac 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 (
<div prop={1}>
diff --git a/src/test/fixtures/simple-150x.jsx b/src/test/fixtures/simple-150x.jsx
index 920e84ea5..385d28bab 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 (