hackmud-script-manager 0.20.5-97101bc → 0.21.1-0b2f476
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/bin/hsm.js +302 -262
- package/env.d.ts +364 -275
- package/generateTypeDeclaration.js +2 -1
- package/index.d.ts +3 -0
- package/index.js +3 -1
- package/package.json +39 -38
- package/processScript/index.d.ts +2 -2
- package/processScript/index.js +14 -11
- package/processScript/minify.js +11 -17
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/preprocess.js +7 -5
- package/processScript/transform.d.ts +3 -0
- package/processScript/transform.js +115 -97
- package/push.d.ts +10 -1
- package/push.js +40 -18
- package/watch.d.ts +2 -1
- package/watch.js +32 -29
@@ -1,5 +1,6 @@
|
|
1
1
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
2
|
import { basename, resolve } from "path"
|
3
|
+
import * as PathPosix from "path/posix"
|
3
4
|
async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
4
5
|
const users = new Set()
|
5
6
|
if (hackmudPath)
|
@@ -29,7 +30,7 @@ async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
|
29
30
|
}
|
30
31
|
})
|
31
32
|
)
|
32
|
-
sourceDirectory = resolve(sourceDirectory)
|
33
|
+
sourceDirectory = PathPosix.resolve(sourceDirectory)
|
33
34
|
let o = ""
|
34
35
|
for (const script of wildScripts) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
|
35
36
|
o += "\n"
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -7,6 +7,7 @@ export { syncMacros } from "./syncMacros.js"
|
|
7
7
|
export { watch } from "./watch.js"
|
8
8
|
import "@samual/lib/readDirectoryWithStats"
|
9
9
|
import "path"
|
10
|
+
import "path/posix"
|
10
11
|
import "@babel/generator"
|
11
12
|
import "@babel/parser"
|
12
13
|
import "@babel/plugin-proposal-decorators"
|
@@ -26,6 +27,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
26
27
|
import "@babel/plugin-transform-unicode-sets-regex"
|
27
28
|
import "@babel/traverse"
|
28
29
|
import "@babel/types"
|
30
|
+
import "@rollup/plugin-alias"
|
29
31
|
import "@rollup/plugin-babel"
|
30
32
|
import "@rollup/plugin-commonjs"
|
31
33
|
import "@rollup/plugin-json"
|
@@ -45,7 +47,7 @@ import "import-meta-resolve"
|
|
45
47
|
import "./processScript/transform.js"
|
46
48
|
import "@samual/lib/clearObject"
|
47
49
|
import "@samual/lib/copyFilePersistent"
|
48
|
-
import "@samual/lib/
|
50
|
+
import "@samual/lib/AutoMap"
|
49
51
|
import "@samual/lib/writeFilePersistent"
|
50
52
|
import "fs/promises"
|
51
53
|
import "chokidar"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.21.1-0b2f476",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -31,50 +31,51 @@
|
|
31
31
|
"url": "https://github.com/samualtnorman/hackmud-script-manager.git"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@babel/generator": "^7.
|
35
|
-
"@babel/parser": "^7.
|
36
|
-
"@babel/plugin-proposal-decorators": "^7.
|
37
|
-
"@babel/plugin-proposal-destructuring-private": "^7.
|
38
|
-
"@babel/plugin-proposal-do-expressions": "^7.
|
39
|
-
"@babel/plugin-proposal-explicit-resource-management": "^7.
|
40
|
-
"@babel/plugin-proposal-function-bind": "^7.
|
41
|
-
"@babel/plugin-proposal-function-sent": "^7.
|
42
|
-
"@babel/plugin-proposal-partial-application": "^7.
|
43
|
-
"@babel/plugin-proposal-pipeline-operator": "^7.
|
44
|
-
"@babel/plugin-proposal-record-and-tuple": "^7.
|
45
|
-
"@babel/plugin-proposal-throw-expressions": "^7.
|
46
|
-
"@babel/plugin-transform-class-properties": "^7.
|
47
|
-
"@babel/plugin-transform-class-static-block": "^7.
|
48
|
-
"@babel/plugin-transform-exponentiation-operator": "^7.
|
49
|
-
"@babel/plugin-transform-json-strings": "^7.
|
50
|
-
"@babel/plugin-transform-logical-assignment-operators": "^7.
|
51
|
-
"@babel/plugin-transform-nullish-coalescing-operator": "^7.
|
52
|
-
"@babel/plugin-transform-numeric-separator": "^7.
|
53
|
-
"@babel/plugin-transform-object-rest-spread": "^7.
|
54
|
-
"@babel/plugin-transform-optional-catch-binding": "^7.
|
55
|
-
"@babel/plugin-transform-optional-chaining": "^7.
|
56
|
-
"@babel/plugin-transform-private-property-in-object": "^7.
|
57
|
-
"@babel/plugin-transform-typescript": "^7.
|
58
|
-
"@babel/plugin-transform-unicode-sets-regex": "^7.
|
59
|
-
"@babel/traverse": "^7.
|
60
|
-
"@babel/types": "^7.
|
34
|
+
"@babel/generator": "^7.26.2",
|
35
|
+
"@babel/parser": "^7.26.2",
|
36
|
+
"@babel/plugin-proposal-decorators": "^7.25.9",
|
37
|
+
"@babel/plugin-proposal-destructuring-private": "^7.26.0",
|
38
|
+
"@babel/plugin-proposal-do-expressions": "^7.25.9",
|
39
|
+
"@babel/plugin-proposal-explicit-resource-management": "^7.25.9",
|
40
|
+
"@babel/plugin-proposal-function-bind": "^7.25.9",
|
41
|
+
"@babel/plugin-proposal-function-sent": "^7.25.9",
|
42
|
+
"@babel/plugin-proposal-partial-application": "^7.25.9",
|
43
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.25.9",
|
44
|
+
"@babel/plugin-proposal-record-and-tuple": "^7.25.9",
|
45
|
+
"@babel/plugin-proposal-throw-expressions": "^7.25.9",
|
46
|
+
"@babel/plugin-transform-class-properties": "^7.25.9",
|
47
|
+
"@babel/plugin-transform-class-static-block": "^7.26.0",
|
48
|
+
"@babel/plugin-transform-exponentiation-operator": "^7.25.9",
|
49
|
+
"@babel/plugin-transform-json-strings": "^7.25.9",
|
50
|
+
"@babel/plugin-transform-logical-assignment-operators": "^7.25.9",
|
51
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.25.9",
|
52
|
+
"@babel/plugin-transform-numeric-separator": "^7.25.9",
|
53
|
+
"@babel/plugin-transform-object-rest-spread": "^7.25.9",
|
54
|
+
"@babel/plugin-transform-optional-catch-binding": "^7.25.9",
|
55
|
+
"@babel/plugin-transform-optional-chaining": "^7.25.9",
|
56
|
+
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
57
|
+
"@babel/plugin-transform-typescript": "^7.25.9",
|
58
|
+
"@babel/plugin-transform-unicode-sets-regex": "^7.25.9",
|
59
|
+
"@babel/traverse": "^7.25.9",
|
60
|
+
"@babel/types": "^7.26.0",
|
61
61
|
"@bloomberg/record-tuple-polyfill": "^0.0.4",
|
62
|
+
"@rollup/plugin-alias": "^5.1.1",
|
62
63
|
"@rollup/plugin-babel": "^6.0.4",
|
63
|
-
"@rollup/plugin-commonjs": "^
|
64
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
64
65
|
"@rollup/plugin-json": "^6.1.0",
|
65
|
-
"@rollup/plugin-node-resolve": "^15.
|
66
|
-
"@samual/lib": "0.
|
67
|
-
"acorn": "^8.
|
66
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
67
|
+
"@samual/lib": "^0.13.0",
|
68
|
+
"acorn": "^8.14.0",
|
68
69
|
"chalk": "^5.3.0",
|
69
|
-
"chokidar": "^
|
70
|
-
"import-meta-resolve": "^4.
|
71
|
-
"prettier": "^3.
|
70
|
+
"chokidar": "^4.0.1",
|
71
|
+
"import-meta-resolve": "^4.1.0",
|
72
|
+
"prettier": "^3.3.3",
|
72
73
|
"proxy-polyfill": "^0.3.2",
|
73
|
-
"rollup": "^4.
|
74
|
-
"terser": "^5.
|
74
|
+
"rollup": "^4.27.4",
|
75
|
+
"terser": "^5.36.0"
|
75
76
|
},
|
76
77
|
"peerDependencies": {
|
77
|
-
"typescript": "5.4.5"
|
78
|
+
"typescript": "^5.4.5"
|
78
79
|
},
|
79
80
|
"type": "module",
|
80
81
|
"exports": {
|
package/processScript/index.d.ts
CHANGED
@@ -16,16 +16,16 @@ export type ProcessOptions = LaxPartial<{
|
|
16
16
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
17
17
|
*/
|
18
18
|
forceQuineCheats: boolean;
|
19
|
+
rootFolderPath: string;
|
19
20
|
}> & {
|
20
21
|
scriptName: string | true;
|
21
22
|
};
|
22
23
|
/** Minifies a given script
|
23
24
|
* @param code JavaScript or TypeScript code
|
24
25
|
* @param options {@link ProcessOptions details} */
|
25
|
-
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
26
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats, rootFolderPath }: ProcessOptions): Promise<{
|
26
27
|
script: string;
|
27
28
|
warnings: {
|
28
29
|
message: string;
|
29
|
-
line: number;
|
30
30
|
}[];
|
31
31
|
}>;
|
package/processScript/index.js
CHANGED
@@ -17,12 +17,13 @@ import babelPluginTransformPrivatePropertyInObject from "@babel/plugin-transform
|
|
17
17
|
import babelPluginTransformUnicodeSetsRegex from "@babel/plugin-transform-unicode-sets-regex"
|
18
18
|
import babelTraverse from "@babel/traverse"
|
19
19
|
import t from "@babel/types"
|
20
|
+
import rollupPluginAlias from "@rollup/plugin-alias"
|
20
21
|
import { babel } from "@rollup/plugin-babel"
|
21
22
|
import rollupPluginCommonJS from "@rollup/plugin-commonjs"
|
22
23
|
import rollupPluginJSON from "@rollup/plugin-json"
|
23
24
|
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
|
24
25
|
import { assert } from "@samual/lib/assert"
|
25
|
-
import {
|
26
|
+
import { relative } from "path"
|
26
27
|
import prettier from "prettier"
|
27
28
|
import { rollup } from "rollup"
|
28
29
|
import { supportedExtensions } from "../constants.js"
|
@@ -51,10 +52,11 @@ async function processScript(
|
|
51
52
|
scriptName,
|
52
53
|
filePath,
|
53
54
|
mangleNames = !1,
|
54
|
-
forceQuineCheats
|
55
|
+
forceQuineCheats,
|
56
|
+
rootFolderPath
|
55
57
|
}
|
56
58
|
) {
|
57
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
59
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:81:36")
|
58
60
|
const sourceCode = code
|
59
61
|
let autocomplete, statedSeclevel
|
60
62
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -115,7 +117,7 @@ async function processScript(
|
|
115
117
|
}
|
116
118
|
}
|
117
119
|
}
|
118
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
120
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:162:36")
|
119
121
|
const plugins = [
|
120
122
|
[babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
|
121
123
|
[babelPluginTransformClassProperties.default],
|
@@ -135,7 +137,7 @@ async function processScript(
|
|
135
137
|
]
|
136
138
|
let filePathResolved
|
137
139
|
if (filePath) {
|
138
|
-
filePathResolved =
|
140
|
+
filePathResolved = relative(".", filePath)
|
139
141
|
if (filePath.endsWith(".ts"))
|
140
142
|
plugins.push([
|
141
143
|
(await import("@babel/plugin-transform-typescript")).default,
|
@@ -204,6 +206,7 @@ async function processScript(
|
|
204
206
|
const bundle = await rollup({
|
205
207
|
input: filePathResolved,
|
206
208
|
plugins: [
|
209
|
+
rollupPluginJSON({ preferConst: !0 }),
|
207
210
|
{
|
208
211
|
name: "hackmud-script-manager",
|
209
212
|
async transform(code, id) {
|
@@ -228,13 +231,13 @@ async function processScript(
|
|
228
231
|
babel({ babelHelpers: "bundled", plugins, configFile: !1, extensions: supportedExtensions }),
|
229
232
|
rollupPluginCommonJS(),
|
230
233
|
rollupPluginNodeResolve({ extensions: supportedExtensions }),
|
231
|
-
|
234
|
+
!!rootFolderPath && rollupPluginAlias({ entries: [{ find: /^\//, replacement: rootFolderPath + "/" }] })
|
232
235
|
],
|
233
236
|
treeshake: { moduleSideEffects: !1 }
|
234
237
|
}),
|
235
238
|
seclevelNames = ["NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC"]
|
236
239
|
code = (await bundle.generate({})).output[0].code
|
237
|
-
const { file, seclevel } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
240
|
+
const { file, seclevel, warnings } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
238
241
|
uniqueId,
|
239
242
|
scriptUser,
|
240
243
|
scriptName
|
@@ -249,7 +252,7 @@ async function processScript(
|
|
249
252
|
traverse(file, {
|
250
253
|
MemberExpression({ node: memberExpression }) {
|
251
254
|
if (!memberExpression.computed) {
|
252
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
255
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:326:60")
|
253
256
|
if ("prototype" == memberExpression.property.name) {
|
254
257
|
memberExpression.computed = !0
|
255
258
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -279,7 +282,7 @@ async function processScript(
|
|
279
282
|
break
|
280
283
|
case "ObjectPattern":
|
281
284
|
for (const property of lValue.properties) {
|
282
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
285
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:356:51")
|
283
286
|
renameVariables(property.value)
|
284
287
|
}
|
285
288
|
break
|
@@ -323,11 +326,11 @@ async function processScript(
|
|
323
326
|
trailingComma: "none"
|
324
327
|
})
|
325
328
|
}
|
326
|
-
code = postprocess(code,
|
329
|
+
code = postprocess(code, uniqueId)
|
327
330
|
if (includesIllegalString(code))
|
328
331
|
throw Error(
|
329
332
|
'you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx'
|
330
333
|
)
|
331
|
-
return { script: code, warnings
|
334
|
+
return { script: code, warnings }
|
332
335
|
}
|
333
336
|
export { minify, postprocess, preprocess, processScript, transform }
|
package/processScript/minify.js
CHANGED
@@ -43,15 +43,6 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
43
43
|
)
|
44
44
|
}
|
45
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
46
|
const jsonValues = []
|
56
47
|
let scriptBeforeJSONValueReplacement,
|
57
48
|
comment,
|
@@ -61,7 +52,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
61
52
|
traverse(fileBeforeJSONValueReplacement, {
|
62
53
|
MemberExpression({ node: memberExpression }) {
|
63
54
|
if (!memberExpression.computed) {
|
64
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
55
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:115:60")
|
65
56
|
if ("prototype" == memberExpression.property.name) {
|
66
57
|
memberExpression.computed = !0
|
67
58
|
memberExpression.property = t.identifier(`_${uniqueId}_PROTOTYPE_PROPERTY_`)
|
@@ -173,7 +164,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
173
164
|
},
|
174
165
|
MemberExpression({ node: memberExpression }) {
|
175
166
|
if (!memberExpression.computed) {
|
176
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
167
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:249:62")
|
177
168
|
if (!(memberExpression.property.name.length < 3)) {
|
178
169
|
memberExpression.computed = !0
|
179
170
|
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
@@ -247,7 +238,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
247
238
|
})
|
248
239
|
await Promise.all(promises)
|
249
240
|
const functionDeclaration = file.program.body[0]
|
250
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
241
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:354:61")
|
251
242
|
if (jsonValues.length) {
|
252
243
|
hasComment = !0
|
253
244
|
if (1 == jsonValues.length)
|
@@ -259,7 +250,10 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
259
250
|
t.memberExpression(
|
260
251
|
t.taggedTemplateExpression(
|
261
252
|
t.memberExpression(
|
262
|
-
t.callExpression(
|
253
|
+
t.callExpression(
|
254
|
+
t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`),
|
255
|
+
[]
|
256
|
+
),
|
263
257
|
t.identifier("split")
|
264
258
|
),
|
265
259
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -283,7 +277,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
283
277
|
t.memberExpression(
|
284
278
|
t.taggedTemplateExpression(
|
285
279
|
t.memberExpression(
|
286
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
280
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
287
281
|
t.identifier("split")
|
288
282
|
),
|
289
283
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -308,7 +302,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
308
302
|
t.memberExpression(
|
309
303
|
t.taggedTemplateExpression(
|
310
304
|
t.memberExpression(
|
311
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
305
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
312
306
|
t.identifier("split")
|
313
307
|
),
|
314
308
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -364,7 +358,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
364
358
|
)
|
365
359
|
}
|
366
360
|
if (1 == forceQuineCheats) return code
|
367
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
361
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:485:43")
|
368
362
|
return (
|
369
363
|
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
370
364
|
countHackmudCharacters(code) + Number(hasComment)
|
@@ -380,7 +374,7 @@ function parseObjectExpression(node, o) {
|
|
380
374
|
"Identifier" == property.key.type ||
|
381
375
|
"NumericLiteral" == property.key.type ||
|
382
376
|
"StringLiteral" == property.key.type,
|
383
|
-
"src/processScript/minify.ts:
|
377
|
+
"src/processScript/minify.ts:507:4"
|
384
378
|
)
|
385
379
|
if ("ArrayExpression" == property.value.type) {
|
386
380
|
const childArray = []
|
@@ -1 +1 @@
|
|
1
|
-
export declare const postprocess: (code: string,
|
1
|
+
export declare const postprocess: (code: string, uniqueId: string) => string;
|
@@ -1,12 +1,12 @@
|
|
1
|
-
const postprocess = (code,
|
1
|
+
const postprocess = (code, uniqueId) =>
|
2
2
|
code
|
3
|
-
.replace(/^function\s
|
3
|
+
.replace(/^function\s*[\w$]+\(/, "function(")
|
4
4
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, "g"), "S\\C$")
|
5
5
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, "g"), "D\\B$")
|
6
6
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, "g"), "_\\_D_S")
|
7
7
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, "g"), "_\\_FMCL_")
|
8
8
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, "g"), "_\\_G_")
|
9
|
-
.replace(RegExp(`\\$${uniqueId}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"),
|
9
|
+
.replace(RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"), "#$1s.$2.$3")
|
10
10
|
.replace(RegExp(`\\$${uniqueId}\\$DEBUG\\$`, "g"), "#D")
|
11
11
|
.replace(RegExp(`\\$${uniqueId}\\$FMCL\\$`, "g"), "#FMCL")
|
12
12
|
.replace(RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, "g"), "#G")
|
@@ -8,7 +8,7 @@ import { resolve } from "import-meta-resolve"
|
|
8
8
|
const { default: traverse } = babelTraverse,
|
9
9
|
{ default: generate } = babelGenerator
|
10
10
|
async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
11
|
-
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:
|
11
|
+
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:23:36")
|
12
12
|
const sourceCode = code
|
13
13
|
let lengthBefore, file, program
|
14
14
|
do {
|
@@ -47,7 +47,7 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
|
47
47
|
})
|
48
48
|
break
|
49
49
|
} catch (error_) {
|
50
|
-
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:67:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -98,8 +98,10 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
|
98
98
|
t.stringLiteral(resolve("proxy-polyfill/src/proxy.js", import.meta.url).slice(7))
|
99
99
|
)
|
100
100
|
)
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
if (1 == program.node.body.length && "FunctionDeclaration" == program.node.body[0].type)
|
102
|
+
throw Error(
|
103
|
+
"Scripts that only contain a single function declaration are no longer supported.\nPrefix the function declaration with `export default`."
|
104
|
+
)
|
105
|
+
return { code: generate(file).code }
|
104
106
|
}
|
105
107
|
export { preprocess }
|
@@ -16,4 +16,7 @@ export type TransformOptions = LaxPartial<{
|
|
16
16
|
export declare function transform(file: File, sourceCode: string, { uniqueId, scriptUser, scriptName, seclevel }: TransformOptions): {
|
17
17
|
file: File;
|
18
18
|
seclevel: number;
|
19
|
+
warnings: {
|
20
|
+
message: string;
|
21
|
+
}[];
|
19
22
|
};
|