Skip to content

Commit

Permalink
Merge branch 'master' of github.com:css-modules/postcss-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
madyankin committed Feb 23, 2022
2 parents f3bfc6d + a400e14 commit 8bd118d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/behaviours.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export function getDefaultPlugins({
const scope = modulesScope({ generateScopedName, exportGlobals });

const plugins = {
[behaviours.LOCAL]: [values, localByDefault, extractImports, scope],
[behaviours.GLOBAL]: [values, extractImports, scope],
[behaviours.LOCAL]: [values, localByDefault({ mode: 'local' }), extractImports, scope],
[behaviours.GLOBAL]: [values, localByDefault({ mode: 'global' }), extractImports, scope],
};

return plugins[behaviour];
Expand Down
38 changes: 38 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ p {
"
`;

exports[`only calls plugins once when it processes :global shorthand selector: plugins once - processes :global shorthand selector - CSS 1`] = `
"/* validator-2-start (globalShorthand.css) *//* validator-1-start (globalShorthand.css) */
.title {
color: red;
}/* validator-1-end (globalShorthand.css) *//* validator-2-end (globalShorthand.css) */
"
`;

exports[`only calls plugins once when it processes :local shorthand selector: plugins once - processes :local shorthand selector - CSS 1`] = `
"/* validator-2-start (localShorthand.css) *//* validator-1-start (localShorthand.css) */
._localShorthand_title {
color: red;
}/* validator-1-end (localShorthand.css) *//* validator-2-end (localShorthand.css) */
"
`;

exports[`only calls plugins once when it processes classes: plugins once - processes classes - CSS 1`] = `
"/* validator-2-start (classes.css) */
Expand Down Expand Up @@ -268,6 +284,28 @@ p {

exports[`preserves comments: preserves comments - JSON 1`] = `Object {}`;

exports[`processes :global shorthand selector: processes :global shorthand selector - CSS 1`] = `
".title {
color: red;
}
"
`;

exports[`processes :global shorthand selector: processes :global shorthand selector - JSON 1`] = `Object {}`;

exports[`processes :local shorthand selector: processes :local shorthand selector - CSS 1`] = `
"._localShorthand_title {
color: red;
}
"
`;

exports[`processes :local shorthand selector: processes :local shorthand selector - JSON 1`] = `
Object {
"title": "_localShorthand_title",
}
`;

exports[`processes classes: processes classes - CSS 1`] = `
".page {
padding: 20px;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/in/globalShorthand.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:global .title {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/in/localShorthand.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local .title {
color: red;
}
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const cases = {
values: "processes values",
interpolated: "generates scoped name with interpolated string",
global: "allows to make CSS global",
localShorthand: "processes :local shorthand selector",
globalShorthand: "processes :global shorthand selector",
};

function generateScopedName(name, filename) {
Expand All @@ -40,7 +42,9 @@ Object.keys(cases).forEach((name) => {
: generateScopedName;

const scopeBehaviour =
name === behaviours.GLOBAL ? behaviours.GLOBAL : behaviours.LOCAL;
name === behaviours.GLOBAL || name === "globalShorthand"
? behaviours.GLOBAL
: behaviours.LOCAL;

it(description, async () => {
const sourceFile = path.join(fixturesPath, "in", `${name}.css`);
Expand Down

0 comments on commit 8bd118d

Please sign in to comment.