mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix exporting default twice
This commit is contained in:
@@ -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 => {},
|
||||
}
|
||||
|
||||
@@ -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>", .{});
|
||||
|
||||
72
src/test/fixtures/double-export-default-bug.jsx
vendored
Normal file
72
src/test/fixtures/double-export-default-bug.jsx
vendored
Normal file
@@ -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 →</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 →</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 →</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 →</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>
|
||||
);
|
||||
}
|
||||
5
src/test/fixtures/function-scope-bug.jsx
vendored
5
src/test/fixtures/function-scope-bug.jsx
vendored
@@ -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}>
|
||||
|
||||
1
src/test/fixtures/simple-150x.jsx
vendored
1
src/test/fixtures/simple-150x.jsx
vendored
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user