Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support named exports with any characters #1057

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,39 @@ function pitch(request) {
return;
}

const result = locals
? namedExport
? Object.keys(locals)
const result = (function makeResult() {
// nb: `locals` is reassigned to const to improve TypeScript narrowing.
const scopeLocals = locals;
if (scopeLocals) {
if (namedExport) {
const identifiers = Array.from(
(function* generateIdentifiers() {
let identifierId = 0;
for (const key of Object.keys(scopeLocals)) {
identifierId += 1;
yield [`_${identifierId.toString(16)}`, key];
}
})()
);
const localsString = identifiers
.map(
(key) =>
`\nexport var ${key} = ${stringifyLocal(
/** @type {Locals} */ (locals)[key]
)};`
([id, key]) =>
`\nvar ${id} = ${stringifyLocal(scopeLocals[key])};`
)
.join("")
: `\n${
esModule ? "export default" : "module.exports ="
} ${JSON.stringify(locals)};`
: esModule
? `\nexport {};`
: "";

.join("");
const exportsString = `export { ${identifiers
.map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
.join(", ")} }`;
return `${localsString};\n${exportsString};\n`;
}
return `\n${
esModule ? "export default" : "module.exports = "
} ${JSON.stringify(locals)};`;
} else if (esModule) {
return "\nexport {};";
}
return "";
})();
let resultSource = `// extracted by ${MiniCssExtractPlugin.pluginName}`;

// only attempt hotreloading if the css is actually used for something other than hash values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ cnA: () => (/* binding */ cnA),
/* harmony export */ cnB: () => (/* binding */ cnB)
/* harmony export */ cnA: () => (/* binding */ _1),
/* harmony export */ cnB: () => (/* binding */ _2)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var cnA = () => "class-name-a";
var cnB = () => "class-name-b";
var _1 = () => "class-name-a";
var _2 = () => "class-name-b";;



/***/ })
/******/ ]);
Expand Down
20 changes: 13 additions & 7 deletions test/cases/es-module-concatenation-modules/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ __webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
a: () => (/* reexport */ a_namespaceObject),
b: () => (/* reexport */ b_namespaceObject),
c: () => (/* reexport */ c)
c: () => (/* reexport */ c_1)
});

// NAMESPACE OBJECT: ./a.css
var a_namespaceObject = {};
__webpack_require__.r(a_namespaceObject);
__webpack_require__.d(a_namespaceObject, {
a: () => (a)
a: () => (_1)
});

// NAMESPACE OBJECT: ./b.css
var b_namespaceObject = {};
__webpack_require__.r(b_namespaceObject);
__webpack_require__.d(b_namespaceObject, {
b: () => (b)
b: () => (b_1)
});

// NAMESPACE OBJECT: ./index.js
Expand All @@ -64,18 +64,24 @@ __webpack_require__.r(index_namespaceObject);
__webpack_require__.d(index_namespaceObject, {
a: () => (a_namespaceObject),
b: () => (b_namespaceObject),
c: () => (c)
c: () => (c_1)
});

;// CONCATENATED MODULE: ./a.css
// extracted by mini-css-extract-plugin
var a = "foo__a";
var _1 = "foo__a";;


;// CONCATENATED MODULE: ./b.css
// extracted by mini-css-extract-plugin
var b = "foo__b";
var b_1 = "foo__b";;


;// CONCATENATED MODULE: ./c.css
// extracted by mini-css-extract-plugin
var c = "foo__c";
var c_1 = "foo__c";;


;// CONCATENATED MODULE: ./index.js
/* eslint-disable import/no-namespace */

Expand Down
14 changes: 8 additions & 6 deletions test/cases/es-named-export-output-module/expected/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ aClass: () => (/* binding */ aClass),
/* harmony export */ bClass: () => (/* binding */ bClass),
/* harmony export */ cClass: () => (/* binding */ cClass)
/* harmony export */ aClass: () => (/* binding */ _1),
/* harmony export */ bClass: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var aClass = "foo__style__a-class";
var bClass = "foo__style__b__class";
var cClass = "foo__style__cClass";
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";;



/***/ })
/******/ ]);
Expand Down
14 changes: 8 additions & 6 deletions test/cases/es-named-export/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ aClass: () => (/* binding */ aClass),
/* harmony export */ bClass: () => (/* binding */ bClass),
/* harmony export */ cClass: () => (/* binding */ cClass)
/* harmony export */ aClass: () => (/* binding */ _1),
/* harmony export */ bClass: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var aClass = "foo__style__a-class";
var bClass = "foo__style__b__class";
var cClass = "foo__style__cClass";
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";;



/***/ })
/******/ ]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ aClass: () => (/* binding */ aClass),
/* harmony export */ bClass: () => (/* binding */ bClass),
/* harmony export */ cClass: () => (/* binding */ cClass)
/* harmony export */ aClass: () => (/* binding */ _1),
/* harmony export */ bClass: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var aClass = "foo__style__a-class";
var bClass = "foo__style__b__class";
var cClass = "foo__style__cClass";
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";;



/***/ })
/******/ ]);
Expand Down