Skip to content

postcss-nested-props breaks upon encountering :global or :local pseudo-selectors #9

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

Closed
Jessidhia opened this issue Aug 5, 2016 · 11 comments
Labels

Comments

@Jessidhia
Copy link

Jessidhia commented Aug 5, 2016

Note that I've encountered this in combination with sugarss, which encourages the use of this transform. css-modules uses the :global and :local pseudo-selectors to selectively disable/enable css-modules with the selectors nested within.

The following sugarss:

:global .selector
  prop: value
  another-prop: another-value

Gets transformed into the following CSS:

:global .selector {
  prop: value;
  another-prop: another-value
}

The previous CSS, after running by postcss-nested-props, is transformed into the following invalid CSS, even though no nested props are present:

: global .selector;
-prop: value;
-another-prop: another-value

It seems to understand :global as being a nesting of "empty string" with the "global .selector" property name, which... makes very little sense.

Is this intended to support a corner case where the caller specifies a prop value and nested props with the same prop declaration, without any whitespace? Perhaps it would be better to require whitespace before such a construct, specifically to prevent the syntactic ambiguity with pseudo-selectors and pseudo-elements. A regexp whitelist will always be a moving target, and will mysteriously cause breakages every time a new one is used.

@jednano jednano added the bug label Aug 29, 2016
jednano pushed a commit that referenced this issue Aug 29, 2016
@jednano
Copy link
Owner

jednano commented Aug 29, 2016

@Kovensky, I've added a commit to #8 that should be published in a week or two, whenever TypeScript 2.0.1 is officially released (should be soon). I'll be unavailable this weekend, however, as I'll be flying to China during that time.

@TamsynUlthara
Copy link

Any chance this fix can get published? I'd like to use this plugin, but I'm using CSS Modules.

@jednano
Copy link
Owner

jednano commented Jan 9, 2017

Gotta' wait a few more days for postcss/postcss#950. Sorry for the long wait. I lost track of this one somehow.

@TamsynUlthara
Copy link

No worries. Thanks!

jednano pushed a commit that referenced this issue Jan 20, 2017
@jednano
Copy link
Owner

jednano commented Jan 20, 2017

@tomxtobin can you give v1.1.5 a try?

@TamsynUlthara
Copy link

Finally got a chance to test it out. It's still not working, unfortunately.

I'm getting invalid CSS that's a little different than before: : global(.some-class-name).

Instead, the final CSS output should be .some-class-name.

@jednano
Copy link
Owner

jednano commented Jan 25, 2017

Do these two tests not represent the issue you have having? If not, can you write a failing test for me in the form of a PR?

@TamsynUlthara
Copy link

It needs to preserve all of these possible forms, in these contexts:

.zeroOrMoreSelectors :global .oneOrMoreSelectors
.zeroOrMoreSelectors :local .oneOrMoreSelectors
.zeroOrMoreSelectors :global(.oneOrMoreSelectors) .zeroOrMoreSelectors
.zeroOrMoreSelectors :local(.oneOrMoreSelectors) .zeroOrMoreSelectors

But sure, I can write a PR when I have a chance.

@jednano
Copy link
Owner

jednano commented Jan 25, 2017

Excellent, please do. I think it would add clarity to the exact scenarios in question. Also, if/when you do write the failing tests, try to keep it as simple as possible with foo, bar, baz and the like.

@jednano
Copy link
Owner

jednano commented Feb 22, 2017

@tomxtobin I've updated the dependencies, gutted gulp, introduced ava. It should be a bit easier for you to write tests now.

@jednano
Copy link
Owner

jednano commented Mar 17, 2017

@Kovensky, I've written a test, but it passes, so I can't reproduce your issue. Here's my test:

test('preserves :global selector rule', scenario(
	`:global .a{b:c;d:e;}`,
	`:global .a{b:c;d:e;}`
));

Closing until I can get a breaking test. Otherwise, it might just be the order in which you're loading your PostCSS plugins.

@jednano jednano closed this as completed Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants