feat(reactivity-transform): support optionally importing macros
This commit is contained in:
@@ -80,6 +80,18 @@ exports[`handle TS casting syntax 1`] = `
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`macro import alias and removal 1`] = `
|
||||
"import { ref as _ref, toRef as _toRef } from 'vue'
|
||||
|
||||
|
||||
|
||||
let a = _ref(1)
|
||||
const __$temp_1 = (useMouse()),
|
||||
x = _toRef(__$temp_1, 'x'),
|
||||
y = _toRef(__$temp_1, 'y')
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`mixing $ref & $computed declarations 1`] = `
|
||||
"import { ref as _ref, computed as _computed } from 'vue'
|
||||
|
||||
|
||||
@@ -362,6 +362,22 @@ test('handle TS casting syntax', () => {
|
||||
assertCode(code)
|
||||
})
|
||||
|
||||
test('macro import alias and removal', () => {
|
||||
const { code } = transform(
|
||||
`
|
||||
import { $ as fromRefs, $ref } from 'vue/macros'
|
||||
|
||||
let a = $ref(1)
|
||||
const { x, y } = fromRefs(useMouse())
|
||||
`
|
||||
)
|
||||
// should remove imports
|
||||
expect(code).not.toMatch(`from 'vue/macros'`)
|
||||
expect(code).toMatch(`let a = _ref(1)`)
|
||||
expect(code).toMatch(`const __$temp_1 = (useMouse())`)
|
||||
assertCode(code)
|
||||
})
|
||||
|
||||
describe('errors', () => {
|
||||
test('$ref w/ destructure', () => {
|
||||
expect(() => transform(`let { a } = $ref(1)`)).toThrow(
|
||||
|
||||
Reference in New Issue
Block a user