]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-core): use more concise marker for compiled slots
authorEvan You <yyx990803@gmail.com>
Wed, 12 Feb 2020 18:45:35 +0000 (13:45 -0500)
committerEvan You <yyx990803@gmail.com>
Wed, 12 Feb 2020 18:45:35 +0000 (13:45 -0500)
packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap
packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap
packages/compiler-core/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap
packages/compiler-core/__tests__/transforms/transformElement.spec.ts
packages/compiler-core/__tests__/transforms/vSlot.spec.ts
packages/compiler-core/src/transforms/vSlot.ts
packages/compiler-ssr/__tests__/ssrComponent.spec.ts
packages/compiler-ssr/__tests__/ssrScopeId.spec.ts
packages/runtime-core/src/componentSlots.ts
packages/runtime-core/src/helpers/renderSlot.ts
packages/server-renderer/__tests__/renderToString.spec.ts

index 223e7538a8014d9ba10ac8cf394e9c8f7cdaa907..8a1497853f0aeb8c6ed52740edb1880805b53757 100644 (file)
@@ -29,7 +29,7 @@ export const render = _withId(function render(_ctx, _cache) {
     default: _withId(() => [
       _createVNode(\\"div\\")
     ]),
-    _compiled: true
+    _: 1
   }))
 })"
 `;
@@ -41,7 +41,7 @@ const _withId = _withScopeId(\\"test\\")
 export const render = _withId(function render(_ctx, _cache) {
   const _component_Child = _resolveComponent(\\"Child\\")
 
-  return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _compiled: true }, [
+  return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 1 }, [
     (_ctx.ok)
       ? {
           name: \\"foo\\",
@@ -76,7 +76,7 @@ export const render = _withId(function render(_ctx, _cache) {
     bar: _withId(() => [
       _createVNode(\\"div\\")
     ]),
-    _compiled: true
+    _: 1
   }))
 })"
 `;
index a6604643684484f021916d0496d2df1284d3396d..1667d09ee33dccb8f9f215876c5dcfd2a202e6d8 100644 (file)
@@ -247,7 +247,7 @@ return function render(_ctx, _cache) {
       default: ({ foo }) => [
         _createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */)
       ],
-      _compiled: true
+      _: 1
     }))
   }
 }"
index 468be39314db385973981e3d544f556f44922403..ab00e2ec9e2f1cc206ff20e165b2208f87c4da54 100644 (file)
@@ -9,7 +9,7 @@ return function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Comp, null, {
     [_ctx.one]: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
     [_ctx.two]: ({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)],
-    _compiled: true
+    _: 1
   }, 512 /* DYNAMIC_SLOTS */))
 }"
 `;
@@ -24,7 +24,7 @@ return function render(_ctx, _cache) {
     default: () => [
       _createVNode(\\"div\\")
     ],
-    _compiled: true
+    _: 1
   }))
 }"
 `;
