hackmud-script-manager-ng 0.26.5 → 0.26.6
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/bin/hsm.d.ts +2 -0
- package/bin/hsm.js +493 -0
- package/constants.d.ts +2 -0
- package/constants.js +3 -0
- package/generateTypeDeclaration.d.ts +1 -0
- package/generateTypeDeclaration.js +70 -0
- package/index.d.ts +16 -0
- package/index.js +52 -0
- package/package.json +3 -22
- package/processScript/index.d.ts +34 -0
- package/processScript/index.js +362 -0
- package/processScript/minify.d.ts +20 -0
- package/processScript/minify.js +431 -0
- package/processScript/postprocess.d.ts +1 -0
- package/processScript/postprocess.js +21 -0
- package/processScript/preprocess.d.ts +11 -0
- package/processScript/preprocess.js +107 -0
- package/processScript/shared.d.ts +5 -0
- package/processScript/shared.js +32 -0
- package/processScript/transform.d.ts +24 -0
- package/processScript/transform.js +803 -0
- package/pull.d.ts +7 -0
- package/pull.js +11 -0
- package/push.d.ts +42 -0
- package/push.js +164 -0
- package/syncMacros.d.ts +4 -0
- package/syncMacros.js +42 -0
- package/watch.d.ts +19 -0
- package/watch.js +220 -0
- package/.envrc +0 -1
- package/.github/FUNDING.yml +0 -14
- package/.github/workflows/publish.yml +0 -27
- package/.github/workflows/test.yml +0 -18
- package/.vscode/settings.json +0 -55
- package/CONTRIBUTING.md +0 -68
- package/eslint.config.js +0 -81
- package/game-scripts-tests/array-rest-works.ts +0 -6
- package/game-scripts-tests/this_array_in_object.ts +0 -16
- package/game-scripts-tests/this_function_array.ts +0 -9
- package/game-scripts-tests/this_in_default_argument.ts +0 -35
- package/game-scripts-tests/this_in_lambda_in_object.ts +0 -26
- package/pnpm-workspace.yaml +0 -2
- package/rollup.config.js +0 -69
- package/scripts/dev.sh +0 -3
- package/scripts/emit-declarations.sh +0 -3
- package/scripts/emit-package-json.js +0 -9
- package/scripts/lint.sh +0 -5
- package/scripts/package.sh +0 -7
- package/scripts/update.sh +0 -4
- package/scripts/version-dev.js +0 -14
- package/src/bin/hsm.ts +0 -754
- package/src/constants.ts +0 -2
- package/src/env.d.ts +0 -13
- package/src/generateTypeDeclaration.ts +0 -119
- package/src/index.ts +0 -13
- package/src/processScript/__snapshots__/index.ts.snap +0 -8
- package/src/processScript/index.ts +0 -474
- package/src/processScript/minify.ts +0 -594
- package/src/processScript/postprocess.ts +0 -19
- package/src/processScript/preprocess.ts +0 -130
- package/src/processScript/shared.ts +0 -33
- package/src/processScript/transform.ts +0 -978
- package/src/pull.ts +0 -20
- package/src/push.ts +0 -200
- package/src/syncMacros.ts +0 -53
- package/src/tsconfig.json +0 -14
- package/src/watch.ts +0 -258
- package/tsconfig.json +0 -23
- package/vitest.config.ts +0 -19
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/* eslint-disable jsdoc/check-param-names */
|
|
2
|
-
import type { NodePath } from "@babel/traverse"
|
|
3
|
-
import type { Program } from "@babel/types"
|
|
4
|
-
import type { LaxPartial } from "@samual/lib"
|
|
5
|
-
import generate from "@babel/generator"
|
|
6
|
-
import { parse } from "@babel/parser"
|
|
7
|
-
import traverse from "@babel/traverse"
|
|
8
|
-
import t from "@babel/types"
|
|
9
|
-
import { assert } from "@samual/lib/assert"
|
|
10
|
-
import { spliceString } from "@samual/lib/spliceString"
|
|
11
|
-
import { resolve as resolveModule } from "import-meta-resolve"
|
|
12
|
-
|
|
13
|
-
export type PreprocessOptions = LaxPartial<{ /** 11 a-z 0-9 characters */ uniqueId: string }>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param code source code for preprocessing
|
|
17
|
-
* @param options {@link PreprocessOptions details}
|
|
18
|
-
*/
|
|
19
|
-
export async function preprocess(code: string, { uniqueId = `00000000000` }: PreprocessOptions = {}): Promise<{ code: string }> {
|
|
20
|
-
assert(/^\w{11}$/.test(uniqueId), HERE)
|
|
21
|
-
|
|
22
|
-
const sourceCode = code
|
|
23
|
-
let lengthBefore
|
|
24
|
-
|
|
25
|
-
do {
|
|
26
|
-
lengthBefore = code.length
|
|
27
|
-
code = code.replace(/^\s+/, ``).replace(/^\/\/.*/, ``).replace(/^\/\*[\s\S]*?\*\//, ``)
|
|
28
|
-
} while (code.length != lengthBefore)
|
|
29
|
-
|
|
30
|
-
code = code.replace(/^function\s*\(/, `export default function (`)
|
|
31
|
-
|
|
32
|
-
let file
|
|
33
|
-
|
|
34
|
-
while (true) {
|
|
35
|
-
let error
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
file = parse(code, {
|
|
39
|
-
plugins: [
|
|
40
|
-
`typescript`,
|
|
41
|
-
[ `decorators`, { decoratorsBeforeExport: true } ],
|
|
42
|
-
`doExpressions`,
|
|
43
|
-
`functionBind`,
|
|
44
|
-
`functionSent`,
|
|
45
|
-
`partialApplication`,
|
|
46
|
-
[ `pipelineOperator`, { proposal: `hack`, topicToken: `%` } ],
|
|
47
|
-
`throwExpressions`,
|
|
48
|
-
[ `recordAndTuple`, { syntaxType: `hash` } ],
|
|
49
|
-
`classProperties`,
|
|
50
|
-
`classPrivateProperties`,
|
|
51
|
-
`classPrivateMethods`,
|
|
52
|
-
`logicalAssignment`,
|
|
53
|
-
`numericSeparator`,
|
|
54
|
-
`nullishCoalescingOperator`,
|
|
55
|
-
`optionalChaining`,
|
|
56
|
-
`optionalCatchBinding`,
|
|
57
|
-
`objectRestSpread`
|
|
58
|
-
],
|
|
59
|
-
sourceType: `module`
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
break
|
|
63
|
-
} catch (error_) {
|
|
64
|
-
assert(error_ instanceof SyntaxError, HERE)
|
|
65
|
-
error = error_ as SyntaxError & { pos: number, code: string, reasonCode: string }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (error.code != `BABEL_PARSER_SYNTAX_ERROR` || error.reasonCode != `PrivateInExpectedIn`) {
|
|
69
|
-
console.error((/.+/.exec(code.slice(error.pos)))?.[0])
|
|
70
|
-
|
|
71
|
-
throw error
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const codeSlice = code.slice(error.pos)
|
|
75
|
-
let match
|
|
76
|
-
|
|
77
|
-
if ((match = /^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(codeSlice)))
|
|
78
|
-
code = spliceString(code, JSON.stringify(sourceCode), error.pos, match[0]!.length)
|
|
79
|
-
else if ((match = /^#[0-4fhmln]?s\./.exec(codeSlice)))
|
|
80
|
-
code = spliceString(code, `$`, error.pos, 1)
|
|
81
|
-
else if ((match = /^#D[^\w$]/.exec(codeSlice)))
|
|
82
|
-
code = spliceString(code, `$`, error.pos, 1)
|
|
83
|
-
else if ((match = /^#FMCL/.exec(codeSlice)))
|
|
84
|
-
code = spliceString(code, `$${uniqueId}$FMCL$`, error.pos, match[0]!.length)
|
|
85
|
-
else if ((match = /^#G/.exec(codeSlice)))
|
|
86
|
-
code = spliceString(code, `$${uniqueId}$GLOBAL$`, error.pos, match[0]!.length)
|
|
87
|
-
else if ((match = /^#db\./.exec(codeSlice)))
|
|
88
|
-
code = spliceString(code, `$`, error.pos, 1)
|
|
89
|
-
else
|
|
90
|
-
throw error
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let program!: NodePath<Program>
|
|
94
|
-
|
|
95
|
-
traverse(file, {
|
|
96
|
-
Program(path) {
|
|
97
|
-
program = path
|
|
98
|
-
path.skip()
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const needRecord = program.scope.hasGlobal(`Record`)
|
|
103
|
-
const needTuple = program.scope.hasGlobal(`Tuple`)
|
|
104
|
-
|
|
105
|
-
if (needRecord || needTuple) {
|
|
106
|
-
file.program.body.unshift(t.importDeclaration(
|
|
107
|
-
needRecord ?
|
|
108
|
-
needTuple ?
|
|
109
|
-
[
|
|
110
|
-
t.importSpecifier(t.identifier(`Record`), t.identifier(`Record`)),
|
|
111
|
-
t.importSpecifier(t.identifier(`Tuple`), t.identifier(`Tuple`))
|
|
112
|
-
]
|
|
113
|
-
: [ t.importSpecifier(t.identifier(`Record`), t.identifier(`Record`)) ]
|
|
114
|
-
: [ t.importSpecifier(t.identifier(`Tuple`), t.identifier(`Tuple`)) ],
|
|
115
|
-
t.stringLiteral(`@bloomberg/record-tuple-polyfill`)
|
|
116
|
-
))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (program.scope.hasGlobal(`Proxy`)) {
|
|
120
|
-
file.program.body.unshift(t.importDeclaration([
|
|
121
|
-
t.importDefaultSpecifier(t.identifier(`Proxy`))
|
|
122
|
-
], t.stringLiteral(resolveModule(`proxy-polyfill/src/proxy.js`, import.meta.url).slice(7))))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (program.node.body.length == 1 && program.node.body[0]!.type == `FunctionDeclaration`) {
|
|
126
|
-
throw Error(`Scripts that only contain a single function declaration are no longer supported.\nPrefix the function declaration with \`export default\`.`)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { code: generate(file).code }
|
|
130
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from "@babel/traverse"
|
|
2
|
-
import type { Identifier, Program } from "@babel/types"
|
|
3
|
-
import t from "@babel/types"
|
|
4
|
-
import { ensure } from "@samual/lib/assert"
|
|
5
|
-
|
|
6
|
-
export function getReferencePathsToGlobal(name: string, program: NodePath<Program>) {
|
|
7
|
-
const [ variableDeclaration ] = program
|
|
8
|
-
.unshiftContainer(`body`, t.variableDeclaration(`let`, [ t.variableDeclarator(t.identifier(name)) ]))
|
|
9
|
-
|
|
10
|
-
program.scope.crawl()
|
|
11
|
-
|
|
12
|
-
const binding = ensure(program.scope.getBinding(name), HERE)
|
|
13
|
-
|
|
14
|
-
variableDeclaration.remove()
|
|
15
|
-
|
|
16
|
-
return binding.referencePaths as NodePath<Identifier>[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const includesIllegalString = (toCheck: string): boolean => toCheck.includes(`SC$`) || toCheck.includes(`DB$`) ||
|
|
20
|
-
toCheck.includes(`__D_S`) || toCheck.includes(`__FMCL_`) || toCheck.includes(`__G_`)
|
|
21
|
-
|
|
22
|
-
export const replaceUnsafeStrings = (uniqueId: string, toReplace: string): string => toReplace
|
|
23
|
-
.replaceAll(`SC$`, `$${uniqueId}$\\$SC_DOLLAR$`)
|
|
24
|
-
.replaceAll(`DB$`, `$${uniqueId}$\\$DB_DOLLAR$`)
|
|
25
|
-
.replaceAll(`__D_S`, `$${uniqueId}$\\$D$`)
|
|
26
|
-
.replaceAll(`__FMCL_`, `$${uniqueId}$\\$FMCL$`)
|
|
27
|
-
.replaceAll(`__G_`, `$${uniqueId}$\\$G$`)
|
|
28
|
-
.replaceAll(`//`, `$${uniqueId}$SLASH_SLASH$`)
|
|
29
|
-
.replaceAll(/#[0-4fhmln]?s(?:\.[_a-z][\d_a-z]{0,24}){2}\(/g, `$${uniqueId}$NOT_A_SUBSCRIPT$$$&$`)
|
|
30
|
-
.replaceAll(/#db\.(?<methodName>[irfu]|u1|us|ObjectId)\(/g, `$${uniqueId}$NOT_A_DB_CALL$$$1$`)
|
|
31
|
-
.replaceAll(`#D(`, `$${uniqueId}$NOT_A_DEBUG_CALL$`)
|
|
32
|
-
.replaceAll(`#FMCL`, `$${uniqueId}$NOT_FMCL$`)
|
|
33
|
-
.replaceAll(`#G`, `$${uniqueId}$NOT_G$`)
|