]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: simplify and use correct ctx in withCtx
authorEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 17:06:37 +0000 (13:06 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 17:06:46 +0000 (13:06 -0400)
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/src/codegen.ts
packages/compiler-ssr/__tests__/ssrComponent.spec.ts
packages/compiler-ssr/__tests__/ssrScopeId.spec.ts
packages/runtime-core/src/helpers/scopeId.ts
packages/runtime-core/src/helpers/withRenderContext.ts

index 84f84e43848b86521d5e40da3dca14ed579c2f70..03ce987117be7475e92b2fd737390f2a6187da8c 100644 (file)
@@ -28,7 +28,7 @@ export const render = _withId(function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Child, null, {
     default: _withId(() => [
       _createVNode(\\"div\\")
-    ], _ctx),
+    ]),
     _: 1
   }))
 })"
@@ -47,7 +47,7 @@ export const render = _withId(function render(_ctx, _cache) {
           name: \\"foo\\",
           fn: _withId(() => [
             _createVNode(\\"div\\")
-          ], _ctx)
+          ])
         }
       : undefined,
     _renderList(_ctx.list, (i) => {
@@ -55,7 +55,7 @@ export const render = _withId(function render(_ctx, _cache) {
         name: i,
         fn: _withId(() => [
           _createVNode(\\"div\\")
-        ], _ctx)
+        ])
       }
     })
   ]), 1024 /* DYNAMIC_SLOTS */))
@@ -72,10 +72,10 @@ export const render = _withId(function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Child, null, {
     foo: _withId(({ msg }) => [
       _createTextVNode(_toDisplayString(msg), 1 /* TEXT */)
-    ], _ctx),
+    ]),
     bar: _withId(() => [
       _createVNode(\\"div\\")
-    ], _ctx),
+    ]),
     _: 1
   }))
 })"
index a7fdc60aa3143894b5e974c81f47721528370773..de021a5e25a6e71708fd165ff2d6deafb4a8d66c 100644 (file)
@@ -246,7 +246,7 @@ return function render(_ctx, _cache) {
     return (_openBlock(), _createBlock(_component_Comp, null, {
       default: _withCtx(({ foo }) => [
         _createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */)
-      ], _ctx),
+      ]),
       _: 1
     }))
   }
index a1bdf0747e7e4f429e20b2d912cbb151fb406a9f..e6d0e11d5e4bd5421bdde434359b55df1e490e37 100644 (file)
@@ -7,8 +7,8 @@ return function render(_ctx, _cache) {
   const _component_Comp = _resolveComponent(\\"Comp\\")
 
   return (_openBlock(), _createBlock(_component_Comp, null, {
-    [_ctx.one]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx),
-    [_ctx.two]: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)], _ctx),
+    [_ctx.one]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
+    [_ctx.two]: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]),
     _: 1
   }, 1024 /* DYNAMIC_SLOTS */))
 }"
@@ -23,7 +23,7 @@ return function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Comp, null, {
     default: _withCtx(() => [
       _createVNode(\\"div\\")
-    ], _ctx),
+    ]),
     _: 1
   }))
 }"
@@ -39,7 +39,7 @@ return function render(_ctx, _cache) {
     _renderList(_ctx.list, (name) => {
       return {
         name: name,
-        fn: _withCtx(() => [_toDisplayString(name)], _ctx)
+        fn: _withCtx(() => [_toDisplayString(name)])
       }
     })
   ]), 1024 /* DYNAMIC_SLOTS */))
@@ -56,7 +56,7 @@ return function render(_ctx, _cache) {
     (_ctx.ok)
       ? {
           name: \\"one\\",
-          fn: _withCtx((props) => [_toDisplayString(props)], _ctx)
+          fn: _withCtx((props) => [_toDisplayString(props)])
         }
       : undefined
   ]), 1024 /* DYNAMIC_SLOTS */))
@@ -76,16 +76,16 @@ return function render(_ctx, _cache) {
       ok
         ? {
             name: \\"one\\",
-            fn: _withCtx(() => [\\"foo\\"], _ctx)
+            fn: _withCtx(() => [\\"foo\\"])
           }
         : orNot
           ? {
               name: \\"two\\",
-              fn: _withCtx((props) => [\\"bar\\"], _ctx)
+              fn: _withCtx((props) => [\\"bar\\"])
             }
           : {
               name: \\"one\\",
-              fn: _withCtx(() => [\\"baz\\"], _ctx)
+              fn: _withCtx(() => [\\"baz\\"])
             }
     ]), 1024 /* DYNAMIC_SLOTS */))
   }
