Skip to content

fix(compiler-sfc): don't inject scope id before child combinator > #13389

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/compiler-sfc/__tests__/compileStyle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,5 +520,12 @@ describe('SFC style preprocessors', () => {
"[data-v-test]:last-child [data-v-test]:active { color: red;
}"
`)
expect(compileScoped(`main { > * { background-color: yellow; } }`))
.toMatchInlineSnapshot(`
"main {
> [data-v-test] { background-color: yellow;
}
}"
`)
})
})
38 changes: 23 additions & 15 deletions packages/compiler-sfc/src/style/pluginScoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ function rewriteSelector(
)
shouldInject = false
}
} else {
// #13387 don't inject [id] at the selector start if node is null
// and the selector starts with a non-empty combinator
const { type, value } = selector.first
if (type === 'combinator' && value !== ' ') {
shouldInject = false
}
}

if (node) {
Expand All @@ -266,8 +273,8 @@ function rewriteSelector(
selector.first.spaces.before = ''
}

const idToAdd = slotted ? id + '-s' : id
if (shouldInject) {
const idToAdd = slotted ? id + '-s' : id
selector.insertAfter(
// If node is null it means we need to inject [id] at the start
// insertAfter can handle `null` here
Expand All @@ -279,20 +286,21 @@ function rewriteSelector(
quoteMark: `"`,
}),
)
// Used for trailing universal selectors (#12906)
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
if (starNode) {
selector.insertBefore(
starNode,
selectorParser.attribute({
attribute: idToAdd,
value: idToAdd,
raws: {},
quoteMark: `"`,
}),
)
selector.removeChild(starNode)
}
}

// Used for trailing universal selectors (#12906)
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
if (starNode) {
selector.insertBefore(
starNode,
selectorParser.attribute({
attribute: idToAdd,
value: idToAdd,
raws: {},
quoteMark: `"`,
}),
)
selector.removeChild(starNode)
}
}

Expand Down