Skip to content

Commit

Permalink
fix: do not break @scope at-rule without params (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Apr 3, 2024
1 parent 6274480 commit e022e3b
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"icss-utils": "^5.1.0",
"postcss": "^8.4.33",
"postcss-modules-extract-imports": "^3.0.0",
"postcss-modules-local-by-default": "^4.0.4",
"postcss-modules-local-by-default": "^4.0.5",
"postcss-modules-scope": "^3.1.2",
"postcss-modules-values": "^4.0.0",
"postcss-value-parser": "^4.2.0",
Expand Down
63 changes: 63 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10330,6 +10330,12 @@ ___CSS_LOADER_EXPORT___.push([module.id, \`@scope (.kthHR5ALtmYK9QgapjA3) {
color: plum;
}
}

@scope {
:scope {
color: red;
}
}
\`, \\"\\"]);
// Exports
___CSS_LOADER_EXPORT___.locals = {
Expand Down Expand Up @@ -10366,6 +10372,12 @@ Array [
color: plum;
}
}

@scope {
:scope {
color: red;
}
}
",
"",
],
Expand Down Expand Up @@ -20968,6 +20980,57 @@ Array [

exports[`"modules" option should work with composes when the "namedExport" is enabled and "exportLocalsConvention" options has "dashesOnly" value: warnings 1`] = `Array []`;

exports[`"modules" option should work with global compose: errors 1`] = `Array []`;

exports[`"modules" option should work with global compose: module 1`] = `
"// Imports
import ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \\"../../../../src/runtime/noSourceMaps.js\\";
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);
// Module
___CSS_LOADER_EXPORT___.push([module.id, \`.global-class {
color: red;
}

.other-global-class {
color: red;
}

.oNDnA1BRHWFMyAdR4iF1 {
color: blue;
}
\`, \\"\\"]);
// Exports
___CSS_LOADER_EXPORT___.locals = {
\\"otherClassName\\": \`oNDnA1BRHWFMyAdR4iF1 global-class other-global-class\`
};
export default ___CSS_LOADER_EXPORT___;
"
`;

exports[`"modules" option should work with global compose: result 1`] = `
Array [
Array [
"./modules/composes/global.css",
".global-class {
color: red;
}

.other-global-class {
color: red;
}

.oNDnA1BRHWFMyAdR4iF1 {
color: blue;
}
",
"",
],
]
`;

exports[`"modules" option should work with global compose: warnings 1`] = `Array []`;

exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: errors 1`] = `Array []`;

exports[`"modules" option should work with the "[local]" placeholder for the "localIdentName" option: module 1`] = `
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/modules/composes/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
:global(.global-class) {
color: red;
}

:global(.other-global-class) {
color: red;
}

.otherClassName {
composes: global-class from global;
composes: other-global-class from global;
color: blue;
}
5 changes: 5 additions & 0 deletions test/fixtures/modules/composes/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import css from './global.css';

__export__ = css;

export default css;
6 changes: 6 additions & 0 deletions test/fixtures/modules/scope/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
color: plum;
}
}

@scope {
:scope {
color: red;
}
}
16 changes: 16 additions & 0 deletions test/modules-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2417,4 +2417,20 @@ describe('"modules" option', () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should work with global compose", async () => {
const compiler = getCompiler("./modules/composes/global.js", {
modules: true,
});
const stats = await compile(compiler);

expect(
getModuleSource("./modules/composes/global.css", stats)
).toMatchSnapshot("module");
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
"result"
);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});

0 comments on commit e022e3b

Please sign in to comment.