Unverified Commit 3418eaf4 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix CJS optimizer (#50376)

Avoid the new `VarDecl` being inserted multiple times.
parent cf9591cd
......@@ -134,14 +134,22 @@ impl VisitMut for CjsOptimizer {
definite: false,
};
self.data.extra_stmts.push(Stmt::Decl(Decl::Var(Box::new(
VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![var],
},
))));
if !self.data.extra_stmts.clone().into_iter().any(|s| {
if let Stmt::Decl(Decl::Var(v)) = &s {
v.decls.iter().any(|d| d.name == var.name)
} else {
false
}
}) {
self.data.extra_stmts.push(Stmt::Decl(Decl::Var(
Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![var],
}),
)));
}
*e = Expr::Ident(new_id.into());
}
......
const server_1 = require('next/server')
server_1.Response()
server_1.Response.rewrite()
const Response = require("next/server/response").Response;
;
Response();
Response.rewrite();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment