fix(compiler): fix template ref codegen for setup-maybe-ref binding types (#4549)
fix #4546
This commit is contained in:
@@ -1004,6 +1004,81 @@ describe('compiler: element transform', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('the binding not exists (inline maybe ref input)', () => {
|
||||
const { node } = parseWithElementTransform(`<input ref="input"/>`, {
|
||||
inline: true,
|
||||
bindingMetadata: {
|
||||
input: BindingTypes.SETUP_MAYBE_REF
|
||||
}
|
||||
})
|
||||
expect(node.props).toMatchObject({
|
||||
type: NodeTypes.JS_OBJECT_EXPRESSION,
|
||||
properties: [
|
||||
{
|
||||
type: NodeTypes.JS_PROPERTY,
|
||||
key: {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: 'ref',
|
||||
isStatic: true
|
||||
},
|
||||
value: {
|
||||
type: NodeTypes.JS_FUNCTION_EXPRESSION,
|
||||
params: ['_value', '_refs'],
|
||||
body: {
|
||||
type: NodeTypes.JS_BLOCK_STATEMENT,
|
||||
body: [
|
||||
{
|
||||
content: `_refs['input'] = _value`
|
||||
},
|
||||
{
|
||||
content: '_isRef(input) && (input.value = _value)'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('the binding not exists (inline let ref input)', () => {
|
||||
const { node } = parseWithElementTransform(`<input ref="input"/>`, {
|
||||
inline: true,
|
||||
bindingMetadata: {
|
||||
input: BindingTypes.SETUP_LET
|
||||
}
|
||||
})
|
||||
expect(node.props).toMatchObject({
|
||||
type: NodeTypes.JS_OBJECT_EXPRESSION,
|
||||
properties: [
|
||||
{
|
||||
type: NodeTypes.JS_PROPERTY,
|
||||
key: {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: 'ref',
|
||||
isStatic: true
|
||||
},
|
||||
value: {
|
||||
type: NodeTypes.JS_FUNCTION_EXPRESSION,
|
||||
params: ['_value', '_refs'],
|
||||
body: {
|
||||
type: NodeTypes.JS_BLOCK_STATEMENT,
|
||||
body: [
|
||||
{
|
||||
content: `_refs['input'] = _value`
|
||||
},
|
||||
{
|
||||
content:
|
||||
'_isRef(input) ? input.value = _value : input = _value'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('HYDRATE_EVENTS', () => {
|
||||
// ignore click events (has dedicated fast path)
|
||||
const { node } = parseWithElementTransform(`<div @click="foo" />`, {
|
||||
|
||||
Reference in New Issue
Block a user