Skip to content

Commit

Permalink
test: remove wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jun 22, 2022
1 parent eeab08f commit 59fc690
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest'
import { transform } from '../src/core/transform'
import type { Identifier, StringLiteral } from '@babel/types'
import type { CallExpression, Identifier, StringLiteral } from '@babel/types'
import type { OptionsResolved, Transformer } from '../src/core/options'

test('basic', async () => {
Expand Down Expand Up @@ -36,3 +36,33 @@ test('basic', async () => {
code = await transform(source, 'foo.js', options)
expect(code).toMatchInlineSnapshot('"const newName = \'string\'"')
})

test('remove wrapper function', async () => {
const source = `const comp = defineComponent({
render() {
return []
}
})`
const transformer: Transformer<CallExpression> = {
filterNode: (node) =>
node.type === 'CallExpression' &&
node.callee.type === 'Identifier' &&
node.callee.name === 'defineComponent',
transform(node, code) {
const [arg] = node.arguments
code.overwrite(node.start!, node.end!, code.slice(arg.start!, arg.end!))
},
}
const options: Pick<OptionsResolved, 'parserOptions' | 'transformer'> = {
transformer: [transformer],
parserOptions: {},
}
const code = await transform(source, 'foo.js', options)
expect(code).toMatchInlineSnapshot(`
"const comp = {
render() {
return []
}
}"
`)
})

0 comments on commit 59fc690

Please sign in to comment.