Merge pull request #17214 from webpack/fix-regression

fix: regression
This commit is contained in:
Sean Larkin 2023-05-17 13:18:56 -07:00 committed by GitHub
commit 5ed1649e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 93 additions and 1 deletions

View File

@ -174,7 +174,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
runtimeRequirements.add(RuntimeGlobals.exports);
// This is a little bit incorrect as TDZ is not correct, but we can't use const.
content = `/* harmony default export */ ${exportsName}${propertyAccess(
used
typeof used === "string" ? [used] : used
)} = `;
} else {
content = `/* unused harmony default export */ var ${name} = `;

View File

@ -0,0 +1,3 @@
const foo = 42;
module.exports = { foo };

View File

@ -0,0 +1,3 @@
const ___CSS_LOADER_EXPORT___ = {};
___CSS_LOADER_EXPORT___.locals = {};
export default ___CSS_LOADER_EXPORT___;

View File

@ -0,0 +1,5 @@
export const baz = 11;
import { mod3 } from "./index";
console.log(mod3.apple);

View File

@ -0,0 +1 @@
export var apple = 45;

View File

@ -0,0 +1,5 @@
export const bar = 42;
const def = -12;
export default def;

View File

@ -0,0 +1,50 @@
import { foo as cjsexport_harmonyimport } from "./cjs-module";
import theDefault, { bar as harmonyexport_harmonyimport } from "./harmony-module";
import theDefaultExpression from "./export-default-expression";
const { harmonyexport_cjsimport } = require("./harmony-module").bar;
const harmonyexport_cjsimportdefault = require("./export-default-expression").default;
import { baz as harmonyexport_harmonyimport_2 } from "./harmony-module-2";
import * as mod3 from "./harmony-module-3";
export { mod3 };
export { theDefaultExpression }
const { expectSourceToContain, expectSourceToMatch } = require("../../../helpers/expectSource");
const regexEscape = require("../../../helpers/regexEscape.js");
// It's important to use propertyName when generating object members to ensure that the exported property name
// uses the same accessor syntax (quotes vs. dot notatation) as the imported property name on the other end
// (which needs to use propertyAccess). Else, minifiers such as Closure Compiler will not be able to minify correctly.
it("should use the same accessor syntax for import and export", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8").toString();
// Reference these imports to generate uses in the source.
cjsexport_harmonyimport;
harmonyexport_harmonyimport;
harmonyexport_cjsimport;
harmonyexport_harmonyimport_2;
theDefault;
theDefaultExpression;
harmonyexport_cjsimportdefault;
/*********** DO NOT MATCH BELOW THIS LINE ***********/
// Checking harmonyexportinitfragment.js formation of standard export fragment
expectSourceToContain(source, "/* harmony export */ bar: () => (/* binding */ bar)");
// Checking formation of imports
expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(/*! ./harmony-module */ ")}\\d+${regexEscape(").bar);")}`);
expectSourceToMatch(source, `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(/*! ./export-default-expression */ ")}\\d+${regexEscape(")[\"default\"]);")}`);
// Checking concatenatedmodule.js formation of exports
expectSourceToContain(source, "mod3: () => (/* reexport */ harmony_module_3_namespaceObject)");
// Checking concatenatedmodule.js formation of namespace objects
expectSourceToContain(source, "apple: () => (apple)");
// Do not break default option
expectSourceToContain(source, "[\"default\"] = (___CSS_LOADER_EXPORT___)");
});

View File

@ -0,0 +1,25 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
environment: {
arrowFunction: true,
bigIntLiteral: false,
const: false,
destructuring: false,
forOf: false,
dynamicImport: true,
module: false
}
},
node: {
__dirname: false,
__filename: false
},
optimization: {
concatenateModules: true,
usedExports: true,
providedExports: true,
minimize: false,
mangleExports: false
}
};