]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler): mark compiler-generated slots for runtime
authorEvan You <yyx990803@gmail.com>
Thu, 3 Oct 2019 18:08:14 +0000 (14:08 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 3 Oct 2019 18:08:14 +0000 (14:08 -0400)
packages/compiler-core/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap
packages/compiler-core/__tests__/transforms/vSlot.spec.ts
packages/compiler-core/src/transforms/vSlot.ts
packages/runtime-core/src/componentSlots.ts

index 78142174a72eb79ff53503db4c364f81644510a7..6d5193d53b355713a4b04d34c1addbc239de3ee4 100644 (file)
@@ -9,7 +9,8 @@ return function render() {
   
   return (openBlock(), createBlock(_component_Comp, null, {
     [_ctx.one]: ({ foo }) => [toString(foo), toString(_ctx.bar)],
-    [_ctx.two]: ({ bar }) => [toString(_ctx.foo), toString(bar)]
+    [_ctx.two]: ({ bar }) => [toString(_ctx.foo), toString(bar)],
+    _compiled: true
   }, 256 /* DYNAMIC_SLOTS */))
 }"
 `;
@@ -22,7 +23,8 @@ return function render() {
   const _component_Comp = resolveComponent(\\"Comp\\")
   
   return (openBlock(), createBlock(_component_Comp, null, {
-    default: ({ foo }) => [toString(foo), toString(_ctx.bar)]
+    default: ({ foo }) => [toString(foo), toString(_ctx.bar)],
+    _compiled: true
   }))
 }"
 `;
@@ -37,7 +39,8 @@ return function render() {
   return (openBlock(), createBlock(_component_Comp, null, {
     default: () => [
       createVNode(\\"div\\")
-    ]
+    ],
+    _compiled: true
   }))
 }"
 `;
@@ -49,7 +52,7 @@ return function render() {
   const _ctx = this
   const _component_Comp = resolveComponent(\\"Comp\\")
   
-  return (openBlock(), createBlock(_component_Comp, null, createSlots({}, [
+  return (openBlock(), createBlock(_component_Comp, null, createSlots({ _compiled: true }, [
     renderList(_ctx.list, (name) => {
       return {
         name: name,
@@ -67,7 +70,7 @@ return function render() {
   const _ctx = this
   const _component_Comp = resolveComponent(\\"Comp\\")
   
-  return (openBlock(), createBlock(_component_Comp, null, createSlots({}, [
+  return (openBlock(), createBlock(_component_Comp, null, createSlots({ _compiled: true }, [
     (_ctx.ok)
       ? {
           name: \\"one\\",
@@ -87,7 +90,7 @@ return function render() {
     
     const _component_Comp = _resolveComponent(\\"Comp\\")
     
-    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({}, [
+    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
       ok
         ? {
             name: \\"one\\",
@@ -116,7 +119,7 @@ return function render() {
     
     const _component_Comp = _resolveComponent(\\"Comp\\")
     
-    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({}, [
+    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
       ok
         ? {
             name: \\"one\\",
@@ -137,7 +140,8 @@ return function render() {
   
   return (openBlock(), createBlock(_component_Comp, null, {
     one: ({ foo }) => [toString(foo), toString(_ctx.bar)],
-    two: ({ bar }) => [toString(_ctx.foo), toString(bar)]
+    two: ({ bar }) => [toString(_ctx.foo), toString(bar)],
+    _compiled: true
   }))
 }"
 `;
@@ -153,12 +157,14 @@ return function render() {
   return (openBlock(), createBlock(_component_Comp, null, {
     default: ({ foo }) => [
       createVNode(_component_Inner, null, {
-        default: ({ bar }) => [toString(foo), toString(bar), toString(_ctx.baz)]
+        default: ({ bar }) => [toString(foo), toString(bar), toString(_ctx.baz)],
+        _compiled: true
       }),
       toString(foo),
       toString(_ctx.bar),
       toString(_ctx.baz)
-    ]
+    ],
+    _compiled: true
   }))
 }"
 `;
index a36e5388ad140875a541dcc7a6e358aefdc0c718..5dc22d4c4e1453a633aa08ea6477d879d31871ef 100644 (file)
@@ -43,17 +43,22 @@ function parseWithSlots(template: string, options: CompilerOptions = {}) {
 function createSlotMatcher(obj: Record<string, any>) {
   return {
     type: NodeTypes.JS_OBJECT_EXPRESSION,
-    properties: Object.keys(obj).map(key => {
-      return {
-        type: NodeTypes.JS_PROPERTY,
-        key: {
-          type: NodeTypes.SIMPLE_EXPRESSION,
-          isStatic: !/^\[/.test(key),
-          content: key.replace(/^\[|\]$/g, '')
-        },
-        value: obj[key]
-      }
-    })
+    properties: Object.keys(obj)
+      .map(key => {
+        return {
+          type: NodeTypes.JS_PROPERTY,
+          key: {
+            type: NodeTypes.SIMPLE_EXPRESSION,
+            isStatic: !/^\[/.test(key),
+            content: key.replace(/^\[|\]$/g, '')
+          },
+          value: obj[key]
+        } as any
+      })
+      .concat({
+        key: { content: `_compiled` },
+        value: { content: `true` }
+      })
   }
 }
 
@@ -330,7 +335,9 @@ describe('compiler: transform component slots', () => {
       type: NodeTypes.JS_CALL_EXPRESSION,
       callee: `_${CREATE_SLOTS}`,
       arguments: [
-        createObjectMatcher({}),
+        createObjectMatcher({
+          _compiled: `[true]`
+        }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
           elements: [
@@ -370,7 +377,9 @@ describe('compiler: transform component slots', () => {
       type: NodeTypes.JS_CALL_EXPRESSION,
       callee: CREATE_SLOTS,
       arguments: [
-        createObjectMatcher({}),
+        createObjectMatcher({
+          _compiled: `[true]`
+        }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
           elements: [
@@ -417,7 +426,9 @@ describe('compiler: transform component slots', () => {
       type: NodeTypes.JS_CALL_EXPRESSION,
       callee: `_${CREATE_SLOTS}`,
       arguments: [
-        createObjectMatcher({}),
+        createObjectMatcher({
+          _compiled: `[true]`
+        }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
           elements: [
@@ -474,7 +485,9 @@ describe('compiler: transform component slots', () => {
       type: NodeTypes.JS_CALL_EXPRESSION,
       callee: CREATE_SLOTS,
       arguments: [
-        createObjectMatcher({}),
+        createObjectMatcher({
+          _compiled: `[true]`
+        }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
           elements: [
index 29286042e772160ae141202b671f18e36af5850b..f68d08df289ba36e3778a4b23d14f8e2d60a889e 100644 (file)
@@ -264,7 +264,9 @@ export function buildSlots(
   }
 
   let slots: ObjectExpression | CallExpression = createObjectExpression(
-    slotsProperties,
+    slotsProperties.concat(
+      createObjectProperty(`_compiled`, createSimpleExpression(`true`, false))
+    ),
     loc
   )
   if (dynamicSlots.length) {
index 67858ee33961e537894476bdbc230da24fcc7bde..534caed5f2877b8d1f74e325e07d834249d7d5e0 100644 (file)
@@ -42,7 +42,7 @@ export function resolveSlots(
 ) {
   let slots: Slots | void
   if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
-    if ((children as any)._normalized) {
+    if ((children as any)._compiled) {
       // pre-normalized slots object generated by compiler
       slots = children as Slots
     } else {