-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-sfc): nested css supports atrule and comment #11899
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
452dd73
fix(compiler-sfc): nested css supports atrule
linzhe141 924b887
chore: update
linzhe141 77b9adf
chore: update
linzhe141 5a332a0
chore: update test
linzhe141 a65e0f5
chore: update test
linzhe141 9f85035
chore: update test
linzhe141 aade28a
chore: update
linzhe141 9e79235
Update packages/compiler-sfc/src/style/pluginScoped.ts
linzhe141 3fc49c1
[autofix.ci] apply automated fixes
autofix-ci[bot] a52f369
chore: update test
linzhe141 72857e7
Update pluginScoped.ts
yyx990803 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,16 +233,12 @@ function rewriteSelector( | |
|
||
if (rule.nodes.some(node => node.type === 'rule')) { | ||
const deep = (rule as any).__deep | ||
const decls = rule.nodes.filter(node => node.type === 'decl') | ||
if (!deep && decls.length) { | ||
for (const decl of decls) { | ||
rule.removeChild(decl) | ||
if (!deep) { | ||
extractAndWrapNodes(rule) | ||
const atruleNodes = rule.nodes.filter(node => node.type === 'atrule') | ||
for (const atnode of atruleNodes) { | ||
extractAndWrapNodes(atnode) | ||
} | ||
const hostRule = new Rule({ | ||
nodes: decls, | ||
selector: '&', | ||
}) | ||
rule.prepend(hostRule) | ||
} | ||
shouldInject = deep | ||
} | ||
|
@@ -286,5 +282,22 @@ function isSpaceCombinator(node: selectorParser.Node) { | |
return node.type === 'combinator' && /^\s+$/.test(node.value) | ||
} | ||
|
||
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. leave newlines between functions. |
||
function extractAndWrapNodes(parentNode: Rule | AtRule) { | ||
if (!parentNode.nodes) return | ||
const nodes = parentNode.nodes.filter( | ||
node => node.type === 'decl' || node.type === 'comment', | ||
) | ||
if (nodes.length) { | ||
for (const node of nodes) { | ||
parentNode.removeChild(node) | ||
} | ||
const wrappedRule = new Rule({ | ||
nodes: nodes, | ||
selector: '&', | ||
}) | ||
parentNode.prepend(wrappedRule) | ||
} | ||
} | ||
|
||
scopedPlugin.postcss = true | ||
export default scopedPlugin |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.