hackmud-script-manager 0.19.1-bd545f5 → 0.19.1-cb8d65f
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.js +180 -232
- package/generateTypeDeclaration.js +1 -1
- package/package.json +4 -9
- package/processScript/index.js +257 -240
- package/processScript/minify.js +380 -394
- package/processScript/preprocess.js +93 -93
- package/processScript/shared.js +11 -11
- package/processScript/transform.js +566 -559
- package/pull.js +1 -1
- package/push.js +2 -2
- package/{bin → src/bin}/hsm.d.ts +0 -0
- package/src/generateTypeDeclaration.d.ts +2 -0
- package/src/processScript/index.d.ts +31 -0
- package/src/processScript/minify.d.ts +18 -0
- package/src/processScript/preprocess.d.ts +9 -0
- package/{processScript → src/processScript}/shared.d.ts +1 -1
- package/src/processScript/transform.d.ts +18 -0
- package/src/pull.d.ts +6 -0
- package/src/push.d.ts +29 -0
- package/{syncMacros.d.ts → src/syncMacros.d.ts} +1 -1
- package/src/watch.d.ts +15 -0
- package/syncMacros.js +1 -1
- package/watch.js +11 -11
- package/generateTypeDeclaration.d.ts +0 -2
- package/processScript/index.d.ts +0 -40
- package/processScript/minify.d.ts +0 -24
- package/processScript/preprocess.d.ts +0 -12
- package/processScript/transform.d.ts +0 -24
- package/pull.d.ts +0 -9
- package/push.d.ts +0 -37
- package/tsconfig.tsbuildinfo +0 -1
- package/watch.d.ts +0 -20
- /package/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{processScript → src/processScript}/postprocess.d.ts +0 -0
| @@ -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:23: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:67: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 | 
            -
            	}
         | 
| 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 105 | 
             
            export { preprocess as default, preprocess }
         | 
    
        package/processScript/shared.js
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 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") ||
         |