@@ -105,7 +105,7 @@ return function render(_ctx, _cache) {
       ok
         ? {
             name: \\"one\\",
-            fn: _withCtx(() => [\\"hello\\"], _ctx)
+            fn: _withCtx(() => [\\"hello\\"])
           }
         : undefined
     ]), 1024 /* DYNAMIC_SLOTS */))
@@ -120,8 +120,8 @@ return function render(_ctx, _cache) {
   const _component_Comp = _resolveComponent(\\"Comp\\")
 
   return (_openBlock(), _createBlock(_component_Comp, null, {
-    one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx),
-    two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)], _ctx),
+    one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
+    two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]),
     _: 1
   }))
 }"
@@ -137,11 +137,11 @@ return function render(_ctx, _cache) {
     const _component_Comp = _resolveComponent(\\"Comp\\")
 
     return (_openBlock(), _createBlock(_component_Comp, null, {
-      one: _withCtx(() => [\\"foo\\"], _ctx),
+      one: _withCtx(() => [\\"foo\\"]),
       default: _withCtx(() => [
         \\"bar\\",
         _createVNode(\\"span\\")
-      ], _ctx),
+      ]),
       _: 1
     }))
   }
@@ -158,14 +158,14 @@ return function render(_ctx, _cache) {
   return (_openBlock(), _createBlock(_component_Comp, null, {
     default: _withCtx(({ foo }) => [
       _createVNode(_component_Inner, null, {
-        default: _withCtx(({ bar }) => [_toDisplayString(foo), _toDisplayString(bar), _toDisplayString(_ctx.baz)], _ctx),
+        default: _withCtx(({ bar }) => [_toDisplayString(foo), _toDisplayString(bar), _toDisplayString(_ctx.baz)]),
         _: 1
       }, 1024 /* DYNAMIC_SLOTS */),
       \\" \\",
       _toDisplayString(foo),
       _toDisplayString(_ctx.bar),
       _toDisplayString(_ctx.baz)
-    ], _ctx),
+    ]),
     _: 1
   }))
 }"
@@ -178,7 +178,7 @@ return function render(_ctx, _cache) {
   const _component_Comp = _resolveComponent(\\"Comp\\")
 
   return (_openBlock(), _createBlock(_component_Comp, null, {
-    default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx),
+    default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
     _: 1
   }))
 }"
index b83d2f3fbf8f44e26299fbb8e1692dc2700bc73b..de697a20122708061a8c58f9f74588d3eadcfa2f 100644 (file)
@@ -49,7 +49,8 @@ import {
   WITH_DIRECTIVES,
   CREATE_BLOCK,
   OPEN_BLOCK,
-  CREATE_STATIC
+  CREATE_STATIC,
+  WITH_CTX
 } from './runtimeHelpers'
 import { ImportItem } from './transform'
 
@@ -769,7 +770,7 @@ function genFunctionExpression(
   if (genScopeId) {
     push(`_withId(`)
   } else if (isSlot) {
-    push(`_withCtx(`)
+    push(`_${helperNameMap[WITH_CTX]}(`)
   }
   push(`(`, node)
   if (isArray(params)) {
@@ -799,7 +800,7 @@ function genFunctionExpression(
     push(`}`)
   }
   if (genScopeId || isSlot) {
-    push(`, _ctx)`)
+    push(`)`)
   }
 }
 
index c4b28dbccbf7ab53d6f9a0429422f61c9e02531f..8abae35d321ee5d6658eb8fabb1c624d220a0a78 100644 (file)
@@ -60,7 +60,7 @@ describe('ssr: components', () => {
                   _createVNode(\\"div\\")
                 ]
               }
-            }, _ctx),
+            }),
             _: 1
           }, _parent))
         }"
@@ -85,7 +85,7 @@ describe('ssr: components', () => {
                   _createTextVNode(_toDisplayString(msg + _ctx.outer), 1 /* TEXT */)
                 ]
               }
-            }, _ctx),
+            }),
             _: 1
           }, _parent))
         }"
@@ -114,7 +114,7 @@ describe('ssr: components', () => {
                   _createTextVNode(\\"foo\\")
                 ]
               }
-            }, _ctx),
+            }),
             named: _withCtx((_, _push, _parent, _scopeId) => {
               if (_push) {
                 _push(\`bar\`)
@@ -123,7 +123,7 @@ describe('ssr: components', () => {
                   _createTextVNode(\\"bar\\")
                 ]
               }
-            }, _ctx),
+            }),
             _: 1
           }, _parent))
         }"
@@ -154,7 +154,7 @@ describe('ssr: components', () => {
                         _createTextVNode(\\"foo\\")
                       ]
                     }
-                  }, _ctx)
+                  })
                 }
               : undefined
           ]), _parent))
@@ -186,7 +186,7 @@ describe('ssr: components', () => {
                       _createTextVNode(_toDisplayString(msg + _ctx.key + _ctx.bar), 1 /* TEXT */)
                     ]
                   }
-                }, _ctx)
+                })
               }
             })
           ]), _parent))
@@ -238,7 +238,7 @@ describe('ssr: components', () => {
                     : _createCommentVNode(\\"v-if\\", true)
                 ]
               }
-            }, _ctx),
+            }),
             bar: _withCtx(({ ok }, _push, _parent, _scopeId) => {
               if (_push) {
                 if (ok) {
@@ -261,7 +261,7 @@ describe('ssr: components', () => {
                     : _createCommentVNode(\\"v-if\\", true)
                 ]
               }
-            }, _ctx),
+            }),
             _: 1
           }, _parent))
         }"
index fe9671b805758ae424b5263caef87f6016ab1998..64bb12f116a5c1159293bc46c23bb7bb267636b9 100644 (file)
@@ -38,7 +38,7 @@ describe('ssr: scopeId', () => {
                 _createTextVNode(\\"foo\\")
               ]
             }
-          }, _ctx),
+          }),
           _: 1
         }, _parent))
       }"
@@ -66,7 +66,7 @@ describe('ssr: scopeId', () => {
                 _createVNode(\\"span\\", null, \\"hello\\")
               ]
             }
-          }, _ctx),
+          }),
           _: 1
         }, _parent))
       }"
@@ -99,7 +99,7 @@ describe('ssr: scopeId', () => {
                       _createVNode(\\"span\\")
                     ]
                   }
-                }, _ctx),
+                }),
                 _: 1
               }, _parent))
             } else {
@@ -108,12 +108,12 @@ describe('ssr: scopeId', () => {
                 _createVNode(_component_bar, null, {
                   default: _withCtx(() => [
                     _createVNode(\\"span\\")
-                  ], _ctx),
+                  ]),
                   _: 1
                 })
               ]
             }
-          }, _ctx),
+          }),
           _: 1
         }, _parent))
       }"
index 0cc88046f32d5633d69f1db6ae59dbed39b353cf..b63f0e7b96c2ad3e0e51550a4bf67a47c8621248 100644 (file)
@@ -2,7 +2,6 @@
 // These are only used in esm-bundler builds, but since exports cannot be
 // conditional, we can only drop inner implementations in non-bundler builds.
 
-import { ComponentInternalInstance } from '../component'
 import { withCtx } from './withRenderContext'
 
 export let currentScopeId: string | null = null
@@ -23,14 +22,13 @@ export function popScopeId() {
 
 export function withScopeId(id: string): <T extends Function>(fn: T) => T {
   if (__BUNDLER__) {
-    return ((fn: Function, ctx?: ComponentInternalInstance) => {
-      return withCtx(function(this: any) {
+    return ((fn: Function) =>
+      withCtx(function(this: any) {
         pushScopeId(id)
         const res = fn.apply(this, arguments)
         popScopeId()
         return res
-      }, ctx)
-    }) as any
+      })) as any
   } else {
     return undefined as any
   }
index b3642a1f84052c603b224b9da3250a5038942784..59c686b1b9e618a3258f672f4a31f4ab38d2985a 100644 (file)
@@ -1,13 +1,13 @@
 import { Slot } from '../componentSlots'
-import { ComponentInternalInstance } from '../component'
 import {
   setCurrentRenderingInstance,
   currentRenderingInstance
 } from '../componentRenderUtils'
+import { ComponentInternalInstance } from '../component'
 
 export function withCtx(
   fn: Slot,
-  ctx: ComponentInternalInstance | null | undefined
+  ctx: ComponentInternalInstance | null = currentRenderingInstance
 ) {
   if (!ctx) return fn
   return function renderFnWithContext() {