Skip to content

Commit 9655640

Browse files
committed
perf: use native filters
1 parent 9cbd706 commit 9655640

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
"@babel/generator": "^7.26.10",
6666
"ast-kit": "^1.4.2",
6767
"magic-string-ast": "^0.8.0",
68-
"unplugin": "^2.2.0",
69-
"unplugin-utils": "^0.2.4"
68+
"unplugin": "^2.3.0"
7069
},
7170
"devDependencies": {
7271
"@antfu/utils": "^9.1.0",

pnpm-lock.yaml

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { toArray, type Arrayable } from '@antfu/utils'
22
import type { Transformer } from './types'
33
import type { ParserOptions } from '@babel/parser'
4-
import type { FilterPattern } from 'unplugin-utils'
4+
import type { FilterPattern } from 'unplugin'
55

66
export interface Options {
77
include?: FilterPattern
8-
exclude?: FilterPattern | undefined
8+
exclude?: FilterPattern
99
enforce?: 'post' | 'pre' | undefined
1010
parserOptions?: ParserOptions
1111
transformer?: Arrayable<Transformer<any>>
@@ -22,7 +22,7 @@ export type OptionsResolved = Overwrite<
2222
}
2323
>
2424

25-
export function resolveOption(options: Options): OptionsResolved {
25+
export function resolveOptions(options: Options): OptionsResolved {
2626
return {
2727
include: options.include || [/\.[jt]sx?$/],
2828
exclude: options.exclude || undefined,

src/index.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import { createUnplugin, type UnpluginInstance } from 'unplugin'
2-
import { createFilter } from 'unplugin-utils'
3-
import { resolveOption, type Options } from './core/options'
2+
import { resolveOptions, type Options } from './core/options'
43
import { transform } from './core/transform'
54

65
export const AST: UnpluginInstance<Options, false> = createUnplugin(
7-
(options = {}) => {
8-
const opt = resolveOption(options)
9-
const filter = createFilter(opt.include, opt.exclude)
6+
(userOptions = {}) => {
7+
const { include, exclude, enforce, ...options } =
8+
resolveOptions(userOptions)
109

1110
const name = 'unplugin-ast'
1211
return {
1312
name,
14-
enforce: options.enforce,
15-
16-
transformInclude(id) {
17-
return filter(id)
18-
},
19-
20-
transform(code, id) {
21-
return transform(code, id, opt)
13+
enforce,
14+
transform: {
15+
filter: { id: { include, exclude } },
16+
handler(code, id) {
17+
return transform(code, id, options)
18+
},
2219
},
2320
}
2421
},

0 commit comments

Comments
 (0)