-
-
Notifications
You must be signed in to change notification settings - Fork 76
fix selector ordering with pseudo elements #383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Changes to PostCSS Cascade Layers | ||
|
||
### Unreleased | ||
|
||
- Process CSS after most other plugins to ensure correct analysis and transformation of sugary CSS. | ||
- Fix selector order with `:before` and other pseudo elements. | ||
|
||
### 1.0.0 (May 12, 2022) | ||
|
||
- Initial version |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,18 +47,18 @@ export function sortCompoundSelector(node) { | |
|
||
node.nodes.sort((a, b) => { | ||
if (a.type === 'selector' && b.type === 'selector' && a.nodes.length && b.nodes.length) { | ||
return selectorTypeOrder(a.nodes[0].value, a.nodes[0].type) - selectorTypeOrder(b.nodes[0].value, b.nodes[0].type); | ||
return selectorTypeOrder(a.nodes[0], a.nodes[0].type) - selectorTypeOrder(b.nodes[0], b.nodes[0].type); | ||
} | ||
|
||
if (a.type === 'selector' && a.nodes.length) { | ||
return selectorTypeOrder(a.nodes[0].value, a.nodes[0].type) - selectorTypeOrder(b.value, b.type); | ||
return selectorTypeOrder(a.nodes[0], a.nodes[0].type) - selectorTypeOrder(b, b.type); | ||
} | ||
|
||
if (b.type === 'selector' && b.nodes.length) { | ||
return selectorTypeOrder(a.value, a.type) - selectorTypeOrder(b.nodes[0].value, b.nodes[0].type); | ||
return selectorTypeOrder(a, a.type) - selectorTypeOrder(b.nodes[0], b.nodes[0].type); | ||
} | ||
|
||
return selectorTypeOrder(a.value, a.type) - selectorTypeOrder(b.value, b.type); | ||
return selectorTypeOrder(a, a.type) - selectorTypeOrder(b, b.type); | ||
}); | ||
} | ||
|
||
|
@@ -67,9 +67,6 @@ function selectorTypeOrder(selector, type) { | |
return selectorTypeOrderIndex.pseudoElement; | ||
} | ||
|
||
if (type === 'pseudo' && selector && selector.indexOf('::') === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This code on line 70 was insufficient but did work with strings. Same change in all other plugins with similar logic. |
||
return selectorTypeOrderIndex.pseudoElement; | ||
} | ||
return selectorTypeOrderIndex[type]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => { | |
|
||
return { | ||
postcssPlugin: 'postcss-cascade-layers', | ||
Once(root: Container, { result }: { result: Result }) { | ||
OnceExit(root: Container, { result }: { result: Result }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see : #374 This change will likely be merged and released before we can add it to |
||
|
||
// Warnings | ||
if (options.onRevertLayerKeyword) { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,7 @@ | |
target { | ||
color: purple; | ||
} | ||
|
||
target:before { | ||
color: pink; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,7 @@ | |
target:not(#\##\##\##\##\##\#) { | ||
color: purple; | ||
} | ||
|
||
target:not(#\##\##\##\##\##\#):before { | ||
color: pink; | ||
} |
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.
This package lacked sufficient coverage for pseudo elements vs classes.