hackmud-script-manager 0.19.1-64ab3ba → 0.19.1-6d8d544
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/bin/hsm.d.ts +0 -0
- package/bin/hsm.js +127 -283
- package/env.d.ts +1357 -0
- package/generateTypeDeclaration.d.ts +1 -2
- package/generateTypeDeclaration.js +2 -2
- package/index.d.ts +2 -2
- package/package.json +6 -7
- package/processScript/index.d.ts +17 -26
- package/processScript/index.js +257 -257
- package/processScript/minify.d.ts +15 -21
- package/processScript/minify.js +381 -395
- package/processScript/postprocess.d.ts +0 -1
- package/processScript/postprocess.js +1 -1
- package/processScript/preprocess.d.ts +6 -9
- package/processScript/preprocess.js +94 -94
- package/processScript/shared.d.ts +1 -1
- package/processScript/shared.js +11 -11
- package/processScript/transform.d.ts +13 -18
- package/processScript/transform.js +594 -559
- package/pull.d.ts +5 -9
- package/pull.js +2 -2
- package/push.d.ts +24 -33
- package/push.js +86 -217
- package/syncMacros.d.ts +1 -2
- package/syncMacros.js +3 -3
- package/typescript@5.3.3.patch +882 -0
- package/watch.d.ts +10 -16
- package/watch.js +20 -20
- package/tsconfig.tsbuildinfo +0 -1
package/processScript/minify.js
CHANGED
@@ -9,309 +9,249 @@ import * as terser from "terser"
|
|
9
9
|
import { getReferencePathsToGlobal, includesIllegalString, replaceUnsafeStrings } from "./shared.js"
|
10
10
|
const { default: generate } = babelGenerator,
|
11
11
|
{ default: traverse } = babelTraverse,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if (program.scope.hasGlobal("_START"))
|
22
|
-
for (const referencePath of getReferencePathsToGlobal("_START", program))
|
23
|
-
referencePath.replaceWith(t.identifier("_ST"))
|
24
|
-
if (program.scope.hasGlobal("_TIMEOUT"))
|
25
|
-
for (const referencePath of getReferencePathsToGlobal("_TIMEOUT", program))
|
26
|
-
referencePath.replaceWith(t.identifier("_TO"))
|
27
|
-
const mainFunctionPath = program.get("body.0")
|
28
|
-
for (const parameter of [...mainFunctionPath.node.params].reverse()) {
|
29
|
-
if ("Identifier" != parameter.type || mainFunctionPath.scope.getBinding(parameter.name).referenced) break
|
30
|
-
mainFunctionPath.node.params.pop()
|
31
|
-
}
|
32
|
-
for (const global in program.scope.globals) {
|
33
|
-
if ("arguments" == global || global.startsWith(`$${uniqueID}$`)) continue
|
34
|
-
const referencePaths = getReferencePathsToGlobal(global, program)
|
35
|
-
if (!(5 + global.length + referencePaths.length >= global.length * referencePaths.length)) {
|
36
|
-
for (const path of referencePaths) path.replaceWith(t.identifier(`_${uniqueID}_GLOBAL_${global}_`))
|
37
|
-
mainFunctionPath.node.body.body.unshift(
|
38
|
-
t.variableDeclaration("let", [
|
39
|
-
t.variableDeclarator(t.identifier(`_${uniqueID}_GLOBAL_${global}_`), t.identifier(global))
|
40
|
-
])
|
41
|
-
)
|
42
|
-
}
|
12
|
+
minifyNumber = async number =>
|
13
|
+
/\$\((?<number>.+)\)/.exec((await terser.minify(`$(${number})`, { ecma: 2015 })).code).groups.number
|
14
|
+
async function minify(file, { uniqueID = "00000000000", mangleNames = !1, forceQuineCheats, autocomplete } = {}) {
|
15
|
+
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/minify.ts:46:36")
|
16
|
+
let program
|
17
|
+
traverse(file, {
|
18
|
+
Program(path) {
|
19
|
+
program = path
|
20
|
+
path.skip()
|
43
21
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
22
|
+
})
|
23
|
+
if (program.scope.hasGlobal("_START"))
|
24
|
+
for (const referencePath of getReferencePathsToGlobal("_START", program))
|
25
|
+
referencePath.replaceWith(t.identifier("_ST"))
|
26
|
+
if (program.scope.hasGlobal("_TIMEOUT"))
|
27
|
+
for (const referencePath of getReferencePathsToGlobal("_TIMEOUT", program))
|
28
|
+
referencePath.replaceWith(t.identifier("_TO"))
|
29
|
+
const mainFunctionPath = program.get("body.0")
|
30
|
+
for (const parameter of [...mainFunctionPath.node.params].reverse()) {
|
31
|
+
if ("Identifier" != parameter.type || mainFunctionPath.scope.getBinding(parameter.name).referenced) break
|
32
|
+
mainFunctionPath.node.params.pop()
|
33
|
+
}
|
34
|
+
for (const global in program.scope.globals) {
|
35
|
+
if ("arguments" == global || global.startsWith(`$${uniqueID}$`)) continue
|
36
|
+
const referencePaths = getReferencePathsToGlobal(global, program)
|
37
|
+
if (!(5 + global.length + referencePaths.length >= global.length * referencePaths.length)) {
|
38
|
+
for (const path of referencePaths) path.replaceWith(t.identifier(`_${uniqueID}_GLOBAL_${global}_`))
|
47
39
|
mainFunctionPath.node.body.body.unshift(
|
48
40
|
t.variableDeclaration("let", [
|
49
|
-
t.variableDeclarator(t.identifier(`_${uniqueID}
|
41
|
+
t.variableDeclarator(t.identifier(`_${uniqueID}_GLOBAL_${global}_`), t.identifier(global))
|
50
42
|
])
|
51
43
|
)
|
52
44
|
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
45
|
+
}
|
46
|
+
const hashGReferencePaths = getReferencePathsToGlobal(`$${uniqueID}$GLOBAL$`, program)
|
47
|
+
if (hashGReferencePaths.length > 3) {
|
48
|
+
for (const path of hashGReferencePaths) path.replaceWith(t.identifier(`_${uniqueID}_G_`))
|
49
|
+
mainFunctionPath.node.body.body.unshift(
|
50
|
+
t.variableDeclaration("let", [
|
51
|
+
t.variableDeclarator(t.identifier(`_${uniqueID}_G_`), t.identifier(`$${uniqueID}$GLOBAL$`))
|
52
|
+
])
|
53
|
+
)
|
54
|
+
}
|
55
|
+
const jsonValues = []
|
56
|
+
let scriptBeforeJSONValueReplacement,
|
57
|
+
comment,
|
58
|
+
undefinedIsReferenced = !1
|
59
|
+
if (1 != forceQuineCheats) {
|
60
|
+
const fileBeforeJSONValueReplacement = t.cloneNode(file)
|
61
|
+
traverse(fileBeforeJSONValueReplacement, {
|
62
|
+
MemberExpression({ node: memberExpression }) {
|
63
|
+
if (!memberExpression.computed) {
|
64
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:127:60")
|
65
|
+
if ("prototype" == memberExpression.property.name) {
|
66
|
+
memberExpression.computed = !0
|
67
|
+
memberExpression.property = t.identifier(`_${uniqueID}_PROTOTYPE_PROPERTY_`)
|
68
|
+
} else if ("__proto__" == memberExpression.property.name) {
|
69
|
+
memberExpression.computed = !0
|
70
|
+
memberExpression.property = t.identifier(`_${uniqueID}_PROTO_PROPERTY_`)
|
71
|
+
} else if (includesIllegalString(memberExpression.property.name)) {
|
72
|
+
memberExpression.computed = !0
|
73
|
+
memberExpression.property = t.stringLiteral(
|
74
|
+
replaceUnsafeStrings(uniqueID, memberExpression.property.name)
|
75
|
+
)
|
81
76
|
}
|
82
|
-
},
|
83
|
-
StringLiteral({ node }) {
|
84
|
-
node.value = replaceUnsafeStrings(uniqueID, node.value)
|
85
|
-
},
|
86
|
-
TemplateLiteral({ node }) {
|
87
|
-
for (const templateElement of node.quasis)
|
88
|
-
if (templateElement.value.cooked) {
|
89
|
-
templateElement.value.cooked = replaceUnsafeStrings(uniqueID, templateElement.value.cooked)
|
90
|
-
templateElement.value.raw = templateElement.value.cooked
|
91
|
-
.replaceAll("\\", "\\\\")
|
92
|
-
.replaceAll("`", "\\`")
|
93
|
-
.replaceAll("${", "$\\{")
|
94
|
-
} else templateElement.value.raw = replaceUnsafeStrings(uniqueID, templateElement.value.raw)
|
95
|
-
},
|
96
|
-
RegExpLiteral(path) {
|
97
|
-
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
|
98
|
-
delete path.node.extra
|
99
77
|
}
|
78
|
+
},
|
79
|
+
ObjectProperty({ node: objectProperty }) {
|
80
|
+
if ("Identifier" == objectProperty.key.type && includesIllegalString(objectProperty.key.name)) {
|
81
|
+
objectProperty.key = t.stringLiteral(replaceUnsafeStrings(uniqueID, objectProperty.key.name))
|
82
|
+
objectProperty.shorthand = !1
|
83
|
+
}
|
84
|
+
},
|
85
|
+
StringLiteral({ node }) {
|
86
|
+
node.value = replaceUnsafeStrings(uniqueID, node.value)
|
87
|
+
},
|
88
|
+
TemplateLiteral({ node }) {
|
89
|
+
for (const templateElement of node.quasis)
|
90
|
+
if (templateElement.value.cooked) {
|
91
|
+
templateElement.value.cooked = replaceUnsafeStrings(uniqueID, templateElement.value.cooked)
|
92
|
+
templateElement.value.raw = templateElement.value.cooked
|
93
|
+
.replaceAll("\\", "\\\\")
|
94
|
+
.replaceAll("`", "\\`")
|
95
|
+
.replaceAll("${", "$\\{")
|
96
|
+
} else templateElement.value.raw = replaceUnsafeStrings(uniqueID, templateElement.value.raw)
|
97
|
+
},
|
98
|
+
RegExpLiteral(path) {
|
99
|
+
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
|
100
|
+
delete path.node.extra
|
101
|
+
}
|
102
|
+
})
|
103
|
+
scriptBeforeJSONValueReplacement = (
|
104
|
+
await terser.minify(generate(fileBeforeJSONValueReplacement).code, {
|
105
|
+
ecma: 2015,
|
106
|
+
compress: {
|
107
|
+
passes: 1 / 0,
|
108
|
+
unsafe: !0,
|
109
|
+
unsafe_arrows: !0,
|
110
|
+
unsafe_comps: !0,
|
111
|
+
unsafe_symbols: !0,
|
112
|
+
unsafe_methods: !0,
|
113
|
+
unsafe_proto: !0,
|
114
|
+
unsafe_regexp: !0,
|
115
|
+
unsafe_undefined: !0,
|
116
|
+
sequences: !1
|
117
|
+
},
|
118
|
+
format: { semicolons: !1 },
|
119
|
+
keep_classnames: !mangleNames,
|
120
|
+
keep_fnames: !mangleNames
|
100
121
|
})
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
122
|
+
).code
|
123
|
+
.replace(RegExp(`_${uniqueID}_PROTOTYPE_PROPERTY_`, "g"), '"prototype"')
|
124
|
+
.replace(RegExp(`_${uniqueID}_PROTO_PROPERTY_`, "g"), '"__proto__"')
|
125
|
+
autocomplete &&
|
126
|
+
(scriptBeforeJSONValueReplacement = spliceString(
|
127
|
+
scriptBeforeJSONValueReplacement,
|
128
|
+
`//${autocomplete}\n`,
|
129
|
+
getFunctionBodyStart(scriptBeforeJSONValueReplacement) + 1
|
130
|
+
))
|
131
|
+
if (0 == forceQuineCheats) return scriptBeforeJSONValueReplacement
|
132
|
+
}
|
133
|
+
let code,
|
134
|
+
hasComment = !1
|
135
|
+
{
|
136
|
+
const promises = []
|
137
|
+
traverse(file, {
|
138
|
+
FunctionDeclaration(path) {
|
139
|
+
path.traverse({
|
140
|
+
Function(path) {
|
141
|
+
"CallExpression" != path.parent.type && "callee" != path.parentKey && path.skip()
|
142
|
+
},
|
143
|
+
Loop: path => path.skip(),
|
144
|
+
ObjectExpression(path) {
|
145
|
+
const o = {}
|
146
|
+
parseObjectExpression(path.node, o) &&
|
147
|
+
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
115
148
|
},
|
116
|
-
|
117
|
-
|
118
|
-
|
149
|
+
ArrayExpression(path) {
|
150
|
+
const o = []
|
151
|
+
parseArrayExpression(path.node, o) &&
|
152
|
+
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
153
|
+
}
|
119
154
|
})
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
traverse(file, {
|
136
|
-
FunctionDeclaration(path) {
|
137
|
-
path.traverse({
|
138
|
-
Function(path) {
|
139
|
-
"CallExpression" != path.parent.type && "callee" != path.parentKey && path.skip()
|
140
|
-
},
|
141
|
-
Loop(path) {
|
142
|
-
path.skip()
|
143
|
-
},
|
144
|
-
ObjectExpression(path) {
|
145
|
-
const o = {}
|
146
|
-
parseObjectExpression(path.node, o) &&
|
147
|
-
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
148
|
-
},
|
149
|
-
ArrayExpression(path) {
|
150
|
-
const o = []
|
151
|
-
parseArrayExpression(path.node, o) &&
|
152
|
-
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
155
|
+
path.traverse({
|
156
|
+
TemplateLiteral(path) {
|
157
|
+
if ("TaggedTemplateExpression" == path.parent.type) return
|
158
|
+
const templateLiteral = path.node
|
159
|
+
let replacement = t.stringLiteral(templateLiteral.quasis[0].value.cooked)
|
160
|
+
for (let index = 0; index < templateLiteral.expressions.length; index++) {
|
161
|
+
const expression = templateLiteral.expressions[index],
|
162
|
+
templateElement = templateLiteral.quasis[index + 1]
|
163
|
+
replacement = t.binaryExpression("+", replacement, expression)
|
164
|
+
templateElement.value.cooked &&
|
165
|
+
(replacement = t.binaryExpression(
|
166
|
+
"+",
|
167
|
+
replacement,
|
168
|
+
t.stringLiteral(templateElement.value.cooked)
|
169
|
+
))
|
153
170
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
templateElement = templateLiteral.quasis[index + 1]
|
163
|
-
replacement = t.binaryExpression("+", replacement, expression)
|
164
|
-
templateElement.value.cooked &&
|
165
|
-
(replacement = t.binaryExpression(
|
166
|
-
"+",
|
167
|
-
replacement,
|
168
|
-
t.stringLiteral(templateElement.value.cooked)
|
169
|
-
))
|
170
|
-
}
|
171
|
-
path.replaceWith(replacement)
|
172
|
-
},
|
173
|
-
MemberExpression({ node: memberExpression }) {
|
174
|
-
if (!memberExpression.computed) {
|
175
|
-
assert("Identifier" == memberExpression.property.type)
|
176
|
-
if (!(memberExpression.property.name.length < 3)) {
|
177
|
-
memberExpression.computed = !0
|
178
|
-
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
179
|
-
}
|
171
|
+
path.replaceWith(replacement)
|
172
|
+
},
|
173
|
+
MemberExpression({ node: memberExpression }) {
|
174
|
+
if (!memberExpression.computed) {
|
175
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:259:62")
|
176
|
+
if (!(memberExpression.property.name.length < 3)) {
|
177
|
+
memberExpression.computed = !0
|
178
|
+
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
180
179
|
}
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
} else if ("-" == path.node.operator && "NumericLiteral" == path.node.argument.type) {
|
189
|
-
const value = -path.node.argument.value
|
190
|
-
promises.push(
|
191
|
-
(async () => {
|
192
|
-
if ((await minifyNumber(value)).length <= 3) return
|
193
|
-
"key" == path.parentKey &&
|
194
|
-
"ObjectProperty" == path.parent.type &&
|
195
|
-
(path.parent.computed = !0)
|
196
|
-
let jsonValueIndex = jsonValues.indexOf(value)
|
197
|
-
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(value))
|
198
|
-
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
199
|
-
})()
|
200
|
-
)
|
201
|
-
path.skip()
|
180
|
+
}
|
181
|
+
},
|
182
|
+
UnaryExpression(path) {
|
183
|
+
if ("void" == path.node.operator) {
|
184
|
+
if ("NumericLiteral" == path.node.argument.type && !path.node.argument.value) {
|
185
|
+
path.replaceWith(t.identifier(`_${uniqueID}_UNDEFINED_`))
|
186
|
+
undefinedIsReferenced = !0
|
202
187
|
}
|
203
|
-
}
|
204
|
-
|
205
|
-
let jsonValueIndex = jsonValues.indexOf(null)
|
206
|
-
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(null))
|
207
|
-
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
208
|
-
},
|
209
|
-
NumericLiteral(path) {
|
188
|
+
} else if ("-" == path.node.operator && "NumericLiteral" == path.node.argument.type) {
|
189
|
+
const value = -path.node.argument.value
|
210
190
|
promises.push(
|
211
191
|
(async () => {
|
212
|
-
if ((await minifyNumber(
|
192
|
+
if ((await minifyNumber(value)).length <= 3) return
|
213
193
|
"key" == path.parentKey &&
|
214
194
|
"ObjectProperty" == path.parent.type &&
|
215
195
|
(path.parent.computed = !0)
|
216
|
-
let jsonValueIndex = jsonValues.indexOf(
|
217
|
-
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(
|
196
|
+
let jsonValueIndex = jsonValues.indexOf(value)
|
197
|
+
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(value))
|
218
198
|
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
219
199
|
})()
|
220
200
|
)
|
221
|
-
|
222
|
-
StringLiteral(path) {
|
223
|
-
path.node.value = replaceUnsafeStrings(uniqueID, path.node.value)
|
224
|
-
if (JSON.stringify(path.node.value).includes("\\u00") || path.toString().length < 4) return
|
225
|
-
"key" == path.parentKey &&
|
226
|
-
"ObjectProperty" == path.parent.type &&
|
227
|
-
(path.parent.computed = !0)
|
228
|
-
let jsonValueIndex = jsonValues.indexOf(path.node.value)
|
229
|
-
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(path.node.value))
|
230
|
-
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
231
|
-
},
|
232
|
-
ObjectProperty({ node }) {
|
233
|
-
if (node.computed || "Identifier" != node.key.type || node.key.name.length < 4) return
|
234
|
-
let jsonValueIndex = jsonValues.indexOf(node.key.name)
|
235
|
-
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(node.key.name))
|
236
|
-
node.computed = !0
|
237
|
-
node.key = t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`)
|
238
|
-
},
|
239
|
-
RegExpLiteral(path) {
|
240
|
-
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
|
241
|
-
delete path.node.extra
|
201
|
+
path.skip()
|
242
202
|
}
|
243
|
-
}
|
244
|
-
path
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
variableDeclaration.declarations.push(
|
281
|
-
t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))
|
282
|
-
)
|
283
|
-
functionDeclaration.body.body.unshift(variableDeclaration)
|
284
|
-
comment = JSON.stringify(jsonValues[0])
|
285
|
-
} else {
|
286
|
-
const variableDeclaration = t.variableDeclaration("let", [
|
287
|
-
t.variableDeclarator(
|
288
|
-
t.identifier(`_${uniqueID}_JSON_VALUE_0_`),
|
289
|
-
t.memberExpression(
|
290
|
-
t.taggedTemplateExpression(
|
291
|
-
t.memberExpression(
|
292
|
-
t.callExpression(t.identifier(`$${uniqueID}$SUBSCRIPT$scripts$quine$`), []),
|
293
|
-
t.identifier("split")
|
294
|
-
),
|
295
|
-
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
296
|
-
),
|
297
|
-
t.identifier(`$${uniqueID}$SPLIT_INDEX$`),
|
298
|
-
!0
|
299
|
-
)
|
300
|
-
)
|
301
|
-
])
|
302
|
-
undefinedIsReferenced &&
|
303
|
-
variableDeclaration.declarations.push(
|
304
|
-
t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))
|
305
|
-
)
|
306
|
-
functionDeclaration.body.body.unshift(variableDeclaration)
|
307
|
-
comment = jsonValues[0]
|
203
|
+
},
|
204
|
+
NullLiteral(path) {
|
205
|
+
let jsonValueIndex = jsonValues.indexOf(null)
|
206
|
+
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(null))
|
207
|
+
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
208
|
+
},
|
209
|
+
NumericLiteral(path) {
|
210
|
+
promises.push(
|
211
|
+
(async () => {
|
212
|
+
if ((await minifyNumber(path.node.value)).length <= 3) return
|
213
|
+
"key" == path.parentKey &&
|
214
|
+
"ObjectProperty" == path.parent.type &&
|
215
|
+
(path.parent.computed = !0)
|
216
|
+
let jsonValueIndex = jsonValues.indexOf(path.node.value)
|
217
|
+
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(path.node.value))
|
218
|
+
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
219
|
+
})()
|
220
|
+
)
|
221
|
+
},
|
222
|
+
StringLiteral(path) {
|
223
|
+
path.node.value = replaceUnsafeStrings(uniqueID, path.node.value)
|
224
|
+
if (JSON.stringify(path.node.value).includes("\\u00") || path.toString().length < 4) return
|
225
|
+
"key" == path.parentKey && "ObjectProperty" == path.parent.type && (path.parent.computed = !0)
|
226
|
+
let jsonValueIndex = jsonValues.indexOf(path.node.value)
|
227
|
+
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(path.node.value))
|
228
|
+
path.replaceWith(t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`))
|
229
|
+
},
|
230
|
+
ObjectProperty({ node }) {
|
231
|
+
if (node.computed || "Identifier" != node.key.type || node.key.name.length < 4) return
|
232
|
+
let jsonValueIndex = jsonValues.indexOf(node.key.name)
|
233
|
+
;-1 == jsonValueIndex && (jsonValueIndex += jsonValues.push(node.key.name))
|
234
|
+
node.computed = !0
|
235
|
+
node.key = t.identifier(`_${uniqueID}_JSON_VALUE_${jsonValueIndex}_`)
|
236
|
+
},
|
237
|
+
RegExpLiteral(path) {
|
238
|
+
path.node.pattern = replaceUnsafeStrings(uniqueID, path.node.pattern)
|
239
|
+
delete path.node.extra
|
308
240
|
}
|
309
|
-
|
241
|
+
})
|
242
|
+
path.skip()
|
243
|
+
}
|
244
|
+
})
|
245
|
+
await Promise.all(promises)
|
246
|
+
const functionDeclaration = file.program.body[0]
|
247
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:363:61")
|
248
|
+
if (jsonValues.length) {
|
249
|
+
hasComment = !0
|
250
|
+
if (1 == jsonValues.length)
|
251
|
+
if ("string" != typeof jsonValues[0] || jsonValues[0].includes("\n") || jsonValues[0].includes("\t")) {
|
310
252
|
const variableDeclaration = t.variableDeclaration("let", [
|
311
253
|
t.variableDeclarator(
|
312
|
-
t.
|
313
|
-
jsonValues.map((_, index) => t.identifier(`_${uniqueID}_JSON_VALUE_${index}_`))
|
314
|
-
),
|
254
|
+
t.identifier(`_${uniqueID}_JSON_VALUE_0_`),
|
315
255
|
t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
|
316
256
|
t.memberExpression(
|
317
257
|
t.taggedTemplateExpression(
|
@@ -332,127 +272,173 @@ const { default: generate } = babelGenerator,
|
|
332
272
|
t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))
|
333
273
|
)
|
334
274
|
functionDeclaration.body.body.unshift(variableDeclaration)
|
335
|
-
comment = JSON.stringify(jsonValues)
|
275
|
+
comment = JSON.stringify(jsonValues[0])
|
276
|
+
} else {
|
277
|
+
const variableDeclaration = t.variableDeclaration("let", [
|
278
|
+
t.variableDeclarator(
|
279
|
+
t.identifier(`_${uniqueID}_JSON_VALUE_0_`),
|
280
|
+
t.memberExpression(
|
281
|
+
t.taggedTemplateExpression(
|
282
|
+
t.memberExpression(
|
283
|
+
t.callExpression(t.identifier(`$${uniqueID}$SUBSCRIPT$scripts$quine$`), []),
|
284
|
+
t.identifier("split")
|
285
|
+
),
|
286
|
+
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
287
|
+
),
|
288
|
+
t.identifier(`$${uniqueID}$SPLIT_INDEX$`),
|
289
|
+
!0
|
290
|
+
)
|
291
|
+
)
|
292
|
+
])
|
293
|
+
undefinedIsReferenced &&
|
294
|
+
variableDeclaration.declarations.push(
|
295
|
+
t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))
|
296
|
+
)
|
297
|
+
functionDeclaration.body.body.unshift(variableDeclaration)
|
298
|
+
comment = jsonValues[0]
|
336
299
|
}
|
337
|
-
} else
|
338
|
-
undefinedIsReferenced &&
|
339
|
-
functionDeclaration.body.body.unshift(
|
340
|
-
t.variableDeclaration("let", [t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))])
|
341
|
-
)
|
342
|
-
code = generate(file).code
|
343
|
-
}
|
344
|
-
code =
|
345
|
-
(
|
346
|
-
await terser.minify(code, {
|
347
|
-
ecma: 2015,
|
348
|
-
compress: {
|
349
|
-
passes: 1 / 0,
|
350
|
-
unsafe: !0,
|
351
|
-
unsafe_arrows: !0,
|
352
|
-
unsafe_comps: !0,
|
353
|
-
unsafe_symbols: !0,
|
354
|
-
unsafe_methods: !0,
|
355
|
-
unsafe_proto: !0,
|
356
|
-
unsafe_regexp: !0,
|
357
|
-
unsafe_undefined: !0,
|
358
|
-
sequences: !1
|
359
|
-
},
|
360
|
-
format: { semicolons: !1, wrap_func_args: !1 },
|
361
|
-
keep_classnames: !mangleNames,
|
362
|
-
keep_fnames: !mangleNames
|
363
|
-
})
|
364
|
-
).code || ""
|
365
|
-
if (null != comment) {
|
366
|
-
code = spliceString(
|
367
|
-
code,
|
368
|
-
`${autocomplete ? `//${autocomplete}\n` : ""}\n//\t${comment}\t\n`,
|
369
|
-
getFunctionBodyStart(code) + 1
|
370
|
-
)
|
371
|
-
code = code.replace(
|
372
|
-
`$${uniqueID}$SPLIT_INDEX$`,
|
373
|
-
await minifyNumber(code.split("\t").findIndex(part => part == comment))
|
374
|
-
)
|
375
|
-
}
|
376
|
-
if (1 == forceQuineCheats) return code
|
377
|
-
assert(scriptBeforeJSONValueReplacement)
|
378
|
-
return (
|
379
|
-
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
380
|
-
countHackmudCharacters(code) + Number(hasComment)
|
381
|
-
) ?
|
382
|
-
scriptBeforeJSONValueReplacement
|
383
|
-
: code
|
384
|
-
},
|
385
|
-
parseObjectExpression = (node, o) => {
|
386
|
-
if (!node.properties.length) return !1
|
387
|
-
for (const property of node.properties) {
|
388
|
-
if ("ObjectProperty" != property.type || property.computed) return !1
|
389
|
-
assert(
|
390
|
-
"Identifier" == property.key.type ||
|
391
|
-
"NumericLiteral" == property.key.type ||
|
392
|
-
"StringLiteral" == property.key.type
|
393
|
-
)
|
394
|
-
if ("ArrayExpression" == property.value.type) {
|
395
|
-
const childArray = []
|
396
|
-
if (!parseArrayExpression(property.value, childArray)) return !1
|
397
|
-
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childArray
|
398
|
-
} else if ("ObjectExpression" == property.value.type) {
|
399
|
-
const childObject = {}
|
400
|
-
if (!parseObjectExpression(property.value, childObject)) return !1
|
401
|
-
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childObject
|
402
|
-
} else if ("NullLiteral" == property.value.type)
|
403
|
-
o["Identifier" == property.key.type ? property.key.name : property.key.value] = null
|
404
|
-
else if (
|
405
|
-
"BooleanLiteral" == property.value.type ||
|
406
|
-
"NumericLiteral" == property.value.type ||
|
407
|
-
"StringLiteral" == property.value.type
|
408
|
-
)
|
409
|
-
o["Identifier" == property.key.type ? property.key.name : property.key.value] = property.value.value
|
410
300
|
else {
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
"NumericLiteral" == element.type ||
|
434
|
-
"StringLiteral" == element.type
|
435
|
-
)
|
436
|
-
o.push(element.value)
|
437
|
-
else {
|
438
|
-
if ("TemplateLiteral" != element.type || element.expressions.length) return !1
|
439
|
-
o.push(element.quasis[0].value.cooked)
|
301
|
+
const variableDeclaration = t.variableDeclaration("let", [
|
302
|
+
t.variableDeclarator(
|
303
|
+
t.arrayPattern(jsonValues.map((_, index) => t.identifier(`_${uniqueID}_JSON_VALUE_${index}_`))),
|
304
|
+
t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [
|
305
|
+
t.memberExpression(
|
306
|
+
t.taggedTemplateExpression(
|
307
|
+
t.memberExpression(
|
308
|
+
t.callExpression(t.identifier(`$${uniqueID}$SUBSCRIPT$scripts$quine$`), []),
|
309
|
+
t.identifier("split")
|
310
|
+
),
|
311
|
+
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
312
|
+
),
|
313
|
+
t.identifier(`$${uniqueID}$SPLIT_INDEX$`),
|
314
|
+
!0
|
315
|
+
)
|
316
|
+
])
|
317
|
+
)
|
318
|
+
])
|
319
|
+
undefinedIsReferenced &&
|
320
|
+
variableDeclaration.declarations.push(t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`)))
|
321
|
+
functionDeclaration.body.body.unshift(variableDeclaration)
|
322
|
+
comment = JSON.stringify(jsonValues)
|
440
323
|
}
|
324
|
+
} else
|
325
|
+
undefinedIsReferenced &&
|
326
|
+
functionDeclaration.body.body.unshift(
|
327
|
+
t.variableDeclaration("let", [t.variableDeclarator(t.identifier(`_${uniqueID}_UNDEFINED_`))])
|
328
|
+
)
|
329
|
+
code = generate(file).code
|
330
|
+
}
|
331
|
+
code =
|
332
|
+
(
|
333
|
+
await terser.minify(code, {
|
334
|
+
ecma: 2015,
|
335
|
+
compress: {
|
336
|
+
passes: 1 / 0,
|
337
|
+
unsafe: !0,
|
338
|
+
unsafe_arrows: !0,
|
339
|
+
unsafe_comps: !0,
|
340
|
+
unsafe_symbols: !0,
|
341
|
+
unsafe_methods: !0,
|
342
|
+
unsafe_proto: !0,
|
343
|
+
unsafe_regexp: !0,
|
344
|
+
unsafe_undefined: !0,
|
345
|
+
sequences: !1
|
346
|
+
},
|
347
|
+
format: { semicolons: !1, wrap_func_args: !1 },
|
348
|
+
keep_classnames: !mangleNames,
|
349
|
+
keep_fnames: !mangleNames
|
350
|
+
})
|
351
|
+
).code || ""
|
352
|
+
if (null != comment) {
|
353
|
+
code = spliceString(
|
354
|
+
code,
|
355
|
+
`${autocomplete ? `//${autocomplete}\n` : ""}\n//\t${comment}\t\n`,
|
356
|
+
getFunctionBodyStart(code) + 1
|
357
|
+
)
|
358
|
+
code = code.replace(
|
359
|
+
`$${uniqueID}$SPLIT_INDEX$`,
|
360
|
+
await minifyNumber(code.split("\t").findIndex(part => part == comment))
|
361
|
+
)
|
362
|
+
}
|
363
|
+
if (1 == forceQuineCheats) return code
|
364
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:494:43")
|
365
|
+
return (
|
366
|
+
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
367
|
+
countHackmudCharacters(code) + Number(hasComment)
|
368
|
+
) ?
|
369
|
+
scriptBeforeJSONValueReplacement
|
370
|
+
: code
|
371
|
+
}
|
372
|
+
function parseObjectExpression(node, o) {
|
373
|
+
if (!node.properties.length) return !1
|
374
|
+
for (const property of node.properties) {
|
375
|
+
if ("ObjectProperty" != property.type || property.computed) return !1
|
376
|
+
assert(
|
377
|
+
"Identifier" == property.key.type ||
|
378
|
+
"NumericLiteral" == property.key.type ||
|
379
|
+
"StringLiteral" == property.key.type,
|
380
|
+
"src/processScript/minify.ts:516:4"
|
381
|
+
)
|
382
|
+
if ("ArrayExpression" == property.value.type) {
|
383
|
+
const childArray = []
|
384
|
+
if (property.value.elements.length && !parseArrayExpression(property.value, childArray)) return !1
|
385
|
+
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childArray
|
386
|
+
} else if ("ObjectExpression" == property.value.type) {
|
387
|
+
const childObject = {}
|
388
|
+
if (property.value.properties.length && !parseObjectExpression(property.value, childObject)) return !1
|
389
|
+
o["Identifier" == property.key.type ? property.key.name : property.key.value] = childObject
|
390
|
+
} else if ("NullLiteral" == property.value.type)
|
391
|
+
o["Identifier" == property.key.type ? property.key.name : property.key.value] = null
|
392
|
+
else if (
|
393
|
+
"BooleanLiteral" == property.value.type ||
|
394
|
+
"NumericLiteral" == property.value.type ||
|
395
|
+
"StringLiteral" == property.value.type
|
396
|
+
)
|
397
|
+
o["Identifier" == property.key.type ? property.key.name : property.key.value] = property.value.value
|
398
|
+
else {
|
399
|
+
if ("TemplateLiteral" != property.value.type || property.value.expressions.length) return !1
|
400
|
+
o["Identifier" == property.key.type ? property.key.name : property.key.value] =
|
401
|
+
property.value.quasis[0].value.cooked
|
441
402
|
}
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
403
|
+
}
|
404
|
+
return !0
|
405
|
+
}
|
406
|
+
function parseArrayExpression(node, o) {
|
407
|
+
if (!node.elements.length) return !1
|
408
|
+
for (const element of node.elements) {
|
409
|
+
if (!element) return !1
|
410
|
+
if ("ArrayExpression" == element.type) {
|
411
|
+
const childArray = []
|
412
|
+
if (!element.elements.length && parseArrayExpression(element, childArray)) return !1
|
413
|
+
o.push(childArray)
|
414
|
+
} else if ("ObjectExpression" == element.type) {
|
415
|
+
const childObject = {}
|
416
|
+
if (element.properties.length && !parseObjectExpression(element, childObject)) return !1
|
417
|
+
o.push(childObject)
|
418
|
+
} else if ("NullLiteral" == element.type) o.push(null)
|
419
|
+
else if (
|
420
|
+
"BooleanLiteral" == element.type ||
|
421
|
+
"NumericLiteral" == element.type ||
|
422
|
+
"StringLiteral" == element.type
|
423
|
+
)
|
424
|
+
o.push(element.value)
|
425
|
+
else {
|
426
|
+
if ("TemplateLiteral" != element.type || element.expressions.length) return !1
|
427
|
+
o.push(element.quasis[0].value.cooked)
|
455
428
|
}
|
456
|
-
return tokens.getToken().start
|
457
429
|
}
|
458
|
-
|
430
|
+
return !0
|
431
|
+
}
|
432
|
+
function getFunctionBodyStart(code) {
|
433
|
+
const tokens = tokenizer(code, { ecmaVersion: 2015 })
|
434
|
+
tokens.getToken()
|
435
|
+
tokens.getToken()
|
436
|
+
tokens.getToken()
|
437
|
+
let nests = 1
|
438
|
+
for (; nests; ) {
|
439
|
+
const token = tokens.getToken()
|
440
|
+
token.type == tokTypes.parenL ? nests++ : token.type == tokTypes.parenR && nests--
|
441
|
+
}
|
442
|
+
return tokens.getToken().start
|
443
|
+
}
|
444
|
+
export { minify }
|