@@ -35,7 +35,7 @@ exports[`compiler: transform component slots named slot with v-for w/ prefixIden
 return function render(_ctx, _cache) {
   const _component_Comp = _resolveComponent(\\"Comp\\")
 
-  return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
+  return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
     _renderList(_ctx.list, (name) => {
       return {
         name: name,
@@ -52,7 +52,7 @@ exports[`compiler: transform component slots named slot with v-if + prefixIdenti
 return function render(_ctx, _cache) {
   const _component_Comp = _resolveComponent(\\"Comp\\")
 
-  return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
+  return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
     (_ctx.ok)
       ? {
           name: \\"one\\",
@@ -72,7 +72,7 @@ return function render(_ctx, _cache) {
 
     const _component_Comp = _resolveComponent(\\"Comp\\")
 
-    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
+    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
       ok
         ? {
             name: \\"one\\",
@@ -101,7 +101,7 @@ return function render(_ctx, _cache) {
 
     const _component_Comp = _resolveComponent(\\"Comp\\")
 
-    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _compiled: true }, [
+    return (_openBlock(), _createBlock(_component_Comp, null, _createSlots({ _: 1 }, [
       ok
         ? {
             name: \\"one\\",
@@ -122,7 +122,7 @@ return function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Comp, null, {
     one: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
     two: ({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)],
-    _compiled: true
+    _: 1
   }))
 }"
 `;
@@ -142,7 +142,7 @@ return function render(_ctx, _cache) {
         \\"bar\\",
         _createVNode(\\"span\\")
       ],
-      _compiled: true
+      _: 1
     }))
   }
 }"
@@ -159,14 +159,14 @@ return function render(_ctx, _cache) {
     default: ({ foo }) => [
       _createVNode(_component_Inner, null, {
         default: ({ bar }) => [_toDisplayString(foo), _toDisplayString(bar), _toDisplayString(_ctx.baz)],
-        _compiled: true
+        _: 1
       }, 512 /* DYNAMIC_SLOTS */),
       \\" \\",
       _toDisplayString(foo),
       _toDisplayString(_ctx.bar),
       _toDisplayString(_ctx.baz)
     ],
-    _compiled: true
+    _: 1
   }))
 }"
 `;
@@ -179,7 +179,7 @@ return function render(_ctx, _cache) {
 
   return (_openBlock(), _createBlock(_component_Comp, null, {
     default: ({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)],
-    _compiled: true
+    _: 1
   }))
 }"
 `;
index 64f215ff42d67f4d8f39428ee51e53eff818769d..a7301c2dcd0db9eaae3def8116379218400cc83c 100644 (file)
@@ -321,13 +321,13 @@ describe('compiler: element transform', () => {
               fallback: {
                 type: NodeTypes.JS_FUNCTION_EXPRESSION
               },
-              _compiled: `[true]`
+              _: `[1]`
             })
           : createObjectMatcher({
               default: {
                 type: NodeTypes.JS_FUNCTION_EXPRESSION
               },
-              _compiled: `[true]`
+              _: `[1]`
             })
       })
     }
@@ -381,7 +381,7 @@ describe('compiler: element transform', () => {
           default: {
             type: NodeTypes.JS_FUNCTION_EXPRESSION
           },
-          _compiled: `[true]`
+          _: `[1]`
         })
       })
     }
index 3d8f1968e93fb2b5e64cb0063a5d31daf0d44f77..c6c9c8324ea29b302ec82a4ab7abee329e232d7a 100644 (file)
@@ -69,8 +69,8 @@ function createSlotMatcher(obj: Record<string, any>) {
         } as any
       })
       .concat({
-        key: { content: `_compiled` },
-        value: { content: `true` }
+        key: { content: `_` },
+        value: { content: `1`, isStatic: false }
       })
   }
 }
@@ -456,7 +456,7 @@ describe('compiler: transform component slots', () => {
       callee: CREATE_SLOTS,
       arguments: [
         createObjectMatcher({
-          _compiled: `[true]`
+          _: `[1]`
         }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
@@ -498,7 +498,7 @@ describe('compiler: transform component slots', () => {
       callee: CREATE_SLOTS,
       arguments: [
         createObjectMatcher({
-          _compiled: `[true]`
+          _: `[1]`
         }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
@@ -547,7 +547,7 @@ describe('compiler: transform component slots', () => {
       callee: CREATE_SLOTS,
       arguments: [
         createObjectMatcher({
-          _compiled: `[true]`
+          _: `[1]`
         }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
@@ -606,7 +606,7 @@ describe('compiler: transform component slots', () => {
       callee: CREATE_SLOTS,
       arguments: [
         createObjectMatcher({
-          _compiled: `[true]`
+          _: `[1]`
         }),
         {
           type: NodeTypes.JS_ARRAY_EXPRESSION,
index 00a9b40056ce77fa9b72e3c40ad181089d631c97..0207cd7c25c3d353d6d035d282c79f2904df3525 100644 (file)
@@ -315,7 +315,7 @@ export function buildSlots(
 
   let slots = createObjectExpression(
     slotsProperties.concat(
-      createObjectProperty(`_compiled`, createSimpleExpression(`true`, false))
+      createObjectProperty(`_`, createSimpleExpression(`1`, false))
     ),
     loc
   ) as SlotsExpression
index 2df79c4e0ee806dcdf798806623a61cc1af7a529..0cca3cefee215e09ed95eac7f30fc7b3ceed3f73 100644 (file)
@@ -61,7 +61,7 @@ describe('ssr: components', () => {
                 ]
               }
             },
-            _compiled: true
+            _: 1
           }, _parent))
         }"
       `)
@@ -86,7 +86,7 @@ describe('ssr: components', () => {
                 ]
               }
             },
-            _compiled: true
+            _: 1
           }, _parent))
         }"
       `)
@@ -124,7 +124,7 @@ describe('ssr: components', () => {
                 ]
               }
             },
-            _compiled: true
+            _: 1
           }, _parent))
         }"
       `)
@@ -142,7 +142,7 @@ describe('ssr: components', () => {
         return function ssrRender(_ctx, _push, _parent) {
           const _component_foo = _resolveComponent(\\"foo\\")
 
-          _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _compiled: true }, [
+          _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [
             (_ctx.ok)
               ? {
                   name: \\"named\\",
@@ -174,7 +174,7 @@ describe('ssr: components', () => {
         return function ssrRender(_ctx, _push, _parent) {
           const _component_foo = _resolveComponent(\\"foo\\")
 
-          _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _compiled: true }, [
+          _push(_ssrRenderComponent(_component_foo, null, _createSlots({ _: 1 }, [
             _renderList(_ctx.names, (key) => {
               return {
                 name: key,
@@ -262,7 +262,7 @@ describe('ssr: components', () => {
                 ]
               }
             },
-            _compiled: true
+            _: 1
           }, _parent))
         }"
       `)
index 8aae0ee85d6c03530ce55be99e6543e056683834..8cb8c1ec6689bdb244eb048ac1ffb85416eaad43 100644 (file)
@@ -39,7 +39,7 @@ describe('ssr: scopeId', () => {
               ]
             }
           },
-          _compiled: true
+          _: 1
         }, _parent))
       }"
     `)
@@ -67,7 +67,7 @@ describe('ssr: scopeId', () => {
               ]
             }
           },
-          _compiled: true
+          _: 1
         }, _parent))
       }"
     `)
@@ -100,7 +100,7 @@ describe('ssr: scopeId', () => {
                     ]
                   }
                 },
-                _compiled: true
+                _: 1
               }, _parent))
             } else {
               return [
@@ -109,12 +109,12 @@ describe('ssr: scopeId', () => {
                   default: () => [
                     _createVNode(\\"span\\")
                   ],
-                  _compiled: true
+                  _: 1
                 })
               ]
             }
           },
-          _compiled: true
+          _: 1
         }, _parent))
       }"
     `)
index ccac9f938f95bffb804561f5cf04aee1f8bff97a..4f7e82a53f75e680d761ff419e8f3c85d71f9540 100644 (file)
@@ -23,7 +23,7 @@ export type RawSlots = {
   // manual render fn hint to skip forced children updates
   $stable?: boolean
   // internal, indicates compiler generated slots = can skip normalization
-  _compiled?: boolean
+  _?: 1
 }
 
 const normalizeSlotValue = (value: unknown): VNode[] =>
@@ -51,7 +51,7 @@ export function resolveSlots(
   let slots: InternalSlots | void
   if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
     const rawSlots = children as RawSlots
-    if (rawSlots._compiled) {
+    if (rawSlots._ === 1) {
       // pre-normalized slots object generated by compiler
       slots = children as Slots
     } else {
index 32d89268c0c50abd9f2b646d1b40c94ee8bf0f6c..eb16bc02200a3e28789feeabe21e5392250e032e 100644 (file)
@@ -35,7 +35,7 @@ export function renderSlot(
       Fragment,
       { key: props.key },
       slot ? slot(props) : fallback || [],
-      slots._compiled ? 0 : PatchFlags.BAIL
+      slots._ ? 0 : PatchFlags.BAIL
     )
   )
 }
index 051f59b4f030a63b32c632a3e951ccc61b8a0b53..eb27c4b08be5d66cdaadc67e95f4cbd0cface972 100644 (file)
@@ -218,7 +218,7 @@ describe('ssr: renderToString', () => {
                       push(`<span>${msg}</span>`)
                     },
                     // important to avoid slots being normalized
-                    _compiled: true as any
+                    _: 1 as any
                   },
                   parent
                 )