}"
`;
-exports[`compiler: hoistStatic transform should NOT hoist element with dynamic props 1`] = `
+exports[`compiler: hoistStatic transform should NOT hoist element with dynamic props (but hoist the props list) 1`] = `
"const _Vue = Vue
+const { createElementVNode: _createElementVNode } = _Vue
+
+const _hoisted_1 = [\\"id\\"]
return function render(_ctx, _cache) {
with (_ctx) {
const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue
return (_openBlock(), _createElementBlock(\\"div\\", null, [
- _createElementVNode(\\"div\\", { id: foo }, null, 8 /* PROPS */, [\\"id\\"])
+ _createElementVNode(\\"div\\", { id: foo }, null, 8 /* PROPS */, _hoisted_1)
]))
}
}"
expect(generate(root).code).toMatchSnapshot()
})
- test('should NOT hoist element with dynamic props', () => {
+ test('should NOT hoist element with dynamic props (but hoist the props list)', () => {
const root = transformWithHoist(`<div><div :id="foo"/></div>`)
- expect(root.hoists.length).toBe(0)
+ expect(root.hoists.length).toBe(1)
expect((root.codegenNode as VNodeCall).children).toMatchObject([
{
type: NodeTypes.ELEMENT,
}),
children: undefined,
patchFlag: genFlagText(PatchFlags.PROPS),
- dynamicProps: `["id"]`
+ dynamicProps: {
+ type: NodeTypes.SIMPLE_EXPRESSION,
+ content: `_hoisted_1`,
+ isStatic: false
+ }
}
}
])
| ForRenderListExpression // v-for fragment call
| undefined
patchFlag: string | undefined
- dynamicProps: string | undefined
+ dynamicProps: string | SimpleExpressionNode | undefined
directives: DirectiveArguments | undefined
isBlock: boolean
disableTracking: boolean
onNodeRemoved(): void
addIdentifiers(exp: ExpressionNode | string): void
removeIdentifiers(exp: ExpressionNode | string): void
- hoist(exp: JSChildNode): SimpleExpressionNode
+ hoist(exp: string | JSChildNode): SimpleExpressionNode
cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T
constantCache: Map<TemplateChildNode, ConstantTypes>
}
},
hoist(exp) {
+ if (isString(exp)) exp = createSimpleExpression(exp, false)
context.hoists.push(exp)
const identifier = createSimpleExpression(
`_hoisted_${context.hoists.length}`,
codegenNode.props = context.hoist(props)
}
}
+ if (codegenNode.dynamicProps) {
+ codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps)
+ }
}
}
} else if (child.type === NodeTypes.TEXT_CALL) {