提交 a5a2da1c 编写于 作者: fxy060608's avatar fxy060608

feat(v3): support >>> or /deep/ or ::v-deep in selectors (without scoped)

上级 7c48ee1f
......@@ -21,17 +21,38 @@ module.exports = postcss.plugin('postcss-uniapp-plugin', function (opts) {
rule.selectors = rule.selectors.map(complexSelector =>
// complexSelector => simpleSelectors
// "a.b#c" => ["a", ".b", "#c"]
transformSelector(complexSelector, simpleSelectors =>
transformSelector(complexSelector, simpleSelectors => {
simpleSelectors.each((selector) => {
// find the last child node to insert attribute selector
selector.each((n) => {
// ">>>" combinator
// and /deep/ alias for >>>, since >>> doesn't work in SASS
if (n.type === 'combinator' &&
(n.value === '>>>' || n.value ===
'/deep/')) {
n.value = ' '
n.spaces.before = n.spaces.after = ''
return false
}
// in newer versions of sass, /deep/ support is also dropped, so add a ::v-deep alias
if (n.type === 'pseudo' && n.value ===
'::v-deep') {
n.value = n.spaces.before = n.spaces.after =
''
return false
}
})
})
// only process type selector, leave alone class & id selectors
simpleSelectors.walkTags(tag => {
return simpleSelectors.walkTags(tag => {
if (tag.value === 'page') {
tag.value = 'body'
} else if (~TAGS.indexOf(tag.value) && tag.value.substring(
0, 4) !== 'uni-') {
0, 4) !== 'uni-') {
tag.value = 'uni-' + tag.value
}
})
)
})
)
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册