]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(sfc): ::slotted selector support
authorEvan You <yyx990803@gmail.com>
Mon, 16 Dec 2019 21:45:10 +0000 (16:45 -0500)
committerEvan You <yyx990803@gmail.com>
Tue, 17 Dec 2019 17:31:38 +0000 (12:31 -0500)
packages/compiler-sfc/src/stylePluginScoped.ts
packages/runtime-core/src/renderer.ts

index 32c132aedaeae3d20eebc1a28ab9c59b237294e1..0941c35da7be06d0415c82b61608ef8f1abb1585 100644 (file)
@@ -5,12 +5,12 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
   const id: string = options
   const keyframes = Object.create(null)
 
-  root.each(function rewriteSelector(node: any) {
+  root.each(function rewriteSelectors(node: any) {
     if (!node.selector) {
       // handle media queries
       if (node.type === 'atrule') {
         if (node.name === 'media' || node.name === 'supports') {
-          node.each(rewriteSelector)
+          node.each(rewriteSelectors)
         } else if (/-?keyframes$/.test(node.name)) {
           // register keyframes
           keyframes[node.params] = node.params = node.params + '-' + id
@@ -18,26 +18,26 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
       }
       return
     }
+
     node.selector = selectorParser((selectors: any) => {
-      selectors.each((selector: any) => {
+      selectors.each(function rewriteSelector(
+        selector: any,
+        _i: number,
+        slotted?: boolean
+      ) {
         let node: any = null
 
         // find the last child node to insert attribute selector
         selector.each((n: any) => {
-          // ">>>" 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 = ''
+          if (n.type === 'pseudo' && n.value === '::v-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 = ''
+          if (n.type === 'pseudo' && n.value === '::v-slotted') {
+            rewriteSelector(n.nodes[0], 0, true)
+            selectors.insertAfter(selector, n.nodes[0])
+            selectors.removeChild(selector)
             return false
           }
 
@@ -55,12 +55,14 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
           selector.first.spaces.before = ''
         }
 
+        const idToAdd = slotted ? id + '-s' : id
         selector.insertAfter(
           node,
           selectorParser.attribute({
-            attribute: id,
-            value: id,
-            raws: {}
+            attribute: idToAdd,
+            value: idToAdd,
+            raws: {},
+            quoteMark: `"`
           })
         )
       })
index 4fe570b6ba813bc6a762052f589affc86ea41105..8543e6ae7662f3088d447d6d09b06afc32587db7 100644 (file)
@@ -384,13 +384,15 @@ export function createRenderer<
     }
 
     // scopeId
-    if (__BUNDLER__ && scopeId !== null) {
-      hostSetScopeId(el, scopeId)
+    if (__BUNDLER__) {
+      if (scopeId !== null) {
+        hostSetScopeId(el, scopeId)
+      }
       const treeOwnerId = parentComponent && parentComponent.type.__scopeId
       // vnode's own scopeId and the current patched component's scopeId is
       // different - this is a slot content node.
       if (treeOwnerId != null && treeOwnerId !== scopeId) {
-        hostSetScopeId(el, treeOwnerId + '::slot')
+        hostSetScopeId(el, treeOwnerId + '-s')
       }
     }