2021-08-23 10:21:42 +08:00
|
|
|
import { parse } from '@babel/parser'
|
|
|
|
import { transform } from '../src'
|
|
|
|
|
|
|
|
function assertCode(code: string) {
|
|
|
|
// parse the generated code to make sure it is valid
|
|
|
|
try {
|
|
|
|
parse(code, {
|
|
|
|
sourceType: 'module',
|
2021-10-08 07:32:59 +08:00
|
|
|
plugins: ['typescript']
|
2021-08-23 10:21:42 +08:00
|
|
|
})
|
2021-09-02 21:53:57 +08:00
|
|
|
} catch (e: any) {
|
2021-08-23 10:21:42 +08:00
|
|
|
console.log(code)
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
expect(code).toMatchSnapshot()
|
|
|
|
}
|
|
|
|
|
|
|
|
test('$ unwrapping', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
import { ref, shallowRef } from 'vue'
|
|
|
|
let foo = $(ref())
|
2022-01-21 07:40:35 +08:00
|
|
|
export let a = $(ref(1))
|
2021-08-23 10:21:42 +08:00
|
|
|
let b = $(shallowRef({
|
|
|
|
count: 0
|
|
|
|
}))
|
|
|
|
let c = () => {}
|
|
|
|
let d
|
2022-01-21 07:48:41 +08:00
|
|
|
label: var e = $(ref())
|
2021-08-23 10:21:42 +08:00
|
|
|
`)
|
|
|
|
expect(code).not.toMatch(`$(ref())`)
|
|
|
|
expect(code).not.toMatch(`$(ref(1))`)
|
|
|
|
expect(code).not.toMatch(`$(shallowRef({`)
|
|
|
|
expect(code).toMatch(`let foo = (ref())`)
|
2022-01-21 07:40:35 +08:00
|
|
|
expect(code).toMatch(`export let a = (ref(1))`)
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(code).toMatch(`
|
|
|
|
let b = (shallowRef({
|
|
|
|
count: 0
|
|
|
|
}))
|
|
|
|
`)
|
|
|
|
// normal declarations left untouched
|
|
|
|
expect(code).toMatch(`let c = () => {}`)
|
|
|
|
expect(code).toMatch(`let d`)
|
2022-01-21 07:48:41 +08:00
|
|
|
expect(code).toMatch(`label: var e = (ref())`)
|
|
|
|
expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
|
2021-08-23 10:21:42 +08:00
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('$ref & $shallowRef declarations', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs, importedHelpers } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let foo = $ref()
|
2022-01-21 07:48:41 +08:00
|
|
|
export let a = $ref(1)
|
2021-08-23 10:21:42 +08:00
|
|
|
let b = $shallowRef({
|
|
|
|
count: 0
|
|
|
|
})
|
|
|
|
let c = () => {}
|
|
|
|
let d
|
2022-01-21 07:48:41 +08:00
|
|
|
label: var e = $ref()
|
2021-08-23 10:21:42 +08:00
|
|
|
`)
|
|
|
|
expect(code).toMatch(
|
|
|
|
`import { ref as _ref, shallowRef as _shallowRef } from 'vue'`
|
|
|
|
)
|
|
|
|
expect(code).not.toMatch(`$ref()`)
|
|
|
|
expect(code).not.toMatch(`$ref(1)`)
|
|
|
|
expect(code).not.toMatch(`$shallowRef({`)
|
|
|
|
expect(code).toMatch(`let foo = _ref()`)
|
|
|
|
expect(code).toMatch(`let a = _ref(1)`)
|
|
|
|
expect(code).toMatch(`
|
|
|
|
let b = _shallowRef({
|
|
|
|
count: 0
|
|
|
|
})
|
|
|
|
`)
|
|
|
|
// normal declarations left untouched
|
|
|
|
expect(code).toMatch(`let c = () => {}`)
|
|
|
|
expect(code).toMatch(`let d`)
|
2022-01-21 07:48:41 +08:00
|
|
|
expect(code).toMatch(`label: var e = _ref()`)
|
|
|
|
expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(importedHelpers).toStrictEqual(['ref', 'shallowRef'])
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('multi $ref declarations', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs, importedHelpers } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let a = $ref(1), b = $ref(2), c = $ref({
|
|
|
|
count: 0
|
|
|
|
})
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`
|
|
|
|
let a = _ref(1), b = _ref(2), c = _ref({
|
|
|
|
count: 0
|
|
|
|
})
|
|
|
|
`)
|
2021-09-28 02:24:21 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['a', 'b', 'c'])
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(importedHelpers).toStrictEqual(['ref'])
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('$computed declaration', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs, importedHelpers } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let a = $computed(() => 1)
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`
|
|
|
|
let a = _computed(() => 1)
|
|
|
|
`)
|
2021-09-28 02:24:21 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['a'])
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(importedHelpers).toStrictEqual(['computed'])
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('mixing $ref & $computed declarations', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs, importedHelpers } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let a = $ref(1), b = $computed(() => a + 1)
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`
|
|
|
|
let a = _ref(1), b = _computed(() => a.value + 1)
|
|
|
|
`)
|
2021-09-28 02:24:21 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['a', 'b'])
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(importedHelpers).toStrictEqual(['ref', 'computed'])
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('accessing ref binding', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
console.log(a)
|
|
|
|
function get() {
|
|
|
|
return a + 1
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`console.log(a.value)`)
|
|
|
|
expect(code).toMatch(`return a.value + 1`)
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
2021-12-31 11:23:50 +08:00
|
|
|
describe('cases that should not append .value', () => {
|
|
|
|
test('member expression', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
console.log(b.a)
|
|
|
|
`)
|
|
|
|
expect(code).not.toMatch(`a.value`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('function argument', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
function get(a) {
|
|
|
|
return a + 1
|
|
|
|
}
|
|
|
|
function get2({ a }) {
|
|
|
|
return a + 1
|
|
|
|
}
|
|
|
|
function get3([a]) {
|
|
|
|
return a + 1
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
expect(code).not.toMatch(`a.value`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('for in/of loops', () => {
|
|
|
|
const { code } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let a = $ref(1)
|
2021-12-31 11:23:50 +08:00
|
|
|
for (const [a, b] of arr) {
|
|
|
|
console.log(a)
|
|
|
|
}
|
|
|
|
for (let a in arr) {
|
|
|
|
console.log(a)
|
2021-08-23 10:21:42 +08:00
|
|
|
}
|
|
|
|
`)
|
2021-12-31 11:23:50 +08:00
|
|
|
expect(code).not.toMatch(`a.value`)
|
|
|
|
})
|
2021-08-23 10:21:42 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('mutating ref binding', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
let b = $ref({ count: 0 })
|
|
|
|
function inc() {
|
|
|
|
a++
|
|
|
|
a = a + 1
|
|
|
|
b.count++
|
|
|
|
b.count = b.count + 1
|
|
|
|
;({ a } = { a: 2 })
|
|
|
|
;[a] = [1]
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`a.value++`)
|
|
|
|
expect(code).toMatch(`a.value = a.value + 1`)
|
|
|
|
expect(code).toMatch(`b.value.count++`)
|
|
|
|
expect(code).toMatch(`b.value.count = b.value.count + 1`)
|
|
|
|
expect(code).toMatch(`;({ a: a.value } = { a: 2 })`)
|
|
|
|
expect(code).toMatch(`;[a.value] = [1]`)
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('using ref binding in property shorthand', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
const b = { a }
|
|
|
|
function test() {
|
|
|
|
const { a } = b
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`const b = { a: a.value }`)
|
|
|
|
// should not convert destructure
|
|
|
|
expect(code).toMatch(`const { a } = b`)
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should not rewrite scope variable', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
|
|
|
|
let a = $ref(1)
|
|
|
|
let b = $ref(1)
|
|
|
|
let d = $ref(1)
|
|
|
|
const e = 1
|
|
|
|
function test() {
|
|
|
|
const a = 2
|
|
|
|
console.log(a)
|
|
|
|
console.log(b)
|
|
|
|
let c = { c: 3 }
|
|
|
|
console.log(c)
|
|
|
|
console.log(d)
|
|
|
|
console.log(e)
|
|
|
|
}
|
2022-04-14 08:06:58 +08:00
|
|
|
let err = $ref(null)
|
|
|
|
try {
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2021-08-23 10:21:42 +08:00
|
|
|
`)
|
|
|
|
expect(code).toMatch('console.log(a)')
|
|
|
|
expect(code).toMatch('console.log(b.value)')
|
|
|
|
expect(code).toMatch('console.log(c)')
|
|
|
|
expect(code).toMatch('console.log(d.value)')
|
|
|
|
expect(code).toMatch('console.log(e)')
|
2022-04-14 08:06:58 +08:00
|
|
|
expect(code).toMatch('console.log(err)')
|
2021-08-23 10:21:42 +08:00
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('object destructure', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs } = transform(`
|
2021-12-11 17:10:31 +08:00
|
|
|
let n = $ref(1), { a, b: c, d = 1, e: f = 2, [g]: h } = $(useFoo())
|
2021-08-23 10:21:42 +08:00
|
|
|
let { foo } = $(useSomthing(() => 1));
|
2021-12-11 17:10:31 +08:00
|
|
|
console.log(n, a, c, d, f, h, foo)
|
2021-08-23 10:21:42 +08:00
|
|
|
`)
|
2021-12-11 17:10:31 +08:00
|
|
|
expect(code).toMatch(`a = _toRef(__$temp_1, 'a')`)
|
|
|
|
expect(code).toMatch(`c = _toRef(__$temp_1, 'b')`)
|
|
|
|
expect(code).toMatch(`d = _toRef(__$temp_1, 'd', 1)`)
|
|
|
|
expect(code).toMatch(`f = _toRef(__$temp_1, 'e', 2)`)
|
|
|
|
expect(code).toMatch(`h = _toRef(__$temp_1, g)`)
|
|
|
|
expect(code).toMatch(`foo = _toRef(__$temp_2, 'foo')`)
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(code).toMatch(
|
2021-12-11 17:10:31 +08:00
|
|
|
`console.log(n.value, a.value, c.value, d.value, f.value, h.value, foo.value)`
|
2021-08-23 10:21:42 +08:00
|
|
|
)
|
2021-12-11 17:10:31 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['n', 'a', 'c', 'd', 'f', 'h', 'foo'])
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('object destructure w/ mid-path default values', () => {
|
|
|
|
const { code, rootRefs } = transform(`
|
|
|
|
const { a: { b } = { b: 123 }} = $(useFoo())
|
|
|
|
console.log(b)
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`b = _toRef((__$temp_1.a || { b: 123 }), 'b')`)
|
|
|
|
expect(code).toMatch(`console.log(b.value)`)
|
|
|
|
expect(rootRefs).toStrictEqual(['b'])
|
2021-08-23 10:21:42 +08:00
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('array destructure', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs } = transform(`
|
2021-12-11 17:10:31 +08:00
|
|
|
let n = $ref(1), [a, b = 1] = $(useFoo())
|
|
|
|
console.log(n, a, b)
|
2021-08-23 10:21:42 +08:00
|
|
|
`)
|
2021-12-11 17:10:31 +08:00
|
|
|
expect(code).toMatch(`a = _toRef(__$temp_1, 0)`)
|
|
|
|
expect(code).toMatch(`b = _toRef(__$temp_1, 1, 1)`)
|
|
|
|
expect(code).toMatch(`console.log(n.value, a.value, b.value)`)
|
|
|
|
expect(rootRefs).toStrictEqual(['n', 'a', 'b'])
|
2021-08-23 10:21:42 +08:00
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('nested destructure', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let [{ a: { b }}] = $(useFoo())
|
|
|
|
let { c: [d, e] } = $(useBar())
|
|
|
|
console.log(b, d, e)
|
|
|
|
`)
|
2021-12-11 17:10:31 +08:00
|
|
|
expect(code).toMatch(`b = _toRef(__$temp_1[0].a, 'b')`)
|
|
|
|
expect(code).toMatch(`d = _toRef(__$temp_2.c, 0)`)
|
|
|
|
expect(code).toMatch(`e = _toRef(__$temp_2.c, 1)`)
|
2021-09-28 02:24:21 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['b', 'd', 'e'])
|
2021-08-23 10:21:42 +08:00
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('$$', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
let a = $ref(1)
|
|
|
|
const b = $$(a)
|
|
|
|
const c = $$({ a })
|
|
|
|
callExternal($$(a))
|
|
|
|
`)
|
|
|
|
expect(code).toMatch(`const b = (a)`)
|
|
|
|
expect(code).toMatch(`const c = ({ a })`)
|
|
|
|
expect(code).toMatch(`callExternal((a))`)
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('nested scopes', () => {
|
2021-09-28 02:24:21 +08:00
|
|
|
const { code, rootRefs } = transform(`
|
2021-08-23 10:21:42 +08:00
|
|
|
let a = $ref(0)
|
|
|
|
let b = $ref(0)
|
|
|
|
let c = 0
|
|
|
|
|
|
|
|
a++ // outer a
|
|
|
|
b++ // outer b
|
|
|
|
c++ // outer c
|
|
|
|
|
2021-08-24 04:00:46 +08:00
|
|
|
let bar = $ref(0)
|
|
|
|
bar++ // outer bar
|
|
|
|
|
2021-08-23 10:21:42 +08:00
|
|
|
function foo({ a }) {
|
|
|
|
a++ // inner a
|
|
|
|
b++ // inner b
|
|
|
|
let c = $ref(0)
|
|
|
|
c++ // inner c
|
|
|
|
let d = $ref(0)
|
|
|
|
|
2021-08-24 04:00:46 +08:00
|
|
|
function bar(c) {
|
2021-08-23 10:21:42 +08:00
|
|
|
c++ // nested c
|
|
|
|
d++ // nested d
|
|
|
|
}
|
2021-08-24 04:00:46 +08:00
|
|
|
bar() // inner bar
|
2021-08-23 10:21:42 +08:00
|
|
|
|
|
|
|
if (true) {
|
|
|
|
let a = $ref(0)
|
|
|
|
a++ // if block a
|
|
|
|
}
|
|
|
|
|
|
|
|
return $$({ a, b, c, d })
|
|
|
|
}
|
|
|
|
`)
|
2021-09-28 02:24:21 +08:00
|
|
|
expect(rootRefs).toStrictEqual(['a', 'b', 'bar'])
|
2021-08-23 10:21:42 +08:00
|
|
|
|
|
|
|
expect(code).toMatch('a.value++ // outer a')
|
|
|
|
expect(code).toMatch('b.value++ // outer b')
|
|
|
|
expect(code).toMatch('c++ // outer c')
|
|
|
|
|
|
|
|
expect(code).toMatch('a++ // inner a') // shadowed by function arg
|
|
|
|
expect(code).toMatch('b.value++ // inner b')
|
|
|
|
expect(code).toMatch('c.value++ // inner c') // shadowed by local ref binding
|
|
|
|
|
|
|
|
expect(code).toMatch('c++ // nested c') // shadowed by inline fn arg
|
|
|
|
expect(code).toMatch(`d.value++ // nested d`)
|
|
|
|
|
|
|
|
expect(code).toMatch(`a.value++ // if block a`) // if block
|
|
|
|
|
2021-08-24 04:00:46 +08:00
|
|
|
expect(code).toMatch(`bar.value++ // outer bar`)
|
|
|
|
// inner bar shadowed by function declaration
|
|
|
|
expect(code).toMatch(`bar() // inner bar`)
|
|
|
|
|
2021-08-23 10:21:42 +08:00
|
|
|
expect(code).toMatch(`return ({ a, b, c, d })`)
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
//#4062
|
|
|
|
test('should not rewrite type identifiers', () => {
|
|
|
|
const { code } = transform(
|
|
|
|
`const props = defineProps<{msg: string; ids?: string[]}>()
|
|
|
|
let ids = $ref([])`,
|
|
|
|
{
|
|
|
|
parserPlugins: ['typescript']
|
|
|
|
}
|
|
|
|
)
|
|
|
|
expect(code).not.toMatch('.value')
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
|
|
|
// #4254
|
|
|
|
test('handle TS casting syntax', () => {
|
|
|
|
const { code } = transform(
|
|
|
|
`
|
|
|
|
let a = $ref(1)
|
|
|
|
console.log(a!)
|
|
|
|
console.log(a! + 1)
|
|
|
|
console.log(a as number)
|
|
|
|
console.log((a as number) + 1)
|
|
|
|
console.log(<number>a)
|
|
|
|
console.log(<number>a + 1)
|
|
|
|
console.log(a! + (a as number))
|
|
|
|
console.log(a! + <number>a)
|
|
|
|
console.log((a as number) + <number>a)
|
|
|
|
`,
|
|
|
|
{
|
|
|
|
parserPlugins: ['typescript']
|
|
|
|
}
|
|
|
|
)
|
|
|
|
expect(code).toMatch('console.log(a.value!)')
|
|
|
|
expect(code).toMatch('console.log(a.value as number)')
|
|
|
|
expect(code).toMatch('console.log(<number>a.value)')
|
|
|
|
assertCode(code)
|
|
|
|
})
|
|
|
|
|
2021-12-11 18:28:03 +08:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-08-23 10:21:42 +08:00
|
|
|
describe('errors', () => {
|
|
|
|
test('$ref w/ destructure', () => {
|
|
|
|
expect(() => transform(`let { a } = $ref(1)`)).toThrow(
|
|
|
|
`cannot be used with destructure`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('$computed w/ destructure', () => {
|
|
|
|
expect(() => transform(`let { a } = $computed(() => 1)`)).toThrow(
|
|
|
|
`cannot be used with destructure`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('warn usage in non-init positions', () => {
|
|
|
|
expect(() =>
|
|
|
|
transform(
|
|
|
|
`let bar = $ref(1)
|
|
|
|
bar = $ref(2)`
|
|
|
|
)
|
|
|
|
).toThrow(`$ref can only be used as the initializer`)
|
|
|
|
|
|
|
|
expect(() => transform(`let bar = { foo: $computed(1) }`)).toThrow(
|
|
|
|
`$computed can only be used as the initializer`
|
|
|
|
)
|
|
|
|
})
|
2021-09-06 05:35:13 +08:00
|
|
|
|
|
|
|
test('not transform the prototype attributes', () => {
|
|
|
|
const { code } = transform(`
|
|
|
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
|
|
const hasOwn = (val, key) => hasOwnProperty.call(val, key)
|
|
|
|
`)
|
|
|
|
expect(code).not.toMatch('.value')
|
|
|
|
})
|
2021-12-11 17:10:31 +08:00
|
|
|
|
|
|
|
test('rest element in $() destructure', () => {
|
|
|
|
expect(() => transform(`let { a, ...b } = $(foo())`)).toThrow(
|
|
|
|
`does not support rest element`
|
|
|
|
)
|
|
|
|
expect(() => transform(`let [a, ...b] = $(foo())`)).toThrow(
|
|
|
|
`does not support rest element`
|
|
|
|
)
|
|
|
|
})
|
2021-08-23 10:21:42 +08:00
|
|
|
})
|