-
Notifications
You must be signed in to change notification settings - Fork 26
fix spec issues #88
fix spec issues #88
Conversation
- fix csstools#87 - add test to ensure that csstools#85 was fixed
@romainmenke nice work! I've started reviewing this and tests don't run for me. Only lint works and it throws on
|
99dcd6c
to
7e44004
Compare
7e44004
to
e5f3ee2
Compare
@Antonio-Laguna Thank you for checking! I updated it to just use |
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
|
||
- run: npm install --ignore-scripts | ||
- run: npm run build | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: npm install --ignore-scripts | ||
- run: npm run test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build fails in node 12, but this is fine.
We only support older node versions externally, not persé for building the plugin itself.
By switching node version and running install again we can build in node 16 and then test in node X
@romainmenke this is solid work. I've tested against all odd cases and it seems that produces spec complaint code :) |
} | ||
|
||
// foo &foo foo & baz -> foo &:is(foo) foo & baz | ||
toSelector = toSelector.replace(/&((?:[\w-_|])(?:[^\s,{]*))/g, (match, p1) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we’re open to regular expressions, then we should use a tokenizer. I will try to make a PR to this branch today. I expect to start on the work in about 5 hours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonathantneal Maybe with postcss-selector-parser
?
Might be too big a hammer, but could be easier to maintain than another tokenizer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was off by several hours, because I forgot it’s the day we all hand out treats to the neighborhood kids!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so good!
* fix spec issues * also fix nesting rules * one more test * cleanup * more fixes : - fix csstools/postcss-nesting#87 - add test to ensure that csstools/postcss-nesting#85 was fixed * update CI
This change was a bit trial and error and might contain issues.
Best to do a thorough review and question everything that looks weird or is unexpected.
In the context of
postcss-preset-env
there should be a moment where we can ship unaltered css to user agents, so it is important to fix spec issues imho.RuleExit
->Rule
Processing rules outside in (used to be inside out) ensures that the parent is always fully resolved and doesn't contain any nesting itself.
This was needed as we now optionally wrap the parent selector in
:is()
to support :body > h1, body p { & span {} }
->:is(body > h1, body p) span {}
If the parent selector contains nesting it would not be valid after wrapping in
:is()
:& h1, & h2 { & span {} }
->:is(& h1, & h2) span {}
(does not start with&
)First pass to split up and sanitise rules
The spec doesn't allow declarations after nesting :
https://www.w3.org/TR/css-nesting-1/#mixing
This is easy to handle on its own before expanding nested css.
rule
andat-rule
nodesrule
orat-rule
was encounteredrule
orat-rule
Rule within rule detect change :
A rule within rule selector is a valid if
&
is the first character and when it is a list if every selector in the list starts with&
.No other restrictions seem to exist.
A special provision for
|
exists. If|
is encountered the rule is skipped.This does not appear to be part of the spec. But this case existed before.
Nest rule within rule detect change :
A nest rule within rule selector is a valid if
&
exists and when it is a list if every selector in the list has&
.No other restrictions seem to exist.
A special provision for
|
exists. If|
is encountered the rule is skipped.This does not appear to be part of the spec. But this case existed before.
Merge selectors change :
This is highly opinionated but I try to avoid
.reduce()
(actually banned it in our org).It results in code that is difficult to grasp, difficult to refactor and prone to bugs.
.reduce()
:is()
when inserting the parent would alter or break the selector.:is()
when it is a list of selectors.These regexp's are used to wrap the child selectors :
Tested with examples like these :
test/direct.expect.css
This file has a lot of changes because we now wrap with
:is()
.The code is a bit too dense for me to be sure that all changes are correct and that no bugs were introduced here.