rewriteSelector() — vue Function Reference
Architecture documentation for the rewriteSelector() function in scoped.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD 346bd118_1c41_64e1_58b1_7fd70084a476["rewriteSelector()"] 822b2e28_d690_8f44_42af_ffc75c6a194a["scoped.ts"] 346bd118_1c41_64e1_58b1_7fd70084a476 -->|defined in| 822b2e28_d690_8f44_42af_ffc75c6a194a cbc564d0_cbc4_b3c1_202b_f67e009171ed["processRule()"] cbc564d0_cbc4_b3c1_202b_f67e009171ed -->|calls| 346bd118_1c41_64e1_58b1_7fd70084a476 a4089a0e_533d_5a8b_1c61_5a7c181491d7["isSpaceCombinator()"] 346bd118_1c41_64e1_58b1_7fd70084a476 -->|calls| a4089a0e_533d_5a8b_1c61_5a7c181491d7 style 346bd118_1c41_64e1_58b1_7fd70084a476 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/compiler-sfc/src/stylePlugins/scoped.ts lines 80–196
function rewriteSelector(
id: string,
selector: selectorParser.Selector,
selectorRoot: selectorParser.Root
) {
let node: selectorParser.Node | null = null
let shouldInject = true
// find the last child node to insert attribute selector
selector.each(n => {
// DEPRECATED ">>>" and "/deep/" combinator
if (
n.type === 'combinator' &&
(n.value === '>>>' || n.value === '/deep/')
) {
n.value = ' '
n.spaces.before = n.spaces.after = ''
// warn(
// `the >>> and /deep/ combinators have been deprecated. ` +
// `Use :deep() instead.`
// )
return false
}
if (n.type === 'pseudo') {
const { value } = n
// deep: inject [id] attribute at the node before the ::v-deep
// combinator.
if (value === ':deep' || value === '::v-deep') {
if (n.nodes.length) {
// .foo ::v-deep(.bar) -> .foo[xxxxxxx] .bar
// replace the current node with ::v-deep's inner selector
let last: selectorParser.Selector['nodes'][0] = n
n.nodes[0].each(ss => {
selector.insertAfter(last, ss)
last = ss
})
// insert a space combinator before if it doesn't already have one
const prev = selector.at(selector.index(n) - 1)
if (!prev || !isSpaceCombinator(prev)) {
selector.insertAfter(
n,
selectorParser.combinator({
value: ' '
})
)
}
selector.removeChild(n)
} else {
// DEPRECATED usage in v3
// .foo ::v-deep .bar -> .foo[xxxxxxx] .bar
// warn(
// `::v-deep usage as a combinator has ` +
// `been deprecated. Use :deep(<inner-selector>) instead.`
// )
const prev = selector.at(selector.index(n) - 1)
if (prev && isSpaceCombinator(prev)) {
selector.removeChild(prev)
}
selector.removeChild(n)
}
return false
}
// !!! Vue 2 does not have :slotted support
// ::v-slotted(.foo) -> .foo[xxxxxxx-s]
// if (value === ':slotted' || value === '::v-slotted') {
// rewriteSelector(id, n.nodes[0], selectorRoot, true /* slotted */)
// let last: selectorParser.Selector['nodes'][0] = n
// n.nodes[0].each(ss => {
// selector.insertAfter(last, ss)
// last = ss
// })
// // selector.insertAfter(n, n.nodes[0])
// selector.removeChild(n)
// // since slotted attribute already scopes the selector there's no
// // need for the non-slot attribute.
// shouldInject = false
// return false
// }
// global: replace with inner selector and do not inject [id].
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does rewriteSelector() do?
rewriteSelector() is a function in the vue codebase, defined in packages/compiler-sfc/src/stylePlugins/scoped.ts.
Where is rewriteSelector() defined?
rewriteSelector() is defined in packages/compiler-sfc/src/stylePlugins/scoped.ts at line 80.
What does rewriteSelector() call?
rewriteSelector() calls 1 function(s): isSpaceCombinator.
What calls rewriteSelector()?
rewriteSelector() is called by 1 function(s): processRule.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free