Skip to content

Commit a1ccc8a

Browse files
authoredJan 6, 2023
feat(es/minifier): Make name mangler understand block scoping (#6670)
**Related issue:** - Closes #5090. - Closes #5766.
1 parent e9f99c4 commit a1ccc8a

File tree

208 files changed

+3087
-2775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+3087
-2775
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
async function test(listings) {
22
for (const listing of listings){}
3-
for (const listing1 of activeAndOpen){
4-
const listing11 = await foo(listing1);
5-
console.log(listing11);
3+
for (const listing of activeAndOpen){
4+
const listing1 = await foo(listing);
5+
console.log(listing1);
66
}
77
}

‎crates/swc/tests/fixture/next.js/server/render/1/output/index.tsx

+22-22
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
398398
props[SERVER_PROPS_ID] = true;
399399
}
400400
if (getServerSideProps && !isFallback) {
401-
let data1;
401+
let data;
402402
let canAccessRes = true;
403403
let resOrProxy = res;
404404
if (process.env.NODE_ENV !== "production") {
@@ -412,7 +412,7 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
412412
});
413413
}
414414
try {
415-
data1 = await getServerSideProps({
415+
data = await getServerSideProps({
416416
req: req,
417417
res: resOrProxy,
418418
query,
@@ -437,45 +437,45 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
437437
}
438438
throw serverSidePropsError;
439439
}
440-
if (data1 == null) {
440+
if (data == null) {
441441
throw new Error(GSSP_NO_RETURNED_VALUE);
442442
}
443-
const invalidKeys1 = Object.keys(data1).filter((key)=>key !== "props" && key !== "redirect" && key !== "notFound");
444-
if (data1.unstable_notFound) {
443+
const invalidKeys = Object.keys(data).filter((key)=>key !== "props" && key !== "redirect" && key !== "notFound");
444+
if (data.unstable_notFound) {
445445
throw new Error(`unstable_notFound has been renamed to notFound, please update the field to continue. Page: ${pathname}`);
446446
}
447-
if (data1.unstable_redirect) {
447+
if (data.unstable_redirect) {
448448
throw new Error(`unstable_redirect has been renamed to redirect, please update the field to continue. Page: ${pathname}`);
449449
}
450-
if (invalidKeys1.length) {
451-
throw new Error(invalidKeysMsg("getServerSideProps", invalidKeys1));
450+
if (invalidKeys.length) {
451+
throw new Error(invalidKeysMsg("getServerSideProps", invalidKeys));
452452
}
453-
if ("notFound" in data1 && data1.notFound) {
453+
if ("notFound" in data && data.notFound) {
454454
if (pathname === "/404") {
455455
throw new Error(`The /404 page can not return notFound in "getStaticProps", please remove it to continue!`);
456456
}
457457
renderOpts.isNotFound = true;
458458
return null;
459459
}
460-
if ("redirect" in data1 && typeof data1.redirect === "object") {
461-
checkRedirectValues(data1.redirect, req, "getServerSideProps");
462-
data1.props = {
463-
__N_REDIRECT: data1.redirect.destination,
464-
__N_REDIRECT_STATUS: getRedirectStatus(data1.redirect)
460+
if ("redirect" in data && typeof data.redirect === "object") {
461+
checkRedirectValues(data.redirect, req, "getServerSideProps");
462+
data.props = {
463+
__N_REDIRECT: data.redirect.destination,
464+
__N_REDIRECT_STATUS: getRedirectStatus(data.redirect)
465465
};
466-
if (typeof data1.redirect.basePath !== "undefined") {
467-
data1.props.__N_REDIRECT_BASE_PATH = data1.redirect.basePath;
466+
if (typeof data.redirect.basePath !== "undefined") {
467+
data.props.__N_REDIRECT_BASE_PATH = data.redirect.basePath;
468468
}
469469
renderOpts.isRedirect = true;
470470
}
471-
if (data1.props instanceof Promise) {
472-
data1.props = await data1.props;
471+
if (data.props instanceof Promise) {
472+
data.props = await data.props;
473473
}
474-
if ((dev || isBuildTimeSSG) && !isSerializableProps(pathname, "getServerSideProps", data1.props)) {
474+
if ((dev || isBuildTimeSSG) && !isSerializableProps(pathname, "getServerSideProps", data.props)) {
475475
// this fn should throw an error instead of ever returning `false`
476476
throw new Error("invariant: getServerSideProps did not return valid props. Please report this.");
477477
}
478-
props.pageProps = Object.assign({}, props.pageProps, data1.props);
478+
props.pageProps = Object.assign({}, props.pageProps, data.props);
479479
renderOpts.pageData = props;
480480
}
481481
if (!isSSG && // we only show this warning for legacy pages
@@ -545,12 +545,12 @@ export async function renderToHTML(req, res, pathname, query, renderOpts) {
545545
throw new Error(`'router' and 'Component' can not be returned in getInitialProps from _app.js https://nextjs.org/docs/messages/cant-override-next-props`);
546546
}
547547
const { App: EnhancedApp , Component: EnhancedComponent } = enhanceComponents(options, App, Component);
548-
const html1 = ReactDOMServer.renderToString(/*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(EnhancedApp, _extends({
548+
const html = ReactDOMServer.renderToString(/*#__PURE__*/ React.createElement(AppContainer, null, /*#__PURE__*/ React.createElement(EnhancedApp, _extends({
549549
Component: EnhancedComponent,
550550
router: router
551551
}, props))));
552552
return {
553-
html: html1,
553+
html,
554554
head
555555
};
556556
};

0 commit comments

Comments
 (0)
Please sign in to comment.