fix: handle case of ref declaration without initial value
This commit is contained in:
@@ -292,6 +292,7 @@ exports[`SFC compile <script setup> ref: syntax sugar convert ref declarations 1
|
||||
|
||||
export function setup() {
|
||||
|
||||
const foo = ref()
|
||||
const a = ref(1)
|
||||
const b = ref({
|
||||
count: 0
|
||||
@@ -299,7 +300,7 @@ export function setup() {
|
||||
let c = () => {}
|
||||
let d
|
||||
|
||||
return { a, b, c, d }
|
||||
return { foo, a, b, c, d }
|
||||
}
|
||||
|
||||
export default { setup }"
|
||||
|
||||
@@ -259,6 +259,7 @@ describe('SFC compile <script setup>', () => {
|
||||
describe('ref: syntax sugar', () => {
|
||||
test('convert ref declarations', () => {
|
||||
const { content, bindings } = compile(`<script setup>
|
||||
ref: foo
|
||||
ref: a = 1
|
||||
ref: b = {
|
||||
count: 0
|
||||
@@ -267,7 +268,10 @@ describe('SFC compile <script setup>', () => {
|
||||
let d
|
||||
</script>`)
|
||||
expect(content).toMatch(`import { ref } from 'vue'`)
|
||||
expect(content).not.toMatch(`ref: foo`)
|
||||
expect(content).not.toMatch(`ref: a`)
|
||||
expect(content).not.toMatch(`ref: b`)
|
||||
expect(content).toMatch(`const foo = ref()`)
|
||||
expect(content).toMatch(`const a = ref(1)`)
|
||||
expect(content).toMatch(`
|
||||
const b = ref({
|
||||
@@ -279,6 +283,7 @@ describe('SFC compile <script setup>', () => {
|
||||
expect(content).toMatch(`let d`)
|
||||
assertCode(content)
|
||||
expect(bindings).toStrictEqual({
|
||||
foo: 'setup',
|
||||
a: 'setup',
|
||||
b: 'setup',
|
||||
c: 'setup',
|
||||
|
||||
Reference in New Issue
Block a user