Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ed1649

Browse files
authored
Merge pull request #17214 from webpack/fix-regression
fix: regression
2 parents ccb3b86 + 06a1f0b commit 5ed1649

File tree

8 files changed

+93
-1
lines changed

8 files changed

+93
-1
lines changed

lib/dependencies/HarmonyExportExpressionDependency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
174174
runtimeRequirements.add(RuntimeGlobals.exports);
175175
// This is a little bit incorrect as TDZ is not correct, but we can't use const.
176176
content = `/* harmony default export */ ${exportsName}${propertyAccess(
177-
used
177+
typeof used === "string" ? [used] : used
178178
)} = `;
179179
} else {
180180
content = `/* unused harmony default export */ var ${name} = `;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const foo = 42;
2+
3+
module.exports = { foo };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const ___CSS_LOADER_EXPORT___ = {};
2+
___CSS_LOADER_EXPORT___.locals = {};
3+
export default ___CSS_LOADER_EXPORT___;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const baz = 11;
2+
3+
import { mod3 } from "./index";
4+
console.log(mod3.apple);
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export var apple = 45;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const bar = 42;
2+
3+
const def = -12;
4+
export default def;
5+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { foo as cjsexport_harmonyimport } from "./cjs-module";
2+
import theDefault, { bar as harmonyexport_harmonyimport } from "./harmony-module";
3+
import theDefaultExpression from "./export-default-expression";
4+
const { harmonyexport_cjsimport } = require("./harmony-module").bar;
5+
const harmonyexport_cjsimportdefault = require("./export-default-expression").default;
6+
import { baz as harmonyexport_harmonyimport_2 } from "./harmony-module-2";
7+
8+
import * as mod3 from "./harmony-module-3";
9+
export { mod3 };
10+
export { theDefaultExpression }
11+
12+
const { expectSourceToContain, expectSourceToMatch } = require("../../../helpers/expectSource");
13+
const regexEscape = require("../../../helpers/regexEscape.js");
14+
15+
// It's important to use propertyName when generating object members to ensure that the exported property name
16+
// uses the same accessor syntax (quotes vs. dot notatation) as the imported property name on the other end
17+
// (which needs to use propertyAccess). Else, minifiers such as Closure Compiler will not be able to minify correctly.
18+
it("should use the same accessor syntax for import and export", function() {
19+
20+
var fs = require("fs");
21+
var source = fs.readFileSync(__filename, "utf-8").toString();
22+
23+
// Reference these imports to generate uses in the source.
24+
25+
cjsexport_harmonyimport;
26+
harmonyexport_harmonyimport;
27+
harmonyexport_cjsimport;
28+
harmonyexport_harmonyimport_2;
29+
theDefault;
30+
theDefaultExpression;
31+
harmonyexport_cjsimportdefault;
32+
33+
/*********** DO NOT MATCH BELOW THIS LINE ***********/
34+
35+
// Checking harmonyexportinitfragment.js formation of standard export fragment
36+
expectSourceToContain(source, "/* harmony export */ bar: () => (/* binding */ bar)");
37+
38+
// Checking formation of imports
39+
expectSourceToMatch(source, `${regexEscape("const { harmonyexport_cjsimport } = (__webpack_require__(/*! ./harmony-module */ ")}\\d+${regexEscape(").bar);")}`);
40+
expectSourceToMatch(source, `${regexEscape("const harmonyexport_cjsimportdefault = (__webpack_require__(/*! ./export-default-expression */ ")}\\d+${regexEscape(")[\"default\"]);")}`);
41+
42+
// Checking concatenatedmodule.js formation of exports
43+
expectSourceToContain(source, "mod3: () => (/* reexport */ harmony_module_3_namespaceObject)");
44+
45+
// Checking concatenatedmodule.js formation of namespace objects
46+
expectSourceToContain(source, "apple: () => (apple)");
47+
48+
// Do not break default option
49+
expectSourceToContain(source, "[\"default\"] = (___CSS_LOADER_EXPORT___)");
50+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
output: {
4+
environment: {
5+
arrowFunction: true,
6+
bigIntLiteral: false,
7+
const: false,
8+
destructuring: false,
9+
forOf: false,
10+
dynamicImport: true,
11+
module: false
12+
}
13+
},
14+
node: {
15+
__dirname: false,
16+
__filename: false
17+
},
18+
optimization: {
19+
concatenateModules: true,
20+
usedExports: true,
21+
providedExports: true,
22+
minimize: false,
23+
mangleExports: false
24+
}
25+
};

0 commit comments

Comments
 (0)