fdfa3c7bae
* Update crates * fixup * fix type * Update test refs * Update css crates * Update test refs * Update test refs * Update test refs * SourceMap * Fix? * Update crates * Fix * Update test refs * Update test refs * Update error reporter * Update snapshots * Update snapshots * Bug? * Fix * Fix lint * Update swc again * fixup * Update test refs * Fix Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
/* eslint-env jest */
|
|
import { transform } from 'next/dist/build/swc'
|
|
|
|
const swc = async (code) => {
|
|
let output = await transform(code)
|
|
return output.code
|
|
}
|
|
|
|
const trim = (s) => s.join('\n').trim().replace(/^\s+/gm, '')
|
|
|
|
describe('next/swc', () => {
|
|
describe('hook_optimizer', () => {
|
|
it('should transform Array-destructured hook return values use object destructuring', async () => {
|
|
const output = await swc(
|
|
trim`
|
|
import { useState } from 'react';
|
|
const [count, setCount] = useState(0);
|
|
`
|
|
)
|
|
|
|
expect(output).toMatch(trim`
|
|
var ref = useState(0), count = ref[0], setCount = ref[1];
|
|
`)
|
|
|
|
expect(output).toMatchInlineSnapshot(`
|
|
"import { useState } from \\"react\\";
|
|
var ref = useState(0), count = ref[0], setCount = ref[1];
|
|
"
|
|
`)
|
|
})
|
|
|
|
it('should be able to ignore some Array-destructured hook return values', async () => {
|
|
const output = await swc(
|
|
trim`
|
|
import { useState } from 'react';
|
|
const [, setCount] = useState(0);
|
|
`
|
|
)
|
|
|
|
expect(output).toMatch(trim`
|
|
var ref = useState(0), setCount = ref[1];
|
|
`)
|
|
|
|
expect(output).toMatchInlineSnapshot(`
|
|
"import { useState } from \\"react\\";
|
|
var ref = useState(0), setCount = ref[1];
|
|
"
|
|
`)
|
|
})
|
|
})
|
|
})
|