Skip to content

Commit

Permalink
move recast
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Oct 26, 2024
1 parent db732f5 commit 33cdaa0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
3 changes: 1 addition & 2 deletions packages/internals/src/lib/ast/ast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { prettyPrint } from 'recast'
import { parse } from '@babel/parser'
import * as recast from 'recast'
import { prettyPrint as recastPrettyPrint } from 'recast'
Expand Down Expand Up @@ -83,4 +82,4 @@ export function parseTs(source: string | null) {
return parsed
}

export const { visit } = recast.types
export const { visit, builders } = recast.types
2 changes: 1 addition & 1 deletion packages/internals/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export {
getRelativePackagePath,
findFileOrUp,
} from './fs/fs.js'
export { parseTs, extractHtmlElementAttr_Text, visit, prettyPrint } from './ast/ast.js'
export { parseTs, extractHtmlElementAttr_Text, visit, prettyPrint, builders } from './ast/ast.js'
export type { Statement } from './ast/ast.js'
15 changes: 3 additions & 12 deletions packages/vite-plugin-stripper/src/lib/transformPackage.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { parse } from '@babel/parser'
import * as recast from 'recast'

const {
visit,
types: { builders },
} = recast
import { builders, parseTs, prettyPrint, visit } from '@kitql/internals'

export const removePackages = async (code: string, packages_to_strip: string[]) => {
try {
const ast = parse(code, {
plugins: ['typescript', 'decorators-legacy', 'importAssertions'],
sourceType: 'module',
})
const ast = parseTs(code)

const packages_striped: string[] = []

Expand Down Expand Up @@ -45,7 +36,7 @@ export const removePackages = async (code: string, packages_to_strip: string[])
})

return {
code: recast.print(ast).code,
code: prettyPrint(ast).code,
info: packages_striped.map((pkg) => `Replaced import from '${pkg}'`),
}
} catch (error) {
Expand Down

0 comments on commit 33cdaa0

Please sign in to comment.