Skip to content

Commit 5ecf394

Browse files
committed
chore(core): use @ast-core/escape
1 parent 58d2971 commit 5ecf394

File tree

3 files changed

+36
-254
lines changed

3 files changed

+36
-254
lines changed

packages/core/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@
4242
"registry": "https://registry.npmjs.org/"
4343
},
4444
"dependencies": {
45+
"@ast-core/escape": "^1.0.0",
46+
"@babel/core": "^7.22.10",
4547
"@babel/helper-plugin-utils": "^7.22.5",
4648
"@babel/preset-typescript": "^7.22.5",
47-
"@babel/core": "^7.22.10",
4849
"@babel/types": "^7.22.10",
50+
"@tailwindcss-mangle/shared": "workspace:^",
51+
"magic-string": "^0.30.2",
4952
"parse5": "^7.1.2",
5053
"postcss": "^8.4.27",
51-
"postcss-selector-parser": "^6.0.13",
52-
"@tailwindcss-mangle/shared": "workspace:^",
53-
"magic-string": "^0.30.2"
54+
"postcss-selector-parser": "^6.0.13"
5455
},
5556
"devDependencies": {
5657
"@parse5/tools": "^0.2.0",

packages/core/src/js/pre.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,14 @@ import { declare } from '@babel/helper-plugin-utils'
33
import MagicString from 'magic-string'
44
import { splitCode } from '@tailwindcss-mangle/shared'
55
import { sort } from 'fast-sort'
6+
import { jsStringEscape } from '@ast-core/escape'
67
interface Options {
78
replaceMap: Map<string, string>
89
magicString: MagicString
910
id: string
1011
addToUsedBy: (key: string, file: string) => void
1112
}
1213

13-
export function jsStringEscape(str: unknown) {
14-
return ('' + str).replaceAll(/[\n\r"'\\\u2028\u2029]/g, (character) => {
15-
switch (character) {
16-
case '"':
17-
case "'":
18-
case '\\': {
19-
return '\\' + character
20-
}
21-
22-
case '\n': {
23-
return '\\n'
24-
}
25-
case '\r': {
26-
return '\\r'
27-
}
28-
case '\u2028': {
29-
return '\\u2028'
30-
}
31-
case '\u2029': {
32-
return '\\u2029'
33-
}
34-
default: {
35-
return character
36-
}
37-
}
38-
})
39-
}
40-
4114
export function handleValue(options: { raw: string; node: babel.types.StringLiteral | babel.types.TemplateElement; offset: number; escape: boolean } & Options) {
4215
const { addToUsedBy, id, magicString, node, raw, replaceMap, offset = 0, escape = false } = options
4316
let value = raw

0 commit comments

Comments
 (0)