mirror of https://github.com/vuejs/core.git
feat(compiler-core): hoist element with static ref (#344)
This commit is contained in:
parent
27f3c2d751
commit
920773fc6b
|
@ -169,6 +169,23 @@ return function render() {
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`compiler: hoistStatic transform prefixIdentifiers hoist element with static ref 1`] = `
|
||||||
|
"const _Vue = Vue
|
||||||
|
const _createVNode = Vue.createVNode
|
||||||
|
|
||||||
|
const _hoisted_1 = _createVNode(\\"span\\", { ref: \\"o\\" })
|
||||||
|
|
||||||
|
return function render() {
|
||||||
|
with (this) {
|
||||||
|
const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue
|
||||||
|
|
||||||
|
return (_openBlock(), _createBlock(\\"div\\", null, [
|
||||||
|
_hoisted_1
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`compiler: hoistStatic transform prefixIdentifiers hoist nested static tree with static interpolation 1`] = `
|
exports[`compiler: hoistStatic transform prefixIdentifiers hoist nested static tree with static interpolation 1`] = `
|
||||||
"const _Vue = Vue
|
"const _Vue = Vue
|
||||||
const _createVNode = Vue.createVNode
|
const _createVNode = Vue.createVNode
|
||||||
|
|
|
@ -677,5 +677,42 @@ describe('compiler: hoistStatic transform', () => {
|
||||||
}).code
|
}).code
|
||||||
).toMatchSnapshot()
|
).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('hoist element with static ref', () => {
|
||||||
|
const { root, args } = transformWithHoist(
|
||||||
|
`<div><span ref="o"></span></div>`,
|
||||||
|
{
|
||||||
|
prefixIdentifiers: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(root.hoists.length).toBe(1)
|
||||||
|
expect(root.hoists).toMatchObject([
|
||||||
|
{
|
||||||
|
type: NodeTypes.JS_CALL_EXPRESSION,
|
||||||
|
callee: CREATE_VNODE,
|
||||||
|
arguments: [
|
||||||
|
`"span"`,
|
||||||
|
createObjectMatcher({
|
||||||
|
ref: `o`
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
])
|
||||||
|
expect(args).toMatchObject([
|
||||||
|
`"div"`,
|
||||||
|
`null`,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: NodeTypes.ELEMENT,
|
||||||
|
codegenNode: {
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
content: `_hoisted_1`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
])
|
||||||
|
expect(generate(root).code).toMatchSnapshot()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -699,10 +699,15 @@ describe('compiler: element transform', () => {
|
||||||
expect(node.arguments[3]).toBe(genFlagText(PatchFlags.FULL_PROPS))
|
expect(node.arguments[3]).toBe(genFlagText(PatchFlags.FULL_PROPS))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('NEED_PATCH (static ref)', () => {
|
test('NO NEED_PATCH (static ref)', () => {
|
||||||
const { node } = parseWithBind(`<div ref="foo" />`)
|
const { node } = parseWithBind(`<div ref="foo" />`)
|
||||||
expect(node.arguments.length).toBe(4)
|
expect(node.arguments.length).toBe(2)
|
||||||
expect(node.arguments[3]).toBe(genFlagText(PatchFlags.NEED_PATCH))
|
expect(node.arguments).toMatchObject([
|
||||||
|
`"div"`,
|
||||||
|
createObjectMatcher({
|
||||||
|
ref: `foo`
|
||||||
|
})
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('NEED_PATCH (dynamic ref)', () => {
|
test('NEED_PATCH (dynamic ref)', () => {
|
||||||
|
|
|
@ -249,9 +249,6 @@ export function buildProps(
|
||||||
const prop = props[i]
|
const prop = props[i]
|
||||||
if (prop.type === NodeTypes.ATTRIBUTE) {
|
if (prop.type === NodeTypes.ATTRIBUTE) {
|
||||||
const { loc, name, value } = prop
|
const { loc, name, value } = prop
|
||||||
if (name === 'ref') {
|
|
||||||
hasRef = true
|
|
||||||
}
|
|
||||||
properties.push(
|
properties.push(
|
||||||
createObjectProperty(
|
createObjectProperty(
|
||||||
createSimpleExpression(
|
createSimpleExpression(
|
||||||
|
|
Loading…
Reference in New Issue