fix(compiler-sfc): fix script setup ref assignment codegen edge case (#4520)
fix #4514
This commit is contained in:
@@ -98,7 +98,7 @@ const myEmit = defineEmits(['foo', 'bar'])
|
||||
emits: ['foo', 'bar'],`)
|
||||
})
|
||||
|
||||
test('defineProps/defineEmits in multi-variable decalration', () => {
|
||||
test('defineProps/defineEmits in multi-variable declaration', () => {
|
||||
const { content } = compile(`
|
||||
<script setup>
|
||||
const props = defineProps(['item']),
|
||||
@@ -112,7 +112,7 @@ const myEmit = defineEmits(['foo', 'bar'])
|
||||
expect(content).toMatch(`emits: ['a'],`)
|
||||
})
|
||||
|
||||
test('defineProps/defineEmits in multi-variable decalration (full removal)', () => {
|
||||
test('defineProps/defineEmits in multi-variable declaration (full removal)', () => {
|
||||
const { content } = compile(`
|
||||
<script setup>
|
||||
const props = defineProps(['item']),
|
||||
@@ -517,6 +517,22 @@ defineExpose({ foo: 123 })
|
||||
<div @click="lett = count"/>
|
||||
<div @click="v += 1"/>
|
||||
<div @click="v -= 1"/>
|
||||
<div @click="() => {
|
||||
let a = '' + lett
|
||||
v = a
|
||||
}"/>
|
||||
<div @click="() => {
|
||||
// nested scopes
|
||||
(()=>{
|
||||
let x = a
|
||||
(()=>{
|
||||
let z = x
|
||||
let z2 = z
|
||||
})
|
||||
let lz = z
|
||||
})
|
||||
v = a
|
||||
}"/>
|
||||
</template>
|
||||
`,
|
||||
{ inlineTemplate: true }
|
||||
@@ -531,6 +547,8 @@ defineExpose({ foo: 123 })
|
||||
)
|
||||
expect(content).toMatch(`_isRef(v) ? v.value += 1 : v += 1`)
|
||||
expect(content).toMatch(`_isRef(v) ? v.value -= 1 : v -= 1`)
|
||||
expect(content).toMatch(`_isRef(v) ? v.value = a : v = a`)
|
||||
expect(content).toMatch(`_isRef(v) ? v.value = _ctx.a : v = _ctx.a`)
|
||||
assertCode(content)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user