hackmud-script-manager 0.21.1-2579301 → 0.21.1-2ac9caf
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 +2 -0
- package/bin/hsm.js +2 -3
- package/generateTypeDeclaration.js +3 -4
- package/index.js +0 -1
- package/package.json +1 -1
- package/processScript/index.js +85 -70
- package/processScript/minify.js +10 -10
- package/processScript/preprocess.js +6 -6
- package/processScript/transform.js +93 -28
- package/watch.js +0 -1
package/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Hackmud Script Manager
|
2
2
|
Command made for [Hackmud Scripting Environment](https://github.com/samualtnorman/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
|
3
3
|
|
4
|
+
Join [our Discord server](https://discord.gg/RSa4Sc6pNA)!
|
5
|
+
|
4
6
|
[](https://ko-fi.com/R6R0XN5CX)
|
5
7
|
|
6
8
|
You can read about how HSM works [in my blog post](https://samual.uk/blog/js-code-transformation-niche-environment/).
|
package/bin/hsm.js
CHANGED
@@ -11,7 +11,6 @@ import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
|
|
11
11
|
import { pull } from "../pull.js"
|
12
12
|
import { syncMacros } from "../syncMacros.js"
|
13
13
|
import "@samual/lib/readDirectoryWithStats"
|
14
|
-
import "path/posix"
|
15
14
|
import "@samual/lib/copyFilePersistent"
|
16
15
|
const formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
|
17
16
|
options = new Map(),
|
@@ -64,7 +63,7 @@ if (process.version.startsWith("v21.")) {
|
|
64
63
|
)
|
65
64
|
}
|
66
65
|
if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
|
67
|
-
console.log("0.21.1-
|
66
|
+
console.log("0.21.1-2ac9caf")
|
68
67
|
process.exit()
|
69
68
|
}
|
70
69
|
let warnedDeprecatedEmitDtsAlias = !1
|
@@ -412,7 +411,7 @@ function logHelp() {
|
|
412
411
|
default:
|
413
412
|
console.log(
|
414
413
|
colourS(
|
415
|
-
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-
|
414
|
+
`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-2ac9caf")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("minify")}\n Minify a script file on the spot\n${colourL("emit-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory\n\n${colourA("Options:")}\n${colourN("--help")}\n Can be used on any command e.g. ${colourC("hsm")} ${colourL("push")} ${colourN("--help")} to show helpful information`
|
416
415
|
)
|
417
416
|
)
|
418
417
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
2
|
import { basename, resolve } from "path"
|
3
|
-
import * as PathPosix from "path/posix"
|
4
3
|
async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
5
4
|
const users = new Set()
|
6
5
|
if (hackmudPath)
|
@@ -32,14 +31,14 @@ async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
|
32
31
|
}
|
33
32
|
})
|
34
33
|
)
|
35
|
-
sourceDirectory = PathPosix.resolve(sourceDirectory)
|
36
34
|
let o = ""
|
37
|
-
for (const script of wildScripts)
|
35
|
+
for (const script of wildScripts)
|
36
|
+
o += `type $${script}$ = typeof import(${JSON.stringify(resolve(sourceDirectory, script))}).default\n`
|
38
37
|
o += "\n"
|
39
38
|
for (const user in allScripts) {
|
40
39
|
const scripts = allScripts[user]
|
41
40
|
for (const script of scripts)
|
42
|
-
o += `type $${user}$${script}$ = typeof import(
|
41
|
+
o += `type $${user}$${script}$ = typeof import(${JSON.stringify(resolve(sourceDirectory, user, script))}).default\n`
|
43
42
|
}
|
44
43
|
o +=
|
45
44
|
"\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n"
|
package/index.js
CHANGED
@@ -7,7 +7,6 @@ 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"
|
11
10
|
import "@babel/generator"
|
12
11
|
import "@babel/parser"
|
13
12
|
import "@babel/plugin-proposal-decorators"
|
package/package.json
CHANGED
package/processScript/index.js
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
import
|
1
|
+
import x74p6qqqm59bm5z5y6gig27x from "@babel/generator"
|
2
2
|
import { parse } from "@babel/parser"
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
import
|
10
|
-
import
|
11
|
-
import
|
12
|
-
import
|
13
|
-
import
|
14
|
-
import
|
15
|
-
import
|
16
|
-
import
|
17
|
-
import
|
18
|
-
import
|
3
|
+
import oj702kyrbwz0zfnvvbo81hkp from "@babel/plugin-proposal-decorators"
|
4
|
+
import f78e9tv67m15rdgj4u1wb3vq from "@babel/plugin-proposal-destructuring-private"
|
5
|
+
import gtyg4tfz98nu1wkx0dchsq3v from "@babel/plugin-proposal-explicit-resource-management"
|
6
|
+
import xzsou42z9vcptieg9b65hb63 from "@babel/plugin-transform-class-properties"
|
7
|
+
import vges20bhnfvotwjumz3f1s3k from "@babel/plugin-transform-class-static-block"
|
8
|
+
import s3jqmi0vb4h2k371lyf9s5sh from "@babel/plugin-transform-exponentiation-operator"
|
9
|
+
import tb2vpz1lwo2i9d4bqsah4cf1 from "@babel/plugin-transform-json-strings"
|
10
|
+
import f59d4lxijzqoapcjlg3lxqyv from "@babel/plugin-transform-logical-assignment-operators"
|
11
|
+
import k6wn9kc8ulu8koyz19q2uka5 from "@babel/plugin-transform-nullish-coalescing-operator"
|
12
|
+
import iqh2zomoef0v98drz2obwndd from "@babel/plugin-transform-numeric-separator"
|
13
|
+
import p3upo54dulyf3smhuzn6i1wr from "@babel/plugin-transform-object-rest-spread"
|
14
|
+
import q52gk9jgt74rv9xyp4ui2ga9 from "@babel/plugin-transform-optional-catch-binding"
|
15
|
+
import dna8hximbataybwj2idneigd from "@babel/plugin-transform-optional-chaining"
|
16
|
+
import ohquoctbyfm5hbs303i8j2l8 from "@babel/plugin-transform-private-property-in-object"
|
17
|
+
import gpt2ely2i4i7d08sj51jz5qk from "@babel/plugin-transform-unicode-sets-regex"
|
18
|
+
import e87bps4ywrmap70rakbapppt from "@babel/traverse"
|
19
19
|
import t from "@babel/types"
|
20
20
|
import rollupPluginAlias from "@rollup/plugin-alias"
|
21
21
|
import { babel } from "@rollup/plugin-babel"
|
@@ -38,9 +38,24 @@ import "acorn"
|
|
38
38
|
import "terser"
|
39
39
|
import "import-meta-resolve"
|
40
40
|
import "@samual/lib/clearObject"
|
41
|
-
const
|
42
|
-
|
43
|
-
|
41
|
+
const generate = x74p6qqqm59bm5z5y6gig27x.default,
|
42
|
+
babelPluginProposalDecorators = oj702kyrbwz0zfnvvbo81hkp.default,
|
43
|
+
babelPluginProposalDestructuringPrivate = f78e9tv67m15rdgj4u1wb3vq.default,
|
44
|
+
babelPluginProposalExplicitResourceManagement = gtyg4tfz98nu1wkx0dchsq3v.default,
|
45
|
+
babelPluginTransformClassProperties = xzsou42z9vcptieg9b65hb63.default,
|
46
|
+
babelPluginTransformClassStaticBlock = vges20bhnfvotwjumz3f1s3k.default,
|
47
|
+
babelPluginTransformExponentiationOperator = s3jqmi0vb4h2k371lyf9s5sh.default,
|
48
|
+
babelPluginTransformJsonStrings = tb2vpz1lwo2i9d4bqsah4cf1.default,
|
49
|
+
babelPluginTransformLogicalAssignmentOperators = f59d4lxijzqoapcjlg3lxqyv.default,
|
50
|
+
babelPluginTransformNullishCoalescingOperator = k6wn9kc8ulu8koyz19q2uka5.default,
|
51
|
+
babelPluginTransformNumericSeparator = iqh2zomoef0v98drz2obwndd.default,
|
52
|
+
babelPluginTransformObjectRestSpread = p3upo54dulyf3smhuzn6i1wr.default,
|
53
|
+
babelPluginTransformOptionalCatchBinding = q52gk9jgt74rv9xyp4ui2ga9.default,
|
54
|
+
babelPluginTransformOptionalChaining = dna8hximbataybwj2idneigd.default,
|
55
|
+
babelPluginTransformPrivatePropertyInObject = ohquoctbyfm5hbs303i8j2l8.default,
|
56
|
+
babelPluginTransformUnicodeSetsRegex = gpt2ely2i4i7d08sj51jz5qk.default,
|
57
|
+
traverse = e87bps4ywrmap70rakbapppt.default,
|
58
|
+
{ format } = prettier
|
44
59
|
async function processScript(
|
45
60
|
code,
|
46
61
|
{
|
@@ -56,7 +71,7 @@ async function processScript(
|
|
56
71
|
rootFolderPath
|
57
72
|
}
|
58
73
|
) {
|
59
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
74
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:78:36")
|
60
75
|
const sourceCode = code
|
61
76
|
let autocomplete, statedSeclevel
|
62
77
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -117,30 +132,30 @@ async function processScript(
|
|
117
132
|
}
|
118
133
|
}
|
119
134
|
}
|
120
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
135
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:159:36")
|
121
136
|
const plugins = [
|
122
|
-
[babelPluginProposalDecorators
|
123
|
-
[babelPluginTransformClassProperties
|
124
|
-
[babelPluginTransformClassStaticBlock
|
125
|
-
[babelPluginTransformPrivatePropertyInObject
|
126
|
-
[babelPluginTransformLogicalAssignmentOperators
|
127
|
-
[babelPluginTransformNumericSeparator
|
128
|
-
[babelPluginTransformNullishCoalescingOperator
|
129
|
-
[babelPluginTransformOptionalChaining
|
130
|
-
[babelPluginTransformOptionalCatchBinding
|
131
|
-
[babelPluginTransformJsonStrings
|
132
|
-
[babelPluginTransformObjectRestSpread
|
133
|
-
[babelPluginTransformExponentiationOperator
|
134
|
-
[babelPluginTransformUnicodeSetsRegex
|
135
|
-
[babelPluginProposalDestructuringPrivate
|
136
|
-
[babelPluginProposalExplicitResourceManagement
|
137
|
+
[babelPluginProposalDecorators, { decoratorsBeforeExport: !0 }],
|
138
|
+
[babelPluginTransformClassProperties],
|
139
|
+
[babelPluginTransformClassStaticBlock],
|
140
|
+
[babelPluginTransformPrivatePropertyInObject],
|
141
|
+
[babelPluginTransformLogicalAssignmentOperators],
|
142
|
+
[babelPluginTransformNumericSeparator],
|
143
|
+
[babelPluginTransformNullishCoalescingOperator],
|
144
|
+
[babelPluginTransformOptionalChaining],
|
145
|
+
[babelPluginTransformOptionalCatchBinding],
|
146
|
+
[babelPluginTransformJsonStrings],
|
147
|
+
[babelPluginTransformObjectRestSpread],
|
148
|
+
[babelPluginTransformExponentiationOperator],
|
149
|
+
[babelPluginTransformUnicodeSetsRegex],
|
150
|
+
[babelPluginProposalDestructuringPrivate],
|
151
|
+
[babelPluginProposalExplicitResourceManagement]
|
137
152
|
]
|
138
153
|
let filePathResolved
|
139
154
|
if (filePath) {
|
140
155
|
filePathResolved = relative(".", filePath)
|
141
156
|
if (filePath.endsWith(".ts"))
|
142
157
|
plugins.push([
|
143
|
-
|
158
|
+
await import("@babel/plugin-transform-typescript").then(module => module.default),
|
144
159
|
{ allowDeclareFields: !0, optimizeConstEnums: !0 }
|
145
160
|
])
|
146
161
|
else {
|
@@ -153,22 +168,22 @@ async function processScript(
|
|
153
168
|
babelPluginProposalThrowExpressions,
|
154
169
|
babelPluginProposalRecordAndTuple
|
155
170
|
] = await Promise.all([
|
156
|
-
import("@babel/plugin-proposal-do-expressions"),
|
157
|
-
import("@babel/plugin-proposal-function-bind"),
|
158
|
-
import("@babel/plugin-proposal-function-sent"),
|
159
|
-
import("@babel/plugin-proposal-partial-application"),
|
160
|
-
import("@babel/plugin-proposal-pipeline-operator"),
|
161
|
-
import("@babel/plugin-proposal-throw-expressions"),
|
162
|
-
import("@babel/plugin-proposal-record-and-tuple")
|
171
|
+
import("@babel/plugin-proposal-do-expressions").then(module => module.default),
|
172
|
+
import("@babel/plugin-proposal-function-bind").then(module => module.default),
|
173
|
+
import("@babel/plugin-proposal-function-sent").then(module => module.default),
|
174
|
+
import("@babel/plugin-proposal-partial-application").then(module => module.default),
|
175
|
+
import("@babel/plugin-proposal-pipeline-operator").then(module => module.default),
|
176
|
+
import("@babel/plugin-proposal-throw-expressions").then(module => module.default),
|
177
|
+
import("@babel/plugin-proposal-record-and-tuple").then(module => module.default)
|
163
178
|
])
|
164
179
|
plugins.push(
|
165
|
-
[babelPluginProposalDoExpressions
|
166
|
-
[babelPluginProposalFunctionBind
|
167
|
-
[babelPluginProposalFunctionSent
|
168
|
-
[babelPluginProposalPartialApplication
|
169
|
-
[babelPluginProposalPipelineOperator
|
170
|
-
[babelPluginProposalThrowExpressions
|
171
|
-
[babelPluginProposalRecordAndTuple
|
180
|
+
[babelPluginProposalDoExpressions],
|
181
|
+
[babelPluginProposalFunctionBind],
|
182
|
+
[babelPluginProposalFunctionSent],
|
183
|
+
[babelPluginProposalPartialApplication],
|
184
|
+
[babelPluginProposalPipelineOperator, { proposal: "hack", topicToken: "%" }],
|
185
|
+
[babelPluginProposalThrowExpressions],
|
186
|
+
[babelPluginProposalRecordAndTuple, { syntaxType: "hash", importPolyfill: !0 }]
|
172
187
|
)
|
173
188
|
}
|
174
189
|
} else {
|
@@ -183,24 +198,24 @@ async function processScript(
|
|
183
198
|
babelPluginProposalThrowExpressions,
|
184
199
|
babelPluginProposalRecordAndTuple
|
185
200
|
] = await Promise.all([
|
186
|
-
import("@babel/plugin-transform-typescript"),
|
187
|
-
import("@babel/plugin-proposal-do-expressions"),
|
188
|
-
import("@babel/plugin-proposal-function-bind"),
|
189
|
-
import("@babel/plugin-proposal-function-sent"),
|
190
|
-
import("@babel/plugin-proposal-partial-application"),
|
191
|
-
import("@babel/plugin-proposal-pipeline-operator"),
|
192
|
-
import("@babel/plugin-proposal-throw-expressions"),
|
193
|
-
import("@babel/plugin-proposal-record-and-tuple")
|
201
|
+
import("@babel/plugin-transform-typescript").then(module => module.default),
|
202
|
+
import("@babel/plugin-proposal-do-expressions").then(module => module.default),
|
203
|
+
import("@babel/plugin-proposal-function-bind").then(module => module.default),
|
204
|
+
import("@babel/plugin-proposal-function-sent").then(module => module.default),
|
205
|
+
import("@babel/plugin-proposal-partial-application").then(module => module.default),
|
206
|
+
import("@babel/plugin-proposal-pipeline-operator").then(module => module.default),
|
207
|
+
import("@babel/plugin-proposal-throw-expressions").then(module => module.default),
|
208
|
+
import("@babel/plugin-proposal-record-and-tuple").then(module => module.default)
|
194
209
|
])
|
195
210
|
plugins.push(
|
196
|
-
[babelPluginTransformTypescript
|
197
|
-
[babelPluginProposalDoExpressions
|
198
|
-
[babelPluginProposalFunctionBind
|
199
|
-
[babelPluginProposalFunctionSent
|
200
|
-
[babelPluginProposalPartialApplication
|
201
|
-
[babelPluginProposalPipelineOperator
|
202
|
-
[babelPluginProposalThrowExpressions
|
203
|
-
[babelPluginProposalRecordAndTuple
|
211
|
+
[babelPluginTransformTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }],
|
212
|
+
[babelPluginProposalDoExpressions],
|
213
|
+
[babelPluginProposalFunctionBind],
|
214
|
+
[babelPluginProposalFunctionSent],
|
215
|
+
[babelPluginProposalPartialApplication],
|
216
|
+
[babelPluginProposalPipelineOperator, { proposal: "hack", topicToken: "%" }],
|
217
|
+
[babelPluginProposalThrowExpressions],
|
218
|
+
[babelPluginProposalRecordAndTuple, { syntaxType: "hash", importPolyfill: !0 }]
|
204
219
|
)
|
205
220
|
}
|
206
221
|
const bundle = await rollup({
|
@@ -253,7 +268,7 @@ async function processScript(
|
|
253
268
|
traverse(file, {
|
254
269
|
MemberExpression({ node: memberExpression }) {
|
255
270
|
if (!memberExpression.computed) {
|
256
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
271
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:323:60")
|
257
272
|
if ("prototype" == memberExpression.property.name) {
|
258
273
|
memberExpression.computed = !0
|
259
274
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -283,7 +298,7 @@ async function processScript(
|
|
283
298
|
break
|
284
299
|
case "ObjectPattern":
|
285
300
|
for (const property of lValue.properties) {
|
286
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
301
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:353:51")
|
287
302
|
renameVariables(property.value)
|
288
303
|
}
|
289
304
|
break
|
package/processScript/minify.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import x74p6qqqm59bm5z5y6gig27x from "@babel/generator"
|
2
|
+
import e87bps4ywrmap70rakbapppt from "@babel/traverse"
|
3
3
|
import t from "@babel/types"
|
4
4
|
import { assert } from "@samual/lib/assert"
|
5
5
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
@@ -7,12 +7,12 @@ import { spliceString } from "@samual/lib/spliceString"
|
|
7
7
|
import { tokenizer, tokTypes } from "acorn"
|
8
8
|
import * as terser from "terser"
|
9
9
|
import { getReferencePathsToGlobal, includesIllegalString, replaceUnsafeStrings } from "./shared.js"
|
10
|
-
const
|
11
|
-
|
10
|
+
const generate = x74p6qqqm59bm5z5y6gig27x.default,
|
11
|
+
traverse = e87bps4ywrmap70rakbapppt.default,
|
12
12
|
minifyNumber = async number =>
|
13
13
|
/\$\((?<number>.+)\)/.exec((await terser.minify(`$(${number})`, { ecma: 2015 })).code).groups.number
|
14
14
|
async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQuineCheats, autocomplete } = {}) {
|
15
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/minify.ts:
|
15
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/minify.ts:41:36")
|
16
16
|
let program
|
17
17
|
traverse(file, {
|
18
18
|
Program(path) {
|
@@ -52,7 +52,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
52
52
|
traverse(fileBeforeJSONValueReplacement, {
|
53
53
|
MemberExpression({ node: memberExpression }) {
|
54
54
|
if (!memberExpression.computed) {
|
55
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
55
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:110:60")
|
56
56
|
if ("prototype" == memberExpression.property.name) {
|
57
57
|
memberExpression.computed = !0
|
58
58
|
memberExpression.property = t.identifier(`_${uniqueId}_PROTOTYPE_PROPERTY_`)
|
@@ -164,7 +164,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
164
164
|
},
|
165
165
|
MemberExpression({ node: memberExpression }) {
|
166
166
|
if (!memberExpression.computed) {
|
167
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
167
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:244:62")
|
168
168
|
if (!(memberExpression.property.name.length < 3)) {
|
169
169
|
memberExpression.computed = !0
|
170
170
|
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
@@ -238,7 +238,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
238
238
|
})
|
239
239
|
await Promise.all(promises)
|
240
240
|
const functionDeclaration = file.program.body[0]
|
241
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
241
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:349:61")
|
242
242
|
if (jsonValues.length) {
|
243
243
|
hasComment = !0
|
244
244
|
if (1 == jsonValues.length)
|
@@ -358,7 +358,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
358
358
|
)
|
359
359
|
}
|
360
360
|
if (1 == forceQuineCheats) return code
|
361
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
361
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:480:43")
|
362
362
|
return countHackmudCharacters(scriptBeforeJSONValueReplacement) <= countHackmudCharacters(code) + Number(hasComment)
|
363
363
|
? scriptBeforeJSONValueReplacement
|
364
364
|
: code
|
@@ -371,7 +371,7 @@ function parseObjectExpression(node, o) {
|
|
371
371
|
"Identifier" == property.key.type ||
|
372
372
|
"NumericLiteral" == property.key.type ||
|
373
373
|
"StringLiteral" == property.key.type,
|
374
|
-
"src/processScript/minify.ts:
|
374
|
+
"src/processScript/minify.ts:502:4"
|
375
375
|
)
|
376
376
|
if ("ArrayExpression" == property.value.type) {
|
377
377
|
const childArray = []
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import
|
1
|
+
import x74p6qqqm59bm5z5y6gig27x from "@babel/generator"
|
2
2
|
import { parse } from "@babel/parser"
|
3
|
-
import
|
3
|
+
import e87bps4ywrmap70rakbapppt from "@babel/traverse"
|
4
4
|
import t from "@babel/types"
|
5
5
|
import { assert } from "@samual/lib/assert"
|
6
6
|
import { spliceString } from "@samual/lib/spliceString"
|
7
7
|
import { resolve } from "import-meta-resolve"
|
8
|
-
const
|
9
|
-
|
8
|
+
const generate = x74p6qqqm59bm5z5y6gig27x.default,
|
9
|
+
traverse = e87bps4ywrmap70rakbapppt.default
|
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:18: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:62:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import
|
1
|
+
import e87bps4ywrmap70rakbapppt from "@babel/traverse"
|
2
2
|
import t from "@babel/types"
|
3
3
|
import { assert } from "@samual/lib/assert"
|
4
4
|
import { clearObject } from "@samual/lib/clearObject"
|
5
5
|
import { validDBMethods } from "../constants.js"
|
6
6
|
import { getReferencePathsToGlobal } from "./shared.js"
|
7
|
-
const
|
7
|
+
const traverse = e87bps4ywrmap70rakbapppt.default,
|
8
8
|
globalFunctionsUnder7Characters = [
|
9
9
|
"Map",
|
10
10
|
"Set",
|
@@ -77,30 +77,30 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
77
77
|
const referencePath = FunctionReferencePaths[0]
|
78
78
|
assert(
|
79
79
|
"MemberExpression" == referencePath.parent.type,
|
80
|
-
"src/processScript/transform.ts:
|
80
|
+
"src/processScript/transform.ts:108:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
81
81
|
)
|
82
82
|
assert(
|
83
83
|
"Identifier" == referencePath.parent.property.type,
|
84
|
-
"src/processScript/transform.ts:
|
84
|
+
"src/processScript/transform.ts:113:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
85
85
|
)
|
86
86
|
assert(
|
87
87
|
"prototype" == referencePath.parent.property.name,
|
88
|
-
"src/processScript/transform.ts:
|
88
|
+
"src/processScript/transform.ts:118:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
89
89
|
)
|
90
90
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
91
91
|
} else {
|
92
92
|
for (const referencePath of FunctionReferencePaths) {
|
93
93
|
assert(
|
94
94
|
"MemberExpression" == referencePath.parent.type,
|
95
|
-
"src/processScript/transform.ts:
|
95
|
+
"src/processScript/transform.ts:126:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
96
96
|
)
|
97
97
|
assert(
|
98
98
|
"Identifier" == referencePath.parent.property.type,
|
99
|
-
"src/processScript/transform.ts:
|
99
|
+
"src/processScript/transform.ts:131:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
100
100
|
)
|
101
101
|
assert(
|
102
102
|
"prototype" == referencePath.parent.property.name,
|
103
|
-
"src/processScript/transform.ts:
|
103
|
+
"src/processScript/transform.ts:136:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
104
104
|
)
|
105
105
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
106
106
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -141,12 +141,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
141
141
|
const neededDbMethodLets = new Set()
|
142
142
|
if (program.scope.hasGlobal("$db"))
|
143
143
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
144
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
145
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
144
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:196:69")
|
145
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:197:72")
|
146
146
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
147
147
|
assert(
|
148
148
|
validDBMethods.includes(databaseOpMethodName),
|
149
|
-
`src/processScript/transform.ts:
|
149
|
+
`src/processScript/transform.ts:203:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
150
150
|
)
|
151
151
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
152
152
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueId}$DB$${databaseOpMethodName}$`))
|
@@ -181,7 +181,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
181
181
|
if (program.scope.hasGlobal("Object"))
|
182
182
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
183
183
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
184
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
184
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:253:64")
|
185
185
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
186
186
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
|
187
187
|
needGetPrototypeOf = !0
|
@@ -194,7 +194,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
194
194
|
if (program.scope.hasGlobal("console"))
|
195
195
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
196
196
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
197
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
197
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:271:64")
|
198
198
|
referencePath.parentPath.replaceWith(
|
199
199
|
t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
200
200
|
)
|
@@ -202,13 +202,13 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
202
202
|
}
|
203
203
|
const lastStatement = program.node.body.at(-1)
|
204
204
|
let exportDefaultName
|
205
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
205
|
+
assert(lastStatement, "src/processScript/transform.ts:285:27 program is empty")
|
206
206
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
207
207
|
program.node.body.pop()
|
208
208
|
for (const specifier of lastStatement.specifiers) {
|
209
209
|
assert(
|
210
210
|
"ExportSpecifier" == specifier.type,
|
211
|
-
`src/processScript/transform.ts:
|
211
|
+
`src/processScript/transform.ts:291:51 ${specifier.type} is currently unsupported`
|
212
212
|
)
|
213
213
|
if (
|
214
214
|
"default" !=
|
@@ -310,11 +310,11 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
310
310
|
let hoistedGlobalBlockFunctions = 0
|
311
311
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
312
312
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
313
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
313
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:405:59")
|
314
314
|
const declarator = globalBlockStatement.declarations[0]
|
315
315
|
assert(
|
316
316
|
"Identifier" == declarator.id.type,
|
317
|
-
`src/processScript/transform.ts:
|
317
|
+
`src/processScript/transform.ts:409:51 declarator.id.type was "${declarator.id.type}"`
|
318
318
|
)
|
319
319
|
program.scope.crawl()
|
320
320
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -329,9 +329,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
329
329
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
330
330
|
) {
|
331
331
|
const binding = program.scope.getBinding(declarator.id.name)
|
332
|
-
assert(binding, "src/processScript/transform.ts:
|
332
|
+
assert(binding, "src/processScript/transform.ts:428:23")
|
333
333
|
for (const referencePath of binding.referencePaths) {
|
334
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
334
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:431:56")
|
335
335
|
referencePath.replaceWith(
|
336
336
|
t.memberExpression(
|
337
337
|
t.identifier(`_${uniqueId}_G_`),
|
@@ -379,16 +379,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
379
379
|
} else globalBlockVariables.add(declarator.id.name)
|
380
380
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
381
381
|
program.scope.crawl()
|
382
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
382
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:488:37")
|
383
383
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
384
384
|
globalBlock.body.splice(globalBlockIndex, 1)
|
385
385
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
386
386
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
387
387
|
program.scope.crawl()
|
388
388
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
389
|
-
assert(binding, "src/processScript/transform.ts:
|
389
|
+
assert(binding, "src/processScript/transform.ts:500:22")
|
390
390
|
for (const referencePath of binding.referencePaths) {
|
391
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
391
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:503:55")
|
392
392
|
referencePath.replaceWith(
|
393
393
|
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(referencePath.node.name))
|
394
394
|
)
|
@@ -562,6 +562,65 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
562
562
|
t.variableDeclarator(t.identifier(`_${uniqueId}_G_`), t.identifier(`$${uniqueId}$GLOBAL$`))
|
563
563
|
])
|
564
564
|
)
|
565
|
+
const replaceAllThisWith = (node, scope, thisId) => {
|
566
|
+
let thisIsReferenced = !1
|
567
|
+
traverse(
|
568
|
+
node,
|
569
|
+
{
|
570
|
+
ThisExpression(path) {
|
571
|
+
thisIsReferenced = !0
|
572
|
+
path.replaceWith(t.identifier(thisId))
|
573
|
+
},
|
574
|
+
Function(path) {
|
575
|
+
"ArrowFunctionExpression" != path.node.type && path.skip()
|
576
|
+
}
|
577
|
+
},
|
578
|
+
scope
|
579
|
+
)
|
580
|
+
return thisIsReferenced
|
581
|
+
},
|
582
|
+
replaceThisInObjectLikeDefinition = path => {
|
583
|
+
const { node: object, scope, parent } = path,
|
584
|
+
evenMoreUniqueId = Math.floor(Math.random() * 2 ** 52)
|
585
|
+
.toString(36)
|
586
|
+
.padStart(11, "0"),
|
587
|
+
reuseDeclaredName =
|
588
|
+
"VariableDeclarator" == parent.type &&
|
589
|
+
"VariableDeclaration" == path.parentPath?.parentPath?.node?.type &&
|
590
|
+
"const" == path.parentPath?.parentPath?.node?.kind &&
|
591
|
+
"Identifier" == parent.id.type
|
592
|
+
let thisId = reuseDeclaredName ? parent.id.name : `_${evenMoreUniqueId}_THIS_`,
|
593
|
+
thisIsReferenced = !1
|
594
|
+
if ("ObjectExpression" == object.type)
|
595
|
+
for (const property of object.properties)
|
596
|
+
"ObjectMethod" == property.type &&
|
597
|
+
(thisIsReferenced ||= replaceAllThisWith(property, scope, thisId))
|
598
|
+
else
|
599
|
+
for (const element of object.elements)
|
600
|
+
null != element && (thisIsReferenced ||= replaceAllThisWith(element, scope, thisId))
|
601
|
+
if (!thisIsReferenced) return
|
602
|
+
if (reuseDeclaredName) return
|
603
|
+
path.replaceWith(t.assignmentExpression("=", t.identifier(thisId), object))
|
604
|
+
const parentBlock = (path => {
|
605
|
+
let someBlock = null,
|
606
|
+
currentParent = path
|
607
|
+
for (; currentParent && currentParent && currentParent.node; ) {
|
608
|
+
if (t.isBlock(currentParent.node)) {
|
609
|
+
someBlock = currentParent.node
|
610
|
+
break
|
611
|
+
}
|
612
|
+
if (t.isArrowFunctionExpression(currentParent.parentPath?.node)) {
|
613
|
+
currentParent.replaceWith(t.blockStatement([t.returnStatement(currentParent.node)]))
|
614
|
+
someBlock = currentParent.node
|
615
|
+
break
|
616
|
+
}
|
617
|
+
currentParent = currentParent.parentPath
|
618
|
+
}
|
619
|
+
assert(null != someBlock, "src/processScript/transform.ts:705:29")
|
620
|
+
return someBlock
|
621
|
+
})(path)
|
622
|
+
parentBlock.body.unshift(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(thisId), null)]))
|
623
|
+
}
|
565
624
|
traverse(file, {
|
566
625
|
BlockStatement({ node: blockStatement }) {
|
567
626
|
for (const [index, functionDeclaration] of blockStatement.body.entries())
|
@@ -581,8 +640,14 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
581
640
|
)
|
582
641
|
}
|
583
642
|
},
|
643
|
+
ObjectExpression(path) {
|
644
|
+
replaceThisInObjectLikeDefinition(path)
|
645
|
+
},
|
646
|
+
ArrayExpression(path) {
|
647
|
+
replaceThisInObjectLikeDefinition(path)
|
648
|
+
},
|
584
649
|
ClassBody({ node: classBody, scope, parent }) {
|
585
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
650
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:804:30")
|
586
651
|
let thisIsReferenced = !1
|
587
652
|
for (const classMethod of classBody.body) {
|
588
653
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -684,23 +749,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
684
749
|
}
|
685
750
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
686
751
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
687
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
752
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:914:60")
|
688
753
|
assert("Identifier" == referencePath.parent.property.type)
|
689
754
|
assert(
|
690
755
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
691
|
-
"src/processScript/transform.ts:
|
756
|
+
"src/processScript/transform.ts:916:81"
|
692
757
|
)
|
693
758
|
assert(
|
694
759
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
695
|
-
"src/processScript/transform.ts:
|
760
|
+
"src/processScript/transform.ts:917:83"
|
696
761
|
)
|
697
762
|
assert(
|
698
763
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
699
|
-
`src/processScript/transform.ts:
|
764
|
+
`src/processScript/transform.ts:921:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
700
765
|
)
|
701
766
|
assert(
|
702
767
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
703
|
-
`src/processScript/transform.ts:
|
768
|
+
`src/processScript/transform.ts:926:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
704
769
|
)
|
705
770
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
706
771
|
referencePath.parentPath.parentPath.replaceWith(
|
package/watch.js
CHANGED
@@ -9,7 +9,6 @@ import { extname, basename, resolve } from "path"
|
|
9
9
|
import { supportedExtensions } from "./constants.js"
|
10
10
|
import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
11
11
|
import { processScript } from "./processScript/index.js"
|
12
|
-
import "path/posix"
|
13
12
|
import "@babel/generator"
|
14
13
|
import "@babel/parser"
|
15
14
|
import "@babel/plugin-proposal-decorators"
|