Skip to content

Commit

Permalink
fix: use inline createFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 29, 2022
1 parent 3a931b8 commit d15ddcc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/utils/basic.ts
@@ -1,4 +1,4 @@
export function toArray<T>(value: T | T[] = []): T[] {
export function toArray<T>(value: T | readonly T[] = []): T[] {
return Array.isArray(value) ? value : [value]
}

Expand Down
1 change: 0 additions & 1 deletion packages/transformer-attributify-jsx/package.json
Expand Up @@ -39,7 +39,6 @@
"@unocss/core": "workspace:*"
},
"devDependencies": {
"@rollup/pluginutils": "^4.2.1",
"magic-string": "^0.26.2"
}
}
15 changes: 14 additions & 1 deletion packages/transformer-attributify-jsx/src/index.ts
@@ -1,8 +1,21 @@
import type { SourceCodeTransformer } from '@unocss/core'
import { createFilter } from '@rollup/pluginutils'
import { toArray } from '@unocss/core'

export type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null

function createFilter(
include: FilterPattern,
exclude: FilterPattern,
): (id: string) => boolean {
const includePattern = toArray(include || [])
const excludePattern = toArray(exclude || [])
return (id: string) => {
if (excludePattern.some(p => id.match(p)))
return false
return includePattern.some(p => id.match(p))
}
}

export interface TransformerAttributifyJsxOptions {
/**
* the list of attributes to ignore
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d15ddcc

Please sign in to comment.