Skip to content

Commit 522077b

Browse files
committed
fix(compiler-sfc): don't inject scope id before child combinator >
1 parent d5ada3d commit 522077b

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

packages/compiler-sfc/__tests__/compileStyle.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,12 @@ describe('SFC style preprocessors', () => {
520520
"[data-v-test]:last-child [data-v-test]:active { color: red;
521521
}"
522522
`)
523+
expect(compileScoped(`main { > * { background-color: yellow; } }`))
524+
.toMatchInlineSnapshot(`
525+
"main {
526+
> [data-v-test] { background-color: yellow;
527+
}
528+
}"
529+
`)
523530
})
524531
})

packages/compiler-sfc/src/style/pluginScoped.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ function rewriteSelector(
255255
)
256256
shouldInject = false
257257
}
258+
} else {
259+
// #13387 don't inject [id] at the selector start if node is null
260+
// and the selector starts with `>`
261+
const { type, value } = selector.first
262+
if (type === 'combinator' && value === '>') {
263+
shouldInject = false
264+
}
258265
}
259266

260267
if (node) {
@@ -266,8 +273,8 @@ function rewriteSelector(
266273
selector.first.spaces.before = ''
267274
}
268275

276+
const idToAdd = slotted ? id + '-s' : id
269277
if (shouldInject) {
270-
const idToAdd = slotted ? id + '-s' : id
271278
selector.insertAfter(
272279
// If node is null it means we need to inject [id] at the start
273280
// insertAfter can handle `null` here
@@ -279,20 +286,21 @@ function rewriteSelector(
279286
quoteMark: `"`,
280287
}),
281288
)
282-
// Used for trailing universal selectors (#12906)
283-
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
284-
if (starNode) {
285-
selector.insertBefore(
286-
starNode,
287-
selectorParser.attribute({
288-
attribute: idToAdd,
289-
value: idToAdd,
290-
raws: {},
291-
quoteMark: `"`,
292-
}),
293-
)
294-
selector.removeChild(starNode)
295-
}
289+
}
290+
291+
// Used for trailing universal selectors (#12906)
292+
// `.foo * {}` -> `.foo[xxxxxxx] [xxxxxxx] {}`
293+
if (starNode) {
294+
selector.insertBefore(
295+
starNode,
296+
selectorParser.attribute({
297+
attribute: idToAdd,
298+
value: idToAdd,
299+
raws: {},
300+
quoteMark: `"`,
301+
}),
302+
)
303+
selector.removeChild(starNode)
296304
}
297305
}
298306

0 commit comments

Comments
 (0)