Skip to content

Commit

Permalink
chore: remove @babel/parser and @babel/traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
sonofmagic committed Sep 15, 2023
1 parent d26100f commit f0750a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
5 changes: 1 addition & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"@ast-core/escape": "^1.0.1",
"@babel/core": "^7.22.19",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/parser": "^7.22.16",
"@babel/preset-typescript": "^7.22.15",
"@babel/traverse": "^7.22.19",
"@babel/types": "^7.22.19",
"@tailwindcss-mangle/config": "workspace:^",
"@tailwindcss-mangle/shared": "workspace:^",
Expand All @@ -62,7 +60,6 @@
"devDependencies": {
"@parse5/tools": "^0.3.0",
"@types/babel__core": "^7.20.1",
"@types/babel__traverse": "^7.20.1",
"@types/micromatch": "^4.0.2",
"@vue/compiler-core": "^3.3.4",
"@vue/compiler-sfc": "^3.3.4"
Expand All @@ -78,4 +75,4 @@
"directories": {
"test": "test"
}
}
}
45 changes: 23 additions & 22 deletions packages/core/src/js/pre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import MagicString from 'magic-string'
import { splitCode } from '@tailwindcss-mangle/shared'
import { sort } from 'fast-sort'
import { jsStringEscape } from '@ast-core/escape'
import { parse, ParseResult } from '@babel/parser'
import traverse from '@babel/traverse'
import type { ParseResult } from '@babel/parser'
import { escapeStringRegexp } from '@/utils'
import type { Context } from '@/ctx'
import { between } from '@/math'
Expand Down Expand Up @@ -147,7 +146,7 @@ export function preProcessJs(options: IPreProcessJsOptions) {
return code
}
const markedArray: [number, number][] = []
traverse(ast, {
babel.traverse(ast, {
CallExpression: {
enter(p) {
const callee = p.get('callee')
Expand Down Expand Up @@ -230,34 +229,36 @@ export function preProcessRawCode(options: IPreProcessRawCodeOptions) {
}
// magicString.original.matchAll(regex)
for (const regExpMatch of allArr) {
let ast: ParseResult<babel.types.File>
let ast: ParseResult<babel.types.File> | null
try {
ast = parse(regExpMatch[0], {
ast = babel.parseSync(regExpMatch[0], {
sourceType: 'unambiguous'
})
traverse(ast, {
StringLiteral: {
enter(p) {
const arr = sort(splitCode(p.node.value)).desc((x) => x.length)

for (const v of arr) {
if (replaceMap.has(v)) {
ctx.addPreserveClass(v)
ast &&
babel.traverse(ast, {
StringLiteral: {
enter(p) {
const arr = sort(splitCode(p.node.value)).desc((x) => x.length)

for (const v of arr) {
if (replaceMap.has(v)) {
ctx.addPreserveClass(v)
}
}
}
}
},
TemplateElement: {
enter(p) {
const arr = sort(splitCode(p.node.value.raw)).desc((x) => x.length)
for (const v of arr) {
if (replaceMap.has(v)) {
ctx.addPreserveClass(v)
},
TemplateElement: {
enter(p) {
const arr = sort(splitCode(p.node.value.raw)).desc((x) => x.length)
for (const v of arr) {
if (replaceMap.has(v)) {
ctx.addPreserveClass(v)
}
}
}
}
}
})
})
} catch {
continue
}
Expand Down
9 changes: 0 additions & 9 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 f0750a4

Please sign in to comment.