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

Incorrectly generates local selectors when using postcss-nested #45

Closed
joepie91 opened this issue Apr 23, 2022 · 2 comments
Closed

Incorrectly generates local selectors when using postcss-nested #45

joepie91 opened this issue Apr 23, 2022 · 2 comments

Comments

@joepie91
Copy link

Test case (all dependencies at latest):

"use strict";

const postcss = require("postcss");

let input = `
:global {
	.foo {
		color: blue;
	}
}

:global .foo {
	color: red;
}
`;

let instance = postcss([
	require("postcss-nested"),
	// require("postcss-modules-local-by-default", { mode: "local" })
]);

instance.process(input).then((result) => {
	console.log(result.css);
});

Output when run as-is:

Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.

:global .foo {
                color: blue;
        }

:global .foo {
        color: red;
}

Output when uncommenting (ie. enabling) postcss-modules-local-by-default:

Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.

 :local(.foo) {
                color: blue;
        }

.foo {
        color: red;
}

Both selectors should be global selectors considering that's how they both reduce down when using postcss-nested, but somehow the one with block-scoped :global incorrectly becomes a local.

I'm not quite sure why - when disabling postcss-modules-local-by-default and inspecting the result AST when only postcss-nested is used, both nodes appear to be identically structured... but maybe I'm missing some PostCSS subtlety here.

@Bygaga63
Copy link

Bygaga63 commented Sep 4, 2023

postcss/postcss-nested#157 also Andrey Sitnik recommended to move everything from Once method to proper Rule

@alexander-akait
Copy link
Member

The answer is above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants