hackmud-script-manager 0.19.1-003b022 → 0.19.1-02bed1a
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 -291
- package/env.d.ts +1657 -0
- package/generateTypeDeclaration.d.ts +1 -2
- package/generateTypeDeclaration.js +2 -2
- package/index.d.ts +2 -2
- package/package.json +10 -8
- package/processScript/index.d.ts +17 -26
- package/processScript/index.js +258 -241
- package/processScript/minify.d.ts +15 -21
- package/processScript/minify.js +385 -399
- package/processScript/postprocess.d.ts +1 -2
- package/processScript/postprocess.js +18 -18
- package/processScript/preprocess.d.ts +7 -10
- package/processScript/preprocess.js +94 -94
- package/processScript/shared.d.ts +2 -2
- package/processScript/shared.js +23 -23
- package/processScript/transform.d.ts +13 -18
- package/processScript/transform.js +596 -561
- 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/watch.d.ts +10 -16
- package/watch.js +24 -24
- package/tsconfig.tsbuildinfo +0 -1
@@ -1,2 +1 @@
|
|
1
|
-
export declare const postprocess: (code: string, seclevel: number,
|
2
|
-
export default postprocess;
|
1
|
+
export declare const postprocess: (code: string, seclevel: number, uniqueId: string) => string;
|
@@ -1,20 +1,20 @@
|
|
1
|
-
const postprocess = (code, seclevel,
|
1
|
+
const postprocess = (code, seclevel, uniqueId) =>
|
2
2
|
code
|
3
3
|
.replace(/^function\s*\w+\(/, "function(")
|
4
|
-
.replace(RegExp(`\\$${
|
5
|
-
.replace(RegExp(`\\$${
|
6
|
-
.replace(RegExp(`\\$${
|
7
|
-
.replace(RegExp(`\\$${
|
8
|
-
.replace(RegExp(`\\$${
|
9
|
-
.replace(RegExp(`\\$${
|
10
|
-
.replace(RegExp(`\\$${
|
11
|
-
.replace(RegExp(`\\$${
|
12
|
-
.replace(RegExp(`\\$${
|
13
|
-
.replace(RegExp(`\\$${
|
14
|
-
.replace(RegExp(`\\$${
|
15
|
-
.replace(RegExp(`\\$${
|
16
|
-
.replace(RegExp(`\\$${
|
17
|
-
.replace(RegExp(`\\$${
|
18
|
-
.replace(RegExp(`\\$${
|
19
|
-
.replace(RegExp(`\\$${
|
20
|
-
export { postprocess
|
4
|
+
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, "g"), "S\\C$")
|
5
|
+
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, "g"), "D\\B$")
|
6
|
+
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, "g"), "_\\_D_S")
|
7
|
+
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, "g"), "_\\_FMCL_")
|
8
|
+
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, "g"), "_\\_G_")
|
9
|
+
.replace(RegExp(`\\$${uniqueId}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"), `#${"nlmhf"[seclevel]}s.$1.$2`)
|
10
|
+
.replace(RegExp(`\\$${uniqueId}\\$DEBUG\\$`, "g"), "#D")
|
11
|
+
.replace(RegExp(`\\$${uniqueId}\\$FMCL\\$`, "g"), "#FMCL")
|
12
|
+
.replace(RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, "g"), "#G")
|
13
|
+
.replace(RegExp(`\\$${uniqueId}\\$DB\\$(\\w+)\\$`, "g"), "#db.$1")
|
14
|
+
.replace(RegExp(`\\$${uniqueId}\\$SLASH_SLASH\\$`, "g"), "/\\/")
|
15
|
+
.replace(RegExp(`\\$${uniqueId}\\$NOT_A_SUBSCRIPT\\$(#[\\w\\.]+)\\(\\$`, "g"), "$1\\(")
|
16
|
+
.replace(RegExp(`\\$${uniqueId}\\$NOT_A_DB_CALL\\$(\\w+)\\$`, "g"), "#db.$1\\(")
|
17
|
+
.replace(RegExp(`\\$${uniqueId}\\$NOT_A_DEBUG_CALL\\$`, "g"), "#D\\(")
|
18
|
+
.replace(RegExp(`\\$${uniqueId}\\$NOT_FMCL\\$`, "g"), "#\\FMCL")
|
19
|
+
.replace(RegExp(`\\$${uniqueId}\\$NOT_G\\$`, "g"), "#\\G")
|
20
|
+
export { postprocess }
|
@@ -1,12 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
}
|
5
|
-
/**
|
6
|
-
|
7
|
-
|
8
|
-
*/
|
9
|
-
export declare const preprocess: (code: string, { uniqueID }?: Partial<PreprocessOptions>) => Promise<{
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
export type PreprocessOptions = LaxPartial<{
|
3
|
+
uniqueId: string;
|
4
|
+
}>;
|
5
|
+
/** @param code source code for preprocessing
|
6
|
+
* @param options {@link PreprocessOptions details} */
|
7
|
+
export declare function preprocess(code: string, { uniqueId }?: PreprocessOptions): Promise<{
|
10
8
|
code: string;
|
11
9
|
}>;
|
12
|
-
export default preprocess;
|
@@ -6,100 +6,100 @@ import { assert } from "@samual/lib/assert"
|
|
6
6
|
import { spliceString } from "@samual/lib/spliceString"
|
7
7
|
import { resolve } from "import-meta-resolve"
|
8
8
|
const { default: traverse } = babelTraverse,
|
9
|
-
{ default: generate } = babelGenerator
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
54
|
-
console.log(/.+/.exec(code.slice(error.pos))?.[0])
|
55
|
-
throw error
|
56
|
-
}
|
57
|
-
const codeSlice = code.slice(error.pos)
|
58
|
-
let match
|
59
|
-
if ((match = /^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(codeSlice)))
|
60
|
-
code = spliceString(code, JSON.stringify(sourceCode), error.pos, match[0].length)
|
61
|
-
else if ((match = /^#[0-4fhmln]?s\./.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
|
62
|
-
else if ((match = /^#D[^\w$]/.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
|
63
|
-
else if ((match = /^#FMCL/.exec(codeSlice)))
|
64
|
-
code = spliceString(code, `$${uniqueID}$FMCL$`, error.pos, match[0].length)
|
65
|
-
else if ((match = /^#G/.exec(codeSlice)))
|
66
|
-
code = spliceString(code, `$${uniqueID}$GLOBAL$`, error.pos, match[0].length)
|
67
|
-
else {
|
68
|
-
if (!(match = /^#db\./.exec(codeSlice))) throw error
|
69
|
-
code = spliceString(code, "$", error.pos, 1)
|
70
|
-
}
|
9
|
+
{ default: generate } = babelGenerator
|
10
|
+
async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
11
|
+
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:22:36")
|
12
|
+
const sourceCode = code
|
13
|
+
let lengthBefore, file, program
|
14
|
+
do {
|
15
|
+
lengthBefore = code.length
|
16
|
+
code = code
|
17
|
+
.replace(/^\s+/, "")
|
18
|
+
.replace(/^\/\/.*/, "")
|
19
|
+
.replace(/^\/\*[\s\S]*?\*\//, "")
|
20
|
+
} while (code.length != lengthBefore)
|
21
|
+
code = code.replace(/^function\s*\(/, "export default function (")
|
22
|
+
for (;;) {
|
23
|
+
let error
|
24
|
+
try {
|
25
|
+
file = parse(code, {
|
26
|
+
plugins: [
|
27
|
+
"typescript",
|
28
|
+
["decorators", { decoratorsBeforeExport: !0 }],
|
29
|
+
"doExpressions",
|
30
|
+
"functionBind",
|
31
|
+
"functionSent",
|
32
|
+
"partialApplication",
|
33
|
+
["pipelineOperator", { proposal: "hack", topicToken: "%" }],
|
34
|
+
"throwExpressions",
|
35
|
+
["recordAndTuple", { syntaxType: "hash" }],
|
36
|
+
"classProperties",
|
37
|
+
"classPrivateProperties",
|
38
|
+
"classPrivateMethods",
|
39
|
+
"logicalAssignment",
|
40
|
+
"numericSeparator",
|
41
|
+
"nullishCoalescingOperator",
|
42
|
+
"optionalChaining",
|
43
|
+
"optionalCatchBinding",
|
44
|
+
"objectRestSpread"
|
45
|
+
],
|
46
|
+
sourceType: "module"
|
47
|
+
})
|
48
|
+
break
|
49
|
+
} catch (error_) {
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:66:42")
|
51
|
+
error = error_
|
71
52
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
53
|
+
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
54
|
+
console.log(/.+/.exec(code.slice(error.pos))?.[0])
|
55
|
+
throw error
|
56
|
+
}
|
57
|
+
const codeSlice = code.slice(error.pos)
|
58
|
+
let match
|
59
|
+
if ((match = /^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(codeSlice)))
|
60
|
+
code = spliceString(code, JSON.stringify(sourceCode), error.pos, match[0].length)
|
61
|
+
else if ((match = /^#[0-4fhmln]?s\./.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
|
62
|
+
else if ((match = /^#D[^\w$]/.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
|
63
|
+
else if ((match = /^#FMCL/.exec(codeSlice)))
|
64
|
+
code = spliceString(code, `$${uniqueId}$FMCL$`, error.pos, match[0].length)
|
65
|
+
else if ((match = /^#G/.exec(codeSlice)))
|
66
|
+
code = spliceString(code, `$${uniqueId}$GLOBAL$`, error.pos, match[0].length)
|
67
|
+
else {
|
68
|
+
if (!(match = /^#db\./.exec(codeSlice))) throw error
|
69
|
+
code = spliceString(code, "$", error.pos, 1)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
traverse(file, {
|
73
|
+
Program(path) {
|
74
|
+
program = path
|
75
|
+
path.skip()
|
76
|
+
}
|
77
|
+
})
|
78
|
+
const needRecord = program.scope.hasGlobal("Record"),
|
79
|
+
needTuple = program.scope.hasGlobal("Tuple")
|
80
|
+
;(needRecord || needTuple) &&
|
81
|
+
file.program.body.unshift(
|
82
|
+
t.importDeclaration(
|
83
|
+
needRecord ?
|
84
|
+
needTuple ?
|
85
|
+
[
|
86
|
+
t.importSpecifier(t.identifier("Record"), t.identifier("Record")),
|
87
|
+
t.importSpecifier(t.identifier("Tuple"), t.identifier("Tuple"))
|
88
|
+
]
|
89
|
+
: [t.importSpecifier(t.identifier("Record"), t.identifier("Record"))]
|
90
|
+
: [t.importSpecifier(t.identifier("Tuple"), t.identifier("Tuple"))],
|
91
|
+
t.stringLiteral("@bloomberg/record-tuple-polyfill")
|
93
92
|
)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
)
|
93
|
+
)
|
94
|
+
program.scope.hasGlobal("Proxy") &&
|
95
|
+
file.program.body.unshift(
|
96
|
+
t.importDeclaration(
|
97
|
+
[t.importDefaultSpecifier(t.identifier("Proxy"))],
|
98
|
+
t.stringLiteral(resolve("proxy-polyfill/src/proxy.js", import.meta.url).slice(7))
|
100
99
|
)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
|
100
|
+
)
|
101
|
+
return 1 == program.node.body.length && "FunctionDeclaration" == program.node.body[0].type ?
|
102
|
+
{ code: "export default " + generate(file).code }
|
103
|
+
: { code: generate(file).code }
|
104
|
+
}
|
105
|
+
export { preprocess }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { NodePath } from "@babel/traverse";
|
2
2
|
import type { Identifier, Program } from "@babel/types";
|
3
|
-
export declare
|
3
|
+
export declare function getReferencePathsToGlobal(name: string, program: NodePath<Program>): NodePath<Identifier>[];
|
4
4
|
export declare const includesIllegalString: (toCheck: string) => boolean;
|
5
|
-
export declare const replaceUnsafeStrings: (
|
5
|
+
export declare const replaceUnsafeStrings: (uniqueId: string, toReplace: string) => string;
|
package/processScript/shared.js
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
import t from "@babel/types"
|
2
2
|
import { ensure } from "@samual/lib/assert"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
function getReferencePathsToGlobal(name, program) {
|
4
|
+
const [variableDeclaration] = program.unshiftContainer(
|
5
|
+
"body",
|
6
|
+
t.variableDeclaration("let", [t.variableDeclarator(t.identifier(name))])
|
7
|
+
)
|
8
|
+
program.scope.crawl()
|
9
|
+
const binding = ensure(program.scope.getBinding(name), "src/processScript/shared.ts:12:57")
|
10
|
+
variableDeclaration.remove()
|
11
|
+
return binding.referencePaths
|
12
|
+
}
|
13
|
+
const includesIllegalString = toCheck =>
|
14
14
|
toCheck.includes("SC$") ||
|
15
15
|
toCheck.includes("DB$") ||
|
16
16
|
toCheck.includes("__D_S") ||
|
17
17
|
toCheck.includes("__FMCL_") ||
|
18
18
|
toCheck.includes("__G_"),
|
19
|
-
replaceUnsafeStrings = (
|
19
|
+
replaceUnsafeStrings = (uniqueId, toReplace) =>
|
20
20
|
toReplace
|
21
|
-
.replaceAll("SC$", `$${
|
22
|
-
.replaceAll("DB$", `$${
|
23
|
-
.replaceAll("__D_S", `$${
|
24
|
-
.replaceAll("__FMCL_", `$${
|
25
|
-
.replaceAll("__G_", `$${
|
26
|
-
.replaceAll("//", `$${
|
27
|
-
.replaceAll(/#[0-4fhmln]?s(?:\.[_a-z][\d_a-z]{0,24}){2}\(/g, `$${
|
28
|
-
.replaceAll(/#db\.(?<methodName>[irfu]|u1|us|ObjectId)\(/g, `$${
|
29
|
-
.replaceAll("#D(", `$${
|
30
|
-
.replaceAll("#FMCL", `$${
|
31
|
-
.replaceAll("#G", `$${
|
21
|
+
.replaceAll("SC$", `$${uniqueId}$\\$SC_DOLLAR$`)
|
22
|
+
.replaceAll("DB$", `$${uniqueId}$\\$DB_DOLLAR$`)
|
23
|
+
.replaceAll("__D_S", `$${uniqueId}$\\$D$`)
|
24
|
+
.replaceAll("__FMCL_", `$${uniqueId}$\\$FMCL$`)
|
25
|
+
.replaceAll("__G_", `$${uniqueId}$\\$G$`)
|
26
|
+
.replaceAll("//", `$${uniqueId}$SLASH_SLASH$`)
|
27
|
+
.replaceAll(/#[0-4fhmln]?s(?:\.[_a-z][\d_a-z]{0,24}){2}\(/g, `$${uniqueId}$NOT_A_SUBSCRIPT$$$&$`)
|
28
|
+
.replaceAll(/#db\.(?<methodName>[irfu]|u1|us|ObjectId)\(/g, `$${uniqueId}$NOT_A_DB_CALL$$$1$`)
|
29
|
+
.replaceAll("#D(", `$${uniqueId}$NOT_A_DEBUG_CALL$`)
|
30
|
+
.replaceAll("#FMCL", `$${uniqueId}$NOT_FMCL$`)
|
31
|
+
.replaceAll("#G", `$${uniqueId}$NOT_G$`)
|
32
32
|
export { getReferencePathsToGlobal, includesIllegalString, replaceUnsafeStrings }
|
@@ -1,24 +1,19 @@
|
|
1
1
|
import type { File } from "@babel/types";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
/** the user going to be hosting this script (or set to `true` if not yet known) */
|
6
|
-
scriptUser: string | true;
|
7
|
-
/** the name of this script (or set to `true` if not yet known) */
|
8
|
-
scriptName: string | true;
|
2
|
+
import type { LaxPartial } from "@samual/lib";
|
3
|
+
export type TransformOptions = LaxPartial<{
|
4
|
+
/** 11 a-z 0-9 characters */ uniqueId: string;
|
5
|
+
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
9
6
|
seclevel: number;
|
7
|
+
}> & {
|
8
|
+
scriptName: string | true;
|
10
9
|
};
|
11
|
-
/**
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
* @param options {@link TransformOptions details}
|
19
|
-
*/
|
20
|
-
export declare const transform: (file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }?: Partial<TransformOptions>) => {
|
10
|
+
/** transform a given babel `File` to be hackmud compatible
|
11
|
+
*
|
12
|
+
* (returned File will need `postprocess()`ing)
|
13
|
+
* @param file babel ast node representing a file containing preprocessed code
|
14
|
+
* @param sourceCode the original untouched source code
|
15
|
+
* @param options {@link TransformOptions details} */
|
16
|
+
export declare function transform(file: File, sourceCode: string, { uniqueId, scriptUser, scriptName, seclevel }: TransformOptions): {
|
21
17
|
file: File;
|
22
18
|
seclevel: number;
|
23
19
|
};
|
24
|
-
export default transform;
|