Skip to content

Commit

Permalink
test: remove node transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Dec 13, 2024
1 parent 293b068 commit 5316df6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/remove-node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { isCallOf } from 'ast-kit'
import { expect, test } from 'vitest'
import { transform } from '../src/core/transform'
import { RemoveNode } from '../src/transformers'
import type { OptionsResolved } from '../src/core/options'

test('remove node', async () => {
const source = `const comp = defineComponent({
render() {
return []
}
})
console.log(mutable({} as const))
`

const options: Pick<OptionsResolved, 'parserOptions' | 'transformer'> = {
transformer: [
RemoveNode(
(node) => node.type === 'ReturnStatement' || isCallOf(node, 'mutable'),
),
],
parserOptions: {},
}
const code = (await transform(source, 'foo.ts', options))?.code
expect(code).toMatchInlineSnapshot(`
"const comp = defineComponent({
render() {
}
})
console.log()
"
`)
})

0 comments on commit 5316df6

Please sign in to comment.