fix: simplify and use correct ctx in withCtx
This commit is contained in:
		
							parent
							
								
									fd3418d79d
								
							
						
					
					
						commit
						4dc8ffc378
					
				| @ -28,7 +28,7 @@ export const render = _withId(function render(_ctx, _cache) { | |||||||
|   return (_openBlock(), _createBlock(_component_Child, null, { |   return (_openBlock(), _createBlock(_component_Child, null, { | ||||||
|     default: _withId(() => [ |     default: _withId(() => [ | ||||||
|       _createVNode(\\"div\\") |       _createVNode(\\"div\\") | ||||||
|     ], _ctx), |     ]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| })" | })" | ||||||
| @ -47,7 +47,7 @@ export const render = _withId(function render(_ctx, _cache) { | |||||||
|           name: \\"foo\\", |           name: \\"foo\\", | ||||||
|           fn: _withId(() => [ |           fn: _withId(() => [ | ||||||
|             _createVNode(\\"div\\") |             _createVNode(\\"div\\") | ||||||
|           ], _ctx) |           ]) | ||||||
|         } |         } | ||||||
|       : undefined, |       : undefined, | ||||||
|     _renderList(_ctx.list, (i) => { |     _renderList(_ctx.list, (i) => { | ||||||
| @ -55,7 +55,7 @@ export const render = _withId(function render(_ctx, _cache) { | |||||||
|         name: i, |         name: i, | ||||||
|         fn: _withId(() => [ |         fn: _withId(() => [ | ||||||
|           _createVNode(\\"div\\") |           _createVNode(\\"div\\") | ||||||
|         ], _ctx) |         ]) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|   ]), 1024 /* DYNAMIC_SLOTS */)) |   ]), 1024 /* DYNAMIC_SLOTS */)) | ||||||
| @ -72,10 +72,10 @@ export const render = _withId(function render(_ctx, _cache) { | |||||||
|   return (_openBlock(), _createBlock(_component_Child, null, { |   return (_openBlock(), _createBlock(_component_Child, null, { | ||||||
|     foo: _withId(({ msg }) => [ |     foo: _withId(({ msg }) => [ | ||||||
|       _createTextVNode(_toDisplayString(msg), 1 /* TEXT */) |       _createTextVNode(_toDisplayString(msg), 1 /* TEXT */) | ||||||
|     ], _ctx), |     ]), | ||||||
|     bar: _withId(() => [ |     bar: _withId(() => [ | ||||||
|       _createVNode(\\"div\\") |       _createVNode(\\"div\\") | ||||||
|     ], _ctx), |     ]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| })" | })" | ||||||
|  | |||||||
| @ -246,7 +246,7 @@ return function render(_ctx, _cache) { | |||||||
|     return (_openBlock(), _createBlock(_component_Comp, null, { |     return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|       default: _withCtx(({ foo }) => [ |       default: _withCtx(({ foo }) => [ | ||||||
|         _createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */) |         _createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */) | ||||||
|       ], _ctx), |       ]), | ||||||
|       _: 1 |       _: 1 | ||||||
|     })) |     })) | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -7,8 +7,8 @@ return function render(_ctx, _cache) { | |||||||
|   const _component_Comp = _resolveComponent(\\"Comp\\") |   const _component_Comp = _resolveComponent(\\"Comp\\") | ||||||
| 
 | 
 | ||||||
|   return (_openBlock(), _createBlock(_component_Comp, null, { |   return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|     [_ctx.one]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx), |     [_ctx.one]: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]), | ||||||
|     [_ctx.two]: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)], _ctx), |     [_ctx.two]: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   }, 1024 /* DYNAMIC_SLOTS */)) |   }, 1024 /* DYNAMIC_SLOTS */)) | ||||||
| }" | }" | ||||||
| @ -23,7 +23,7 @@ return function render(_ctx, _cache) { | |||||||
|   return (_openBlock(), _createBlock(_component_Comp, null, { |   return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|     default: _withCtx(() => [ |     default: _withCtx(() => [ | ||||||
|       _createVNode(\\"div\\") |       _createVNode(\\"div\\") | ||||||
|     ], _ctx), |     ]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| }" | }" | ||||||
| @ -39,7 +39,7 @@ return function render(_ctx, _cache) { | |||||||
|     _renderList(_ctx.list, (name) => { |     _renderList(_ctx.list, (name) => { | ||||||
|       return { |       return { | ||||||
|         name: name, |         name: name, | ||||||
|         fn: _withCtx(() => [_toDisplayString(name)], _ctx) |         fn: _withCtx(() => [_toDisplayString(name)]) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|   ]), 1024 /* DYNAMIC_SLOTS */)) |   ]), 1024 /* DYNAMIC_SLOTS */)) | ||||||
| @ -56,7 +56,7 @@ return function render(_ctx, _cache) { | |||||||
|     (_ctx.ok) |     (_ctx.ok) | ||||||
|       ? { |       ? { | ||||||
|           name: \\"one\\", |           name: \\"one\\", | ||||||
|           fn: _withCtx((props) => [_toDisplayString(props)], _ctx) |           fn: _withCtx((props) => [_toDisplayString(props)]) | ||||||
|         } |         } | ||||||
|       : undefined |       : undefined | ||||||
|   ]), 1024 /* DYNAMIC_SLOTS */)) |   ]), 1024 /* DYNAMIC_SLOTS */)) | ||||||
| @ -76,16 +76,16 @@ return function render(_ctx, _cache) { | |||||||
|       ok |       ok | ||||||
|         ? { |         ? { | ||||||
|             name: \\"one\\", |             name: \\"one\\", | ||||||
|             fn: _withCtx(() => [\\"foo\\"], _ctx) |             fn: _withCtx(() => [\\"foo\\"]) | ||||||
|           } |           } | ||||||
|         : orNot |         : orNot | ||||||
|           ? { |           ? { | ||||||
|               name: \\"two\\", |               name: \\"two\\", | ||||||
|               fn: _withCtx((props) => [\\"bar\\"], _ctx) |               fn: _withCtx((props) => [\\"bar\\"]) | ||||||
|             } |             } | ||||||
|           : { |           : { | ||||||
|               name: \\"one\\", |               name: \\"one\\", | ||||||
|               fn: _withCtx(() => [\\"baz\\"], _ctx) |               fn: _withCtx(() => [\\"baz\\"]) | ||||||
|             } |             } | ||||||
|     ]), 1024 /* DYNAMIC_SLOTS */)) |     ]), 1024 /* DYNAMIC_SLOTS */)) | ||||||
|   } |   } | ||||||
| @ -105,7 +105,7 @@ return function render(_ctx, _cache) { | |||||||
|       ok |       ok | ||||||
|         ? { |         ? { | ||||||
|             name: \\"one\\", |             name: \\"one\\", | ||||||
|             fn: _withCtx(() => [\\"hello\\"], _ctx) |             fn: _withCtx(() => [\\"hello\\"]) | ||||||
|           } |           } | ||||||
|         : undefined |         : undefined | ||||||
|     ]), 1024 /* DYNAMIC_SLOTS */)) |     ]), 1024 /* DYNAMIC_SLOTS */)) | ||||||
| @ -120,8 +120,8 @@ return function render(_ctx, _cache) { | |||||||
|   const _component_Comp = _resolveComponent(\\"Comp\\") |   const _component_Comp = _resolveComponent(\\"Comp\\") | ||||||
| 
 | 
 | ||||||
|   return (_openBlock(), _createBlock(_component_Comp, null, { |   return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|     one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx), |     one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]), | ||||||
|     two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)], _ctx), |     two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| }" | }" | ||||||
| @ -137,11 +137,11 @@ return function render(_ctx, _cache) { | |||||||
|     const _component_Comp = _resolveComponent(\\"Comp\\") |     const _component_Comp = _resolveComponent(\\"Comp\\") | ||||||
| 
 | 
 | ||||||
|     return (_openBlock(), _createBlock(_component_Comp, null, { |     return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|       one: _withCtx(() => [\\"foo\\"], _ctx), |       one: _withCtx(() => [\\"foo\\"]), | ||||||
|       default: _withCtx(() => [ |       default: _withCtx(() => [ | ||||||
|         \\"bar\\", |         \\"bar\\", | ||||||
|         _createVNode(\\"span\\") |         _createVNode(\\"span\\") | ||||||
|       ], _ctx), |       ]), | ||||||
|       _: 1 |       _: 1 | ||||||
|     })) |     })) | ||||||
|   } |   } | ||||||
| @ -158,14 +158,14 @@ return function render(_ctx, _cache) { | |||||||
|   return (_openBlock(), _createBlock(_component_Comp, null, { |   return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|     default: _withCtx(({ foo }) => [ |     default: _withCtx(({ foo }) => [ | ||||||
|       _createVNode(_component_Inner, null, { |       _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 |         _: 1 | ||||||
|       }, 1024 /* DYNAMIC_SLOTS */), |       }, 1024 /* DYNAMIC_SLOTS */), | ||||||
|       \\" \\", |       \\" \\", | ||||||
|       _toDisplayString(foo), |       _toDisplayString(foo), | ||||||
|       _toDisplayString(_ctx.bar), |       _toDisplayString(_ctx.bar), | ||||||
|       _toDisplayString(_ctx.baz) |       _toDisplayString(_ctx.baz) | ||||||
|     ], _ctx), |     ]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| }" | }" | ||||||
| @ -178,7 +178,7 @@ return function render(_ctx, _cache) { | |||||||
|   const _component_Comp = _resolveComponent(\\"Comp\\") |   const _component_Comp = _resolveComponent(\\"Comp\\") | ||||||
| 
 | 
 | ||||||
|   return (_openBlock(), _createBlock(_component_Comp, null, { |   return (_openBlock(), _createBlock(_component_Comp, null, { | ||||||
|     default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)], _ctx), |     default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]), | ||||||
|     _: 1 |     _: 1 | ||||||
|   })) |   })) | ||||||
| }" | }" | ||||||
|  | |||||||
| @ -49,7 +49,8 @@ import { | |||||||
|   WITH_DIRECTIVES, |   WITH_DIRECTIVES, | ||||||
|   CREATE_BLOCK, |   CREATE_BLOCK, | ||||||
|   OPEN_BLOCK, |   OPEN_BLOCK, | ||||||
|   CREATE_STATIC |   CREATE_STATIC, | ||||||
|  |   WITH_CTX | ||||||
| } from './runtimeHelpers' | } from './runtimeHelpers' | ||||||
| import { ImportItem } from './transform' | import { ImportItem } from './transform' | ||||||
| 
 | 
 | ||||||
| @ -769,7 +770,7 @@ function genFunctionExpression( | |||||||
|   if (genScopeId) { |   if (genScopeId) { | ||||||
|     push(`_withId(`) |     push(`_withId(`) | ||||||
|   } else if (isSlot) { |   } else if (isSlot) { | ||||||
|     push(`_withCtx(`) |     push(`_${helperNameMap[WITH_CTX]}(`) | ||||||
|   } |   } | ||||||
|   push(`(`, node) |   push(`(`, node) | ||||||
|   if (isArray(params)) { |   if (isArray(params)) { | ||||||
| @ -799,7 +800,7 @@ function genFunctionExpression( | |||||||
|     push(`}`) |     push(`}`) | ||||||
|   } |   } | ||||||
|   if (genScopeId || isSlot) { |   if (genScopeId || isSlot) { | ||||||
|     push(`, _ctx)`) |     push(`)`) | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -60,7 +60,7 @@ describe('ssr: components', () => { | |||||||
|                   _createVNode(\\"div\\") |                   _createVNode(\\"div\\") | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             _: 1 |             _: 1 | ||||||
|           }, _parent)) |           }, _parent)) | ||||||
|         }" |         }" | ||||||
| @ -85,7 +85,7 @@ describe('ssr: components', () => { | |||||||
|                   _createTextVNode(_toDisplayString(msg + _ctx.outer), 1 /* TEXT */) |                   _createTextVNode(_toDisplayString(msg + _ctx.outer), 1 /* TEXT */) | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             _: 1 |             _: 1 | ||||||
|           }, _parent)) |           }, _parent)) | ||||||
|         }" |         }" | ||||||
| @ -114,7 +114,7 @@ describe('ssr: components', () => { | |||||||
|                   _createTextVNode(\\"foo\\") |                   _createTextVNode(\\"foo\\") | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             named: _withCtx((_, _push, _parent, _scopeId) => { |             named: _withCtx((_, _push, _parent, _scopeId) => { | ||||||
|               if (_push) { |               if (_push) { | ||||||
|                 _push(\`bar\`)
 |                 _push(\`bar\`)
 | ||||||
| @ -123,7 +123,7 @@ describe('ssr: components', () => { | |||||||
|                   _createTextVNode(\\"bar\\") |                   _createTextVNode(\\"bar\\") | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             _: 1 |             _: 1 | ||||||
|           }, _parent)) |           }, _parent)) | ||||||
|         }" |         }" | ||||||
| @ -154,7 +154,7 @@ describe('ssr: components', () => { | |||||||
|                         _createTextVNode(\\"foo\\") |                         _createTextVNode(\\"foo\\") | ||||||
|                       ] |                       ] | ||||||
|                     } |                     } | ||||||
|                   }, _ctx) |                   }) | ||||||
|                 } |                 } | ||||||
|               : undefined |               : undefined | ||||||
|           ]), _parent)) |           ]), _parent)) | ||||||
| @ -186,7 +186,7 @@ describe('ssr: components', () => { | |||||||
|                       _createTextVNode(_toDisplayString(msg + _ctx.key + _ctx.bar), 1 /* TEXT */) |                       _createTextVNode(_toDisplayString(msg + _ctx.key + _ctx.bar), 1 /* TEXT */) | ||||||
|                     ] |                     ] | ||||||
|                   } |                   } | ||||||
|                 }, _ctx) |                 }) | ||||||
|               } |               } | ||||||
|             }) |             }) | ||||||
|           ]), _parent)) |           ]), _parent)) | ||||||
| @ -238,7 +238,7 @@ describe('ssr: components', () => { | |||||||
|                     : _createCommentVNode(\\"v-if\\", true) |                     : _createCommentVNode(\\"v-if\\", true) | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             bar: _withCtx(({ ok }, _push, _parent, _scopeId) => { |             bar: _withCtx(({ ok }, _push, _parent, _scopeId) => { | ||||||
|               if (_push) { |               if (_push) { | ||||||
|                 if (ok) { |                 if (ok) { | ||||||
| @ -261,7 +261,7 @@ describe('ssr: components', () => { | |||||||
|                     : _createCommentVNode(\\"v-if\\", true) |                     : _createCommentVNode(\\"v-if\\", true) | ||||||
|                 ] |                 ] | ||||||
|               } |               } | ||||||
|             }, _ctx), |             }), | ||||||
|             _: 1 |             _: 1 | ||||||
|           }, _parent)) |           }, _parent)) | ||||||
|         }" |         }" | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ describe('ssr: scopeId', () => { | |||||||
|                 _createTextVNode(\\"foo\\") |                 _createTextVNode(\\"foo\\") | ||||||
|               ] |               ] | ||||||
|             } |             } | ||||||
|           }, _ctx), |           }), | ||||||
|           _: 1 |           _: 1 | ||||||
|         }, _parent)) |         }, _parent)) | ||||||
|       }" |       }" | ||||||
| @ -66,7 +66,7 @@ describe('ssr: scopeId', () => { | |||||||
|                 _createVNode(\\"span\\", null, \\"hello\\") |                 _createVNode(\\"span\\", null, \\"hello\\") | ||||||
|               ] |               ] | ||||||
|             } |             } | ||||||
|           }, _ctx), |           }), | ||||||
|           _: 1 |           _: 1 | ||||||
|         }, _parent)) |         }, _parent)) | ||||||
|       }" |       }" | ||||||
| @ -99,7 +99,7 @@ describe('ssr: scopeId', () => { | |||||||
|                       _createVNode(\\"span\\") |                       _createVNode(\\"span\\") | ||||||
|                     ] |                     ] | ||||||
|                   } |                   } | ||||||
|                 }, _ctx), |                 }), | ||||||
|                 _: 1 |                 _: 1 | ||||||
|               }, _parent)) |               }, _parent)) | ||||||
|             } else { |             } else { | ||||||
| @ -108,12 +108,12 @@ describe('ssr: scopeId', () => { | |||||||
|                 _createVNode(_component_bar, null, { |                 _createVNode(_component_bar, null, { | ||||||
|                   default: _withCtx(() => [ |                   default: _withCtx(() => [ | ||||||
|                     _createVNode(\\"span\\") |                     _createVNode(\\"span\\") | ||||||
|                   ], _ctx), |                   ]), | ||||||
|                   _: 1 |                   _: 1 | ||||||
|                 }) |                 }) | ||||||
|               ] |               ] | ||||||
|             } |             } | ||||||
|           }, _ctx), |           }), | ||||||
|           _: 1 |           _: 1 | ||||||
|         }, _parent)) |         }, _parent)) | ||||||
|       }" |       }" | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ | |||||||
| // These are only used in esm-bundler builds, but since exports cannot be
 | // These are only used in esm-bundler builds, but since exports cannot be
 | ||||||
| // conditional, we can only drop inner implementations in non-bundler builds.
 | // conditional, we can only drop inner implementations in non-bundler builds.
 | ||||||
| 
 | 
 | ||||||
| import { ComponentInternalInstance } from '../component' |  | ||||||
| import { withCtx } from './withRenderContext' | import { withCtx } from './withRenderContext' | ||||||
| 
 | 
 | ||||||
| export let currentScopeId: string | null = null | export let currentScopeId: string | null = null | ||||||
| @ -23,14 +22,13 @@ export function popScopeId() { | |||||||
| 
 | 
 | ||||||
| export function withScopeId(id: string): <T extends Function>(fn: T) => T { | export function withScopeId(id: string): <T extends Function>(fn: T) => T { | ||||||
|   if (__BUNDLER__) { |   if (__BUNDLER__) { | ||||||
|     return ((fn: Function, ctx?: ComponentInternalInstance) => { |     return ((fn: Function) => | ||||||
|       return withCtx(function(this: any) { |       withCtx(function(this: any) { | ||||||
|         pushScopeId(id) |         pushScopeId(id) | ||||||
|         const res = fn.apply(this, arguments) |         const res = fn.apply(this, arguments) | ||||||
|         popScopeId() |         popScopeId() | ||||||
|         return res |         return res | ||||||
|       }, ctx) |       })) as any | ||||||
|     }) as any |  | ||||||
|   } else { |   } else { | ||||||
|     return undefined as any |     return undefined as any | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -1,13 +1,13 @@ | |||||||
| import { Slot } from '../componentSlots' | import { Slot } from '../componentSlots' | ||||||
| import { ComponentInternalInstance } from '../component' |  | ||||||
| import { | import { | ||||||
|   setCurrentRenderingInstance, |   setCurrentRenderingInstance, | ||||||
|   currentRenderingInstance |   currentRenderingInstance | ||||||
| } from '../componentRenderUtils' | } from '../componentRenderUtils' | ||||||
|  | import { ComponentInternalInstance } from '../component' | ||||||
| 
 | 
 | ||||||
| export function withCtx( | export function withCtx( | ||||||
|   fn: Slot, |   fn: Slot, | ||||||
|   ctx: ComponentInternalInstance | null | undefined |   ctx: ComponentInternalInstance | null = currentRenderingInstance | ||||||
| ) { | ) { | ||||||
|   if (!ctx) return fn |   if (!ctx) return fn | ||||||
|   return function renderFnWithContext() { |   return function renderFnWithContext() { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user