From ddb84c682b821ed949b5710d1fea1ed2722151cd Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 2 Apr 2024 21:07:57 +0300 Subject: [PATCH] test: added --- .../expected/main.js | 4 +- .../expected/main.js | 9 +- .../expected/main.css | 12 +++ .../expected/main.js | 93 +++++++++++++++++++ .../es-named-and-default-export/index.js | 8 ++ .../es-named-and-default-export/style.css | 11 +++ .../webpack.config.js | 36 +++++++ .../expected/main.mjs | 4 +- .../es-named-export-as-is/expected/main.js | 4 +- .../expected/main.mjs | 4 +- test/cases/es-named-export/expected/main.js | 4 +- .../expected/main.js | 4 +- 12 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 test/cases/es-named-and-default-export/expected/main.css create mode 100644 test/cases/es-named-and-default-export/expected/main.js create mode 100644 test/cases/es-named-and-default-export/index.js create mode 100644 test/cases/es-named-and-default-export/style.css create mode 100644 test/cases/es-named-and-default-export/webpack.config.js diff --git a/test/cases/custom-loader-with-functional-exports/expected/main.js b/test/cases/custom-loader-with-functional-exports/expected/main.js index 8648479e..e3e3d2ff 100644 --- a/test/cases/custom-loader-with-functional-exports/expected/main.js +++ b/test/cases/custom-loader-with-functional-exports/expected/main.js @@ -8,14 +8,12 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ cnA: () => (/* binding */ _1), -/* harmony export */ cnB: () => (/* binding */ _2), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cnB: () => (/* binding */ _2) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = () => "class-name-a"; var _2 = () => "class-name-b"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "cnA": _1, "cnB": _2 }); /***/ }) diff --git a/test/cases/es-module-concatenation-modules/expected/main.js b/test/cases/es-module-concatenation-modules/expected/main.js index 279943a9..918474db 100644 --- a/test/cases/es-module-concatenation-modules/expected/main.js +++ b/test/cases/es-module-concatenation-modules/expected/main.js @@ -48,16 +48,14 @@ __webpack_require__.d(__webpack_exports__, { var a_namespaceObject = {}; __webpack_require__.r(a_namespaceObject); __webpack_require__.d(a_namespaceObject, { - a: () => (_1), - "default": () => (a) + a: () => (_1) }); // NAMESPACE OBJECT: ./b.css var b_namespaceObject = {}; __webpack_require__.r(b_namespaceObject); __webpack_require__.d(b_namespaceObject, { - b: () => (b_1), - "default": () => (b) + b: () => (b_1) }); // NAMESPACE OBJECT: ./index.js @@ -73,19 +71,16 @@ __webpack_require__.d(index_namespaceObject, { // extracted by mini-css-extract-plugin var _1 = "foo__a"; -/* harmony default export */ const a = ({ "a": _1 }); ;// CONCATENATED MODULE: ./b.css // extracted by mini-css-extract-plugin var b_1 = "foo__b"; -/* harmony default export */ const b = ({ "b": b_1 }); ;// CONCATENATED MODULE: ./c.css // extracted by mini-css-extract-plugin var c_1 = "foo__c"; -/* harmony default export */ const c = ({ "c": c_1 }); ;// CONCATENATED MODULE: ./index.js /* eslint-disable import/no-namespace */ diff --git a/test/cases/es-named-and-default-export/expected/main.css b/test/cases/es-named-and-default-export/expected/main.css new file mode 100644 index 00000000..aa9b1569 --- /dev/null +++ b/test/cases/es-named-and-default-export/expected/main.css @@ -0,0 +1,12 @@ +.foo__style__a-class { + background: red; +} + +.foo__style__b__class { + color: green; +} + +.foo__style__cClass { + color: blue; +} + diff --git a/test/cases/es-named-and-default-export/expected/main.js b/test/cases/es-named-and-default-export/expected/main.js new file mode 100644 index 00000000..693ca53e --- /dev/null +++ b/test/cases/es-named-and-default-export/expected/main.js @@ -0,0 +1,93 @@ +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ([ +/* 0 */, +/* 1 */ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "a-class": () => (/* binding */ _1), +/* harmony export */ b__class: () => (/* binding */ _2), +/* harmony export */ cClass: () => (/* binding */ _3), +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ }); +// extracted by mini-css-extract-plugin +var _1 = "foo__style__a-class"; +var _2 = "foo__style__b__class"; +var _3 = "foo__style__cClass"; + +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 }); + + +/***/ }) +/******/ ]); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); + + +// eslint-disable-next-line no-console +console.log({ css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__["a-class"], bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.b__class, cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); + +})(); + +/******/ })() +; \ No newline at end of file diff --git a/test/cases/es-named-and-default-export/index.js b/test/cases/es-named-and-default-export/index.js new file mode 100644 index 00000000..aa114287 --- /dev/null +++ b/test/cases/es-named-and-default-export/index.js @@ -0,0 +1,8 @@ +import css, { + "a-class" as aClass, + "b__class" as bClass, + cClass, +} from "./style.css"; + +// eslint-disable-next-line no-console +console.log({ css, aClass, bClass, cClass }); diff --git a/test/cases/es-named-and-default-export/style.css b/test/cases/es-named-and-default-export/style.css new file mode 100644 index 00000000..a9085408 --- /dev/null +++ b/test/cases/es-named-and-default-export/style.css @@ -0,0 +1,11 @@ +.a-class { + background: red; +} + +.b__class { + color: green; +} + +.cClass { + color: blue; +} diff --git a/test/cases/es-named-and-default-export/webpack.config.js b/test/cases/es-named-and-default-export/webpack.config.js new file mode 100644 index 00000000..d7d364b3 --- /dev/null +++ b/test/cases/es-named-and-default-export/webpack.config.js @@ -0,0 +1,36 @@ +import Self from "../../../src"; + +module.exports = { + entry: "./index.js", + module: { + rules: [ + { + test: /\.css$/, + use: [ + { + loader: Self.loader, + options: { + defaultExport: true, + }, + }, + { + loader: "css-loader", + options: { + esModule: true, + modules: { + namedExport: true, + exportLocalsConvention: "asIs", + localIdentName: "foo__[name]__[local]", + }, + }, + }, + ], + }, + ], + }, + plugins: [ + new Self({ + filename: "[name].css", + }), + ], +}; diff --git a/test/cases/es-named-export-as-is-output-module/expected/main.mjs b/test/cases/es-named-export-as-is-output-module/expected/main.mjs index b1a9cd9c..dd030372 100644 --- a/test/cases/es-named-export-as-is-output-module/expected/main.mjs +++ b/test/cases/es-named-export-as-is-output-module/expected/main.mjs @@ -7,15 +7,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "a-class": () => (/* binding */ _1), /* harmony export */ b__class: () => (/* binding */ _2), -/* harmony export */ cClass: () => (/* binding */ _3), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cClass: () => (/* binding */ _3) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = "Xh041yLR4iCP4RGjge50"; var _2 = "NMuRsxoDwvW8BhSXhFAY"; var _3 = "ayWIv09rPsAqE2JznIsI"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 }); /***/ }) diff --git a/test/cases/es-named-export-as-is/expected/main.js b/test/cases/es-named-export-as-is/expected/main.js index 260d0610..a17ffa68 100644 --- a/test/cases/es-named-export-as-is/expected/main.js +++ b/test/cases/es-named-export-as-is/expected/main.js @@ -9,15 +9,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "a-class": () => (/* binding */ _1), /* harmony export */ b__class: () => (/* binding */ _2), -/* harmony export */ cClass: () => (/* binding */ _3), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cClass: () => (/* binding */ _3) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = "Xh041yLR4iCP4RGjge50"; var _2 = "NMuRsxoDwvW8BhSXhFAY"; var _3 = "ayWIv09rPsAqE2JznIsI"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 }); /***/ }) diff --git a/test/cases/es-named-export-output-module/expected/main.mjs b/test/cases/es-named-export-output-module/expected/main.mjs index ef9a39c9..eea1b171 100644 --- a/test/cases/es-named-export-output-module/expected/main.mjs +++ b/test/cases/es-named-export-output-module/expected/main.mjs @@ -7,15 +7,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ aClass: () => (/* binding */ _1), /* harmony export */ bClass: () => (/* binding */ _2), -/* harmony export */ cClass: () => (/* binding */ _3), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cClass: () => (/* binding */ _3) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = "foo__style__a-class"; var _2 = "foo__style__b__class"; var _3 = "foo__style__cClass"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "aClass": _1, "bClass": _2, "cClass": _3 }); /***/ }) diff --git a/test/cases/es-named-export/expected/main.js b/test/cases/es-named-export/expected/main.js index 4e92f660..08202354 100644 --- a/test/cases/es-named-export/expected/main.js +++ b/test/cases/es-named-export/expected/main.js @@ -9,15 +9,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "a-class": () => (/* binding */ _1), /* harmony export */ b__class: () => (/* binding */ _2), -/* harmony export */ cClass: () => (/* binding */ _3), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cClass: () => (/* binding */ _3) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = "foo__style__a-class"; var _2 = "foo__style__b__class"; var _3 = "foo__style__cClass"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 }); /***/ }) diff --git a/test/cases/export-only-locals-and-es-named-export/expected/main.js b/test/cases/export-only-locals-and-es-named-export/expected/main.js index ba7befb1..fc556c4f 100644 --- a/test/cases/export-only-locals-and-es-named-export/expected/main.js +++ b/test/cases/export-only-locals-and-es-named-export/expected/main.js @@ -9,15 +9,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ aClass: () => (/* binding */ _1), /* harmony export */ bClass: () => (/* binding */ _2), -/* harmony export */ cClass: () => (/* binding */ _3), -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) +/* harmony export */ cClass: () => (/* binding */ _3) /* harmony export */ }); // extracted by mini-css-extract-plugin var _1 = "foo__style__a-class"; var _2 = "foo__style__b__class"; var _3 = "foo__style__cClass"; -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "aClass": _1, "bClass": _2, "cClass": _3 }); /***/ })