Skip to content

Commit f0750a4

Browse files
committed
chore: remove @babel/parser and @babel/traverse
1 parent d26100f commit f0750a4

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

packages/core/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
"@ast-core/escape": "^1.0.1",
4747
"@babel/core": "^7.22.19",
4848
"@babel/helper-plugin-utils": "^7.22.5",
49-
"@babel/parser": "^7.22.16",
5049
"@babel/preset-typescript": "^7.22.15",
51-
"@babel/traverse": "^7.22.19",
5250
"@babel/types": "^7.22.19",
5351
"@tailwindcss-mangle/config": "workspace:^",
5452
"@tailwindcss-mangle/shared": "workspace:^",
@@ -62,7 +60,6 @@
6260
"devDependencies": {
6361
"@parse5/tools": "^0.3.0",
6462
"@types/babel__core": "^7.20.1",
65-
"@types/babel__traverse": "^7.20.1",
6663
"@types/micromatch": "^4.0.2",
6764
"@vue/compiler-core": "^3.3.4",
6865
"@vue/compiler-sfc": "^3.3.4"
@@ -78,4 +75,4 @@
7875
"directories": {
7976
"test": "test"
8077
}
81-
}
78+
}

packages/core/src/js/pre.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import MagicString from 'magic-string'
44
import { splitCode } from '@tailwindcss-mangle/shared'
55
import { sort } from 'fast-sort'
66
import { jsStringEscape } from '@ast-core/escape'
7-
import { parse, ParseResult } from '@babel/parser'
8-
import traverse from '@babel/traverse'
7+
import type { ParseResult } from '@babel/parser'
98
import { escapeStringRegexp } from '@/utils'
109
import type { Context } from '@/ctx'
1110
import { between } from '@/math'
@@ -147,7 +146,7 @@ export function preProcessJs(options: IPreProcessJsOptions) {
147146
return code
148147
}
149148
const markedArray: [number, number][] = []
150-
traverse(ast, {
149+
babel.traverse(ast, {
151150
CallExpression: {
152151
enter(p) {
153152
const callee = p.get('callee')
@@ -230,34 +229,36 @@ export function preProcessRawCode(options: IPreProcessRawCodeOptions) {
230229
}
231230
// magicString.original.matchAll(regex)
232231
for (const regExpMatch of allArr) {
233-
let ast: ParseResult<babel.types.File>
232+
let ast: ParseResult<babel.types.File> | null
234233
try {
235-
ast = parse(regExpMatch[0], {
234+
ast = babel.parseSync(regExpMatch[0], {
236235
sourceType: 'unambiguous'
237236
})
238-
traverse(ast, {
239-
StringLiteral: {
240-
enter(p) {
241-
const arr = sort(splitCode(p.node.value)).desc((x) => x.length)
242237

243-
for (const v of arr) {
244-
if (replaceMap.has(v)) {
245-
ctx.addPreserveClass(v)
238+
ast &&
239+
babel.traverse(ast, {
240+
StringLiteral: {
241+
enter(p) {
242+
const arr = sort(splitCode(p.node.value)).desc((x) => x.length)
243+
244+
for (const v of arr) {
245+
if (replaceMap.has(v)) {
246+
ctx.addPreserveClass(v)
247+
}
246248
}
247249
}
248-
}
249-
},
250-
TemplateElement: {
251-
enter(p) {
252-
const arr = sort(splitCode(p.node.value.raw)).desc((x) => x.length)
253-
for (const v of arr) {
254-
if (replaceMap.has(v)) {
255-
ctx.addPreserveClass(v)
250+
},
251+
TemplateElement: {
252+
enter(p) {
253+
const arr = sort(splitCode(p.node.value.raw)).desc((x) => x.length)
254+
for (const v of arr) {
255+
if (replaceMap.has(v)) {
256+
ctx.addPreserveClass(v)
257+
}
256258
}
257259
}
258260
}
259-
}
260-
})
261+
})
261262
} catch {
262263
continue
263264
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)