mirror of https://github.com/vuejs/core.git
Merge 3e21461ca0
into 56be3dd4db
This commit is contained in:
commit
4dcbc6b29b
|
@ -1143,6 +1143,36 @@ describe('SFC analyze <script> bindings', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('recognizes data/setup return', () => {
|
||||
const { bindings } = compile(`
|
||||
<script>
|
||||
const bar = 2
|
||||
const foo = 2
|
||||
const msg = 2
|
||||
const hello = 2
|
||||
export default {
|
||||
setup() {
|
||||
return {
|
||||
foo: 1,
|
||||
hello: numm
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
foo: null,
|
||||
msg: null
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
`)
|
||||
expect(bindings).toStrictEqual({
|
||||
foo: BindingTypes.SETUP_MAYBE_REF,
|
||||
msg: BindingTypes.DATA,
|
||||
hello: BindingTypes.SETUP_MAYBE_REF,
|
||||
})
|
||||
})
|
||||
|
||||
it('recognizes methods', () => {
|
||||
const { bindings } = compile(`
|
||||
<script>
|
||||
|
|
|
@ -87,6 +87,8 @@ function analyzeBindingsFromOptions(node: ObjectExpression): BindingMetadata {
|
|||
bodyItem.argument.type === 'ObjectExpression'
|
||||
) {
|
||||
for (const key of getObjectExpressionKeys(bodyItem.argument)) {
|
||||
// use variables in setup first, consistent with runtime
|
||||
if (bindings[key] === BindingTypes.SETUP_MAYBE_REF) continue
|
||||
bindings[key] =
|
||||
property.key.name === 'setup'
|
||||
? BindingTypes.SETUP_MAYBE_REF
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
import { defineComponent, h, renderToString } from '@vue/runtime-test'
|
||||
|
||||
describe('api: options', () => {
|
||||
test('mix api options: setup and data with created', () => {
|
||||
const mixinA = defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
a: 'from setup',
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
a: 'from data',
|
||||
}
|
||||
},
|
||||
created(this: any) {
|
||||
this.a = 'from created'
|
||||
},
|
||||
render() {
|
||||
return `${this.a}`
|
||||
},
|
||||
})
|
||||
expect(renderToString(h(mixinA))).toBe(`from created`)
|
||||
})
|
||||
|
||||
test('mix api options: data and setup with created', () => {
|
||||
const mixinA = defineComponent({
|
||||
data() {
|
||||
return {
|
||||
a: 'from data',
|
||||
}
|
||||
},
|
||||
setup() {
|
||||
return {
|
||||
a: 'from setup',
|
||||
}
|
||||
},
|
||||
created(this: any) {
|
||||
this.a = 'from created'
|
||||
},
|
||||
render() {
|
||||
return `${this.a}`
|
||||
},
|
||||
})
|
||||
expect(renderToString(h(mixinA))).toBe(`from created`)
|
||||
})
|
||||
|
||||
test('mix api options: data and setup', () => {
|
||||
const mixinA = defineComponent({
|
||||
data() {
|
||||
return {
|
||||
a: 'from data',
|
||||
}
|
||||
},
|
||||
setup() {
|
||||
return {
|
||||
a: 'from setup',
|
||||
}
|
||||
},
|
||||
created(this: any) {},
|
||||
render() {
|
||||
return `${this.a}`
|
||||
},
|
||||
})
|
||||
expect(renderToString(h(mixinA))).toBe(`from setup`)
|
||||
})
|
||||
|
||||
test('mix api options: setup and data', () => {
|
||||
const mixinA = defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
a: 'from setup',
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
a: 'from data',
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return `${this.a}`
|
||||
},
|
||||
})
|
||||
expect(renderToString(h(mixinA))).toBe(`from setup`)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue