}))
let c = () => {}
let d
+ label: var e = $(ref())
`)
expect(code).not.toMatch(`$(ref())`)
expect(code).not.toMatch(`$(ref(1))`)
// normal declarations left untouched
expect(code).toMatch(`let c = () => {}`)
expect(code).toMatch(`let d`)
- expect(rootRefs).toStrictEqual(['foo', 'a', 'b'])
+ expect(code).toMatch(`label: var e = (ref())`)
+ expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
assertCode(code)
})
test('$ref & $shallowRef declarations', () => {
const { code, rootRefs, importedHelpers } = transform(`
let foo = $ref()
- let a = $ref(1)
+ export let a = $ref(1)
let b = $shallowRef({
count: 0
})
let c = () => {}
let d
+ label: var e = $ref()
`)
expect(code).toMatch(
`import { ref as _ref, shallowRef as _shallowRef } from 'vue'`
// normal declarations left untouched
expect(code).toMatch(`let c = () => {}`)
expect(code).toMatch(`let d`)
- expect(rootRefs).toStrictEqual(['foo', 'a', 'b'])
+ expect(code).toMatch(`label: var e = _ref()`)
+ expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
expect(importedHelpers).toStrictEqual(['ref', 'shallowRef'])
assertCode(code)
})
stmt.declaration.type === 'VariableDeclaration'
) {
walkVariableDeclaration(stmt.declaration, isRoot)
+ } else if (
+ stmt.type === 'LabeledStatement' &&
+ stmt.body.type === 'VariableDeclaration'
+ ) {
+ walkVariableDeclaration(stmt.body, isRoot)
}
}
}