Skip to content

Commit 3c27edd

Browse files
committed
fix regex backslashes getting duplicated
1 parent ffccc16 commit 3c27edd

3 files changed

Lines changed: 6 additions & 15 deletions

File tree

src/processScript/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ export async function processScript(
309309

310310
RegExpLiteral(path) {
311311
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
312-
.replace(/\\/g, `\\\\`)
313-
.replace(/\//g, `\\/`)
314-
315312
delete path.node.extra
316313
}
317314
})

src/processScript/minify.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ export async function minify(file: File, autocomplete?: string, {
158158

159159
RegExpLiteral(path) {
160160
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
161-
.replace(/\\/g, `\\\\`)
162-
.replace(/\//g, `\\/`)
163-
164161
delete path.node.extra
165162
}
166163
})
@@ -363,9 +360,6 @@ export async function minify(file: File, autocomplete?: string, {
363360

364361
RegExpLiteral(path) {
365362
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
366-
.replace(/\\/g, `\\\\`)
367-
.replace(/\//g, `\\/`)
368-
369363
delete path.node.extra
370364
}
371365
})

src/processScript/postprocess.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export function postprocess(code: string, seclevel: number, uniqueID: string) {
22
return code
33
.replace(/^function\s*\w+\(/, `function(`)
4-
.replace(new RegExp(`\\$${uniqueID}\\$\\\\\\\\\\$SC_DOLLAR\\$`, `g`), `SC\\$`)
5-
.replace(new RegExp(`\\$${uniqueID}\\$\\\\\\\\\\$DB_DOLLAR\\$`, `g`), `DB\\$`)
6-
.replace(new RegExp(`\\$${uniqueID}\\$\\\\\\\\\\$D\\$`, `g`), `__D_\\S`)
7-
.replace(new RegExp(`\\$${uniqueID}\\$\\\\\\\\\\$FMCL\\$`, `g`), `__FMCL\\_`)
8-
.replace(new RegExp(`\\$${uniqueID}\\$\\\\\\\\\\$G\\$`, `g`), `__G\\_`)
4+
.replace(new RegExp(`\\$${uniqueID}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, `g`), `S\\C$`)
5+
.replace(new RegExp(`\\$${uniqueID}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, `g`), `D\\B$`)
6+
.replace(new RegExp(`\\$${uniqueID}\\$\\\\(?:\\\\)?\\$D\\$`, `g`), `_\\_D_S`)
7+
.replace(new RegExp(`\\$${uniqueID}\\$\\\\(?:\\\\)?\\$FMCL\\$`, `g`), `_\\_FMCL_`)
8+
.replace(new RegExp(`\\$${uniqueID}\\$\\\\(?:\\\\)?\\$G\\$`, `g`), `_\\_G_`)
99
.replace(new RegExp(`\\$${uniqueID}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)`, `g`), `#${`nlmhf`[seclevel]}s.$1.$2`)
1010
.replace(new RegExp(`\\$${uniqueID}\\$DEBUG`, `g`), `#D`)
1111
.replace(new RegExp(`\\$${uniqueID}\\$FMCL`, `g`), `#FMCL`)
@@ -15,7 +15,7 @@ export function postprocess(code: string, seclevel: number, uniqueID: string) {
1515
.replace(new RegExp(`\\$${uniqueID}\\$NOT_A_SUBSCRIPT\\$(#[\\w\\.]+)\\(\\$`, `g`), `$1\\(`)
1616
.replace(new RegExp(`\\$${uniqueID}\\$NOT_A_DB_CALL\\$(\\w+)\\$`, `g`), `#db.$1\\(`)
1717
.replace(new RegExp(`\\$${uniqueID}\\$NOT_A_DEBUG_CALL\\$`, `g`), `#D\\(`)
18-
.replace(new RegExp(`\\$${uniqueID}\\$NOT_FMCL\\$`, `g`), `#FMC\\L`)
18+
.replace(new RegExp(`\\$${uniqueID}\\$NOT_FMCL\\$`, `g`), `#\\FMCL`)
1919
.replace(new RegExp(`\\$${uniqueID}\\$NOT_G\\$`, `g`), `#\\G`)
2020
}
2121

0 commit comments

Comments
 (0)