hackmud-script-manager 0.21.1-8e6657c → 0.21.1-93e7bef
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 +22 -12
 - package/env.d.ts +11 -10
 - package/package.json +1 -1
 - package/processScript/preprocess.js +79 -139
 
    
        package/bin/hsm.js
    CHANGED
    
    | 
         @@ -55,14 +55,16 @@ const pushModule = import("../push.js"), 
     | 
|
| 
       55 
55 
     | 
    
         
             
            	colourS = chalk.rgb(122, 178, 244),
         
     | 
| 
       56 
56 
     | 
    
         
             
            	colourV = chalk.rgb(255, 0, 236),
         
     | 
| 
       57 
57 
     | 
    
         
             
            	colourW = chalk.rgb(255, 150, 224)
         
     | 
| 
       58 
     | 
    
         
            -
            process.version.startsWith("v21.")  
     | 
| 
      
 58 
     | 
    
         
            +
            if (process.version.startsWith("v21.")) {
         
     | 
| 
      
 59 
     | 
    
         
            +
            	process.exitCode = 1
         
     | 
| 
       59 
60 
     | 
    
         
             
            	console.warn(
         
     | 
| 
       60 
61 
     | 
    
         
             
            		colourF(
         
     | 
| 
       61 
62 
     | 
    
         
             
            			`${chalk.bold("Warning:")} Support for Node.js 21 will be dropped in the next minor version of HSM\n         Your current version of Node.js is ${chalk.bold(process.version)}\n         You should update your version of Node.js\n         https://nodejs.org/en/download/package-manager\n`
         
     | 
| 
       62 
63 
     | 
    
         
             
            		)
         
     | 
| 
       63 
64 
     | 
    
         
             
            	)
         
     | 
| 
      
 65 
     | 
    
         
            +
            }
         
     | 
| 
       64 
66 
     | 
    
         
             
            if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
         
     | 
| 
       65 
     | 
    
         
            -
            	console.log("0.21.1- 
     | 
| 
      
 67 
     | 
    
         
            +
            	console.log("0.21.1-93e7bef")
         
     | 
| 
       66 
68 
     | 
    
         
             
            	process.exit()
         
     | 
| 
       67 
69 
     | 
    
         
             
            }
         
     | 
| 
       68 
70 
     | 
    
         
             
            let warnedDeprecatedEmitDtsAlias = !1
         
     | 
| 
         @@ -79,13 +81,14 @@ switch (commands[0]) { 
     | 
|
| 
       79 
81 
     | 
    
         
             
            	case "minify":
         
     | 
| 
       80 
82 
     | 
    
         
             
            		{
         
     | 
| 
       81 
83 
     | 
    
         
             
            			const noMinifyOption = popOption("no-minify", "skip-minify")
         
     | 
| 
       82 
     | 
    
         
            -
            			noMinifyOption &&
         
     | 
| 
       83 
     | 
    
         
            -
            				 
     | 
| 
      
 84 
     | 
    
         
            +
            			if (noMinifyOption && "no-minify" != noMinifyOption.name) {
         
     | 
| 
      
 85 
     | 
    
         
            +
            				process.exitCode = 1
         
     | 
| 
       84 
86 
     | 
    
         
             
            				console.warn(
         
     | 
| 
       85 
87 
     | 
    
         
             
            					colourF(
         
     | 
| 
       86 
88 
     | 
    
         
             
            						`${chalk.bold("Warning:")} ${formatOption(noMinifyOption.name)} is deprecated and will be removed in the next minor\n         release of HSM\n         You should switch to using its alias ${colourN("--no-minify")}\n`
         
     | 
| 
       87 
89 
     | 
    
         
             
            					)
         
     | 
| 
       88 
90 
     | 
    
         
             
            				)
         
     | 
| 
      
 91 
     | 
    
         
            +
            			}
         
     | 
| 
       89 
92 
     | 
    
         
             
            			const mangleNamesOption = popOption("mangle-names"),
         
     | 
| 
       90 
93 
     | 
    
         
             
            				forceQuineCheatsOption = popOption("force-quine-cheats"),
         
     | 
| 
       91 
94 
     | 
    
         
             
            				noQuineCheatsOptions = popOption("no-quine-cheats"),
         
     | 
| 
         @@ -158,6 +161,7 @@ switch (commands[0]) { 
     | 
|
| 
       158 
161 
     | 
    
         
             
            								rootFolderPath
         
     | 
| 
       159 
162 
     | 
    
         
             
            							}),
         
     | 
| 
       160 
163 
     | 
    
         
             
            							timeTook = performance.now() - timeStart
         
     | 
| 
      
 164 
     | 
    
         
            +
            						warnings.length && (process.exitCode = 1)
         
     | 
| 
       161 
165 
     | 
    
         
             
            						for (const { message } of warnings)
         
     | 
| 
       162 
166 
     | 
    
         
             
            							console.warn(colourF(`${chalk.bold("Warning:")} ${message}`))
         
     | 
| 
       163 
167 
     | 
    
         
             
            						await writeFilePersistent(outputPath, script)
         
     | 
| 
         @@ -207,14 +211,18 @@ switch (commands[0]) { 
     | 
|
| 
       207 
211 
     | 
    
         
             
            						"dts",
         
     | 
| 
       208 
212 
     | 
    
         
             
            						"gen-types"
         
     | 
| 
       209 
213 
     | 
    
         
             
            					)
         
     | 
| 
       210 
     | 
    
         
            -
            					 
     | 
| 
      
 214 
     | 
    
         
            +
            					if (
         
     | 
| 
      
 215 
     | 
    
         
            +
            						dtsPathOption &&
         
     | 
| 
       211 
216 
     | 
    
         
             
            						"dts-path" != dtsPathOption.name &&
         
     | 
| 
       212 
     | 
    
         
            -
            						"type-declaration-path" != dtsPathOption.name 
     | 
| 
      
 217 
     | 
    
         
            +
            						"type-declaration-path" != dtsPathOption.name
         
     | 
| 
      
 218 
     | 
    
         
            +
            					) {
         
     | 
| 
      
 219 
     | 
    
         
            +
            						process.exitCode = 1
         
     | 
| 
       213 
220 
     | 
    
         
             
            						console.warn(
         
     | 
| 
       214 
221 
     | 
    
         
             
            							colourF(
         
     | 
| 
       215 
222 
     | 
    
         
             
            								`${chalk.bold("Warning:")} ${formatOption(dtsPathOption.name)} is deprecated and will be removed in the\n         next minor release of HSM\n         You should switch to using its alias ${colourN("--dts-path")}\n`
         
     | 
| 
       216 
223 
     | 
    
         
             
            							)
         
     | 
| 
       217 
224 
     | 
    
         
             
            						)
         
     | 
| 
      
 225 
     | 
    
         
            +
            					}
         
     | 
| 
       218 
226 
     | 
    
         
             
            					complainAboutUnrecognisedOptions()
         
     | 
| 
       219 
227 
     | 
    
         
             
            					const { watch } = await watchModule
         
     | 
| 
       220 
228 
     | 
    
         
             
            					watch(sourcePath, hackmudPath, {
         
     | 
| 
         @@ -244,7 +252,7 @@ switch (commands[0]) { 
     | 
|
| 
       244 
252 
     | 
    
         
             
            						const typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
         
     | 
| 
       245 
253 
     | 
    
         
             
            						declarationPathPromise = writeFile(typeDeclarationPath, typeDeclaration)
         
     | 
| 
       246 
254 
     | 
    
         
             
            							.catch(error => {
         
     | 
| 
       247 
     | 
    
         
            -
            								assert(error instanceof Error, "src/bin/hsm.ts: 
     | 
| 
      
 255 
     | 
    
         
            +
            								assert(error instanceof Error, "src/bin/hsm.ts:299:38")
         
     | 
| 
       248 
256 
     | 
    
         
             
            								if ("EISDIR" != error.code) throw error
         
     | 
| 
       249 
257 
     | 
    
         
             
            								typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
         
     | 
| 
       250 
258 
     | 
    
         
             
            								return writeFile(typeDeclarationPath, typeDeclaration)
         
     | 
| 
         @@ -311,6 +319,7 @@ switch (commands[0]) { 
     | 
|
| 
       311 
319 
     | 
    
         
             
            		{
         
     | 
| 
       312 
320 
     | 
    
         
             
            			if ("emit-dts" != commands[0] && "gen-dts" != commands[0]) {
         
     | 
| 
       313 
321 
     | 
    
         
             
            				warnedDeprecatedEmitDtsAlias = !0
         
     | 
| 
      
 322 
     | 
    
         
            +
            				process.exitCode = 1
         
     | 
| 
       314 
323 
     | 
    
         
             
            				console.warn(
         
     | 
| 
       315 
324 
     | 
    
         
             
            					colourF(
         
     | 
| 
       316 
325 
     | 
    
         
             
            						`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n         in the next minor release of HSM\n         You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
         
     | 
| 
         @@ -330,7 +339,7 @@ switch (commands[0]) { 
     | 
|
| 
       330 
339 
     | 
    
         
             
            				typeDeclaration = await generateTypeDeclaration(sourcePath, hackmudPath)
         
     | 
| 
       331 
340 
     | 
    
         
             
            			let typeDeclarationPath = resolve(outputPath)
         
     | 
| 
       332 
341 
     | 
    
         
             
            			await writeFile(typeDeclarationPath, typeDeclaration).catch(error => {
         
     | 
| 
       333 
     | 
    
         
            -
            				assert(error instanceof Error, "src/bin/hsm.ts: 
     | 
| 
      
 342 
     | 
    
         
            +
            				assert(error instanceof Error, "src/bin/hsm.ts:438:35")
         
     | 
| 
       334 
343 
     | 
    
         
             
            				if ("EISDIR" != error.code) throw error
         
     | 
| 
       335 
344 
     | 
    
         
             
            				typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
         
     | 
| 
       336 
345 
     | 
    
         
             
            				return writeFile(typeDeclarationPath, typeDeclaration)
         
     | 
| 
         @@ -379,14 +388,14 @@ function logHelp() { 
     | 
|
| 
       379 
388 
     | 
    
         
             
            		case "gen-dts":
         
     | 
| 
       380 
389 
     | 
    
         
             
            		case "gen-types":
         
     | 
| 
       381 
390 
     | 
    
         
             
            		case "emit-dts":
         
     | 
| 
       382 
     | 
    
         
            -
            			warnedDeprecatedEmitDtsAlias  
     | 
| 
       383 
     | 
    
         
            -
            				 
     | 
| 
       384 
     | 
    
         
            -
            				"gen-dts" == commands[0] ||
         
     | 
| 
      
 391 
     | 
    
         
            +
            			if (!warnedDeprecatedEmitDtsAlias && "emit-dts" != commands[0] && "gen-dts" != commands[0]) {
         
     | 
| 
      
 392 
     | 
    
         
            +
            				process.exitCode = 1
         
     | 
| 
       385 
393 
     | 
    
         
             
            				console.warn(
         
     | 
| 
       386 
394 
     | 
    
         
             
            					colourF(
         
     | 
| 
       387 
395 
     | 
    
         
             
            						`${chalk.bold("Warning:")} ${colourC("hsm")} ${colourL(commands[0])} is deprecated and will be removed\n         in the next minor release of HSM\n         You should switch to using its alias ${colourC("hsm")} ${colourL("emit-dts")}\n`
         
     | 
| 
       388 
396 
     | 
    
         
             
            					)
         
     | 
| 
       389 
397 
     | 
    
         
             
            				)
         
     | 
| 
      
 398 
     | 
    
         
            +
            			}
         
     | 
| 
       390 
399 
     | 
    
         
             
            			console.log(
         
     | 
| 
       391 
400 
     | 
    
         
             
            				colourS(
         
     | 
| 
       392 
401 
     | 
    
         
             
            					`${colourJ("Generate a type declaration file for a directory of scripts")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [output path]")}\n\n${colourA("Options:")}\n${hackmudPathOption}`
         
     | 
| 
         @@ -403,7 +412,7 @@ function logHelp() { 
     | 
|
| 
       403 
412 
     | 
    
         
             
            		default:
         
     | 
| 
       404 
413 
     | 
    
         
             
            			console.log(
         
     | 
| 
       405 
414 
     | 
    
         
             
            				colourS(
         
     | 
| 
       406 
     | 
    
         
            -
            					`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1- 
     | 
| 
      
 415 
     | 
    
         
            +
            					`${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-93e7bef")}\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`
         
     | 
| 
       407 
416 
     | 
    
         
             
            				)
         
     | 
| 
       408 
417 
     | 
    
         
             
            			)
         
     | 
| 
       409 
418 
     | 
    
         
             
            	}
         
     | 
| 
         @@ -412,6 +421,7 @@ function logInfo({ path, users, characterCount, error, warnings }, hackmudPath) 
     | 
|
| 
       412 
421 
     | 
    
         
             
            	path = relative(".", path)
         
     | 
| 
       413 
422 
     | 
    
         
             
            	if (error) logError(`Error "${chalk.bold(error.message)}" in ${chalk.bold(path)}`)
         
     | 
| 
       414 
423 
     | 
    
         
             
            	else {
         
     | 
| 
      
 424 
     | 
    
         
            +
            		warnings.length && (process.exitCode = 1)
         
     | 
| 
       415 
425 
     | 
    
         
             
            		for (const warning of warnings) console.warn(colourF(`${chalk.bold("Warning:")} ${warning.message}`))
         
     | 
| 
       416 
426 
     | 
    
         
             
            		log(
         
     | 
| 
       417 
427 
     | 
    
         
             
            			`Pushed ${chalk.bold(path)} to ${users.map(user => chalk.bold(userColours.get(user))).join(", ")} | ${chalk.bold(characterCount + "")} chars | ${chalk.bold(resolve(hackmudPath, users[0], "scripts", basename(path, extname(path))) + ".js")}`
         
     | 
    
        package/env.d.ts
    CHANGED
    
    | 
         @@ -703,14 +703,14 @@ type MongoObject = { [k: string]: MongoValue, [k: `$${string}`]: never } 
     | 
|
| 
       703 
703 
     | 
    
         
             
            type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
         
     | 
| 
       704 
704 
     | 
    
         | 
| 
       705 
705 
     | 
    
         
             
            type MongoQueryObject =
         
     | 
| 
       706 
     | 
    
         
            -
            	{ [k: string]: MongoQueryValue, [k: `$${string}`]: MongoValue 
     | 
| 
      
 706 
     | 
    
         
            +
            	{ [k: string]: MongoQueryValue, [k: `$${string}`]: MongoValue } & { $type?: keyof MongoTypeStringsToTypes | (string & {}) }
         
     | 
| 
       707 
707 
     | 
    
         | 
| 
       708 
708 
     | 
    
         
             
            type MongoTypeStringsToTypes = {
         
     | 
| 
       709 
709 
     | 
    
         
             
            	double: number
         
     | 
| 
       710 
710 
     | 
    
         
             
            	string: string
         
     | 
| 
       711 
711 
     | 
    
         
             
            	object: MongoObject
         
     | 
| 
       712 
712 
     | 
    
         
             
            	array: MongoValue[]
         
     | 
| 
       713 
     | 
    
         
            -
            	objectId:  
     | 
| 
      
 713 
     | 
    
         
            +
            	objectId: MongoObjectId
         
     | 
| 
       714 
714 
     | 
    
         
             
            	bool: boolean
         
     | 
| 
       715 
715 
     | 
    
         
             
            	date: Date
         
     | 
| 
       716 
716 
     | 
    
         
             
            	null: null
         
     | 
| 
         @@ -720,8 +720,8 @@ type MongoTypeStringsToTypes = { 
     | 
|
| 
       720 
720 
     | 
    
         | 
| 
       721 
721 
     | 
    
         
             
            type MongoTypeString = keyof MongoTypeStringsToTypes
         
     | 
| 
       722 
722 
     | 
    
         
             
            type MongoTypeNumber = -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 127
         
     | 
| 
       723 
     | 
    
         
            -
            type MongoId = Exclude<MongoPrimitive, null> | MongoObject
         
     | 
| 
       724 
     | 
    
         
            -
            type MongoQueryId = Exclude<MongoPrimitive, null> | MongoQueryObject
         
     | 
| 
      
 723 
     | 
    
         
            +
            type MongoId = Exclude<MongoPrimitive, null | false> | MongoObjectId | MongoObject
         
     | 
| 
      
 724 
     | 
    
         
            +
            type MongoQueryId = Exclude<MongoPrimitive, null | false> | MongoObjectId | MongoQueryObject
         
     | 
| 
       725 
725 
     | 
    
         
             
            type MongoDocument = MongoObject & { _id?: MongoId }
         
     | 
| 
       726 
726 
     | 
    
         | 
| 
       727 
727 
     | 
    
         
             
            type MongoQueryType<TQuery extends MongoQueryObject> = {
         
     | 
| 
         @@ -865,8 +865,8 @@ type BrainContext = Replace<CliContext, { /** Whether the script is being run vi 
     | 
|
| 
       865 
865 
     | 
    
         
             
            // when anyField: true is given, other fields (except _id) are omitted
         
     | 
| 
       866 
866 
     | 
    
         | 
| 
       867 
867 
     | 
    
         
             
            type MongoProject<TDocument, TProjection> =
         
     | 
| 
       868 
     | 
    
         
            -
            	 
     | 
| 
       869 
     | 
    
         
            -
            		 
     | 
| 
      
 868 
     | 
    
         
            +
            	(TProjection extends { _id: false | 0 } ? {} : { _id: TDocument extends { _id: infer TId } ? TId : MongoId }) & (
         
     | 
| 
      
 869 
     | 
    
         
            +
            		true extends (1 extends TProjection[keyof TProjection] ? true : TProjection[keyof TProjection]) ?
         
     | 
| 
       870 
870 
     | 
    
         
             
            			{
         
     | 
| 
       871 
871 
     | 
    
         
             
            				[K in
         
     | 
| 
       872 
872 
     | 
    
         
             
            					keyof TDocument as K extends keyof TProjection ? TProjection[K] extends true | 1 ? K : never : never
         
     | 
| 
         @@ -877,7 +877,8 @@ type MongoProject<TDocument, TProjection> = 
     | 
|
| 
       877 
877 
     | 
    
         
             
            					keyof TProjection as TProjection[K] extends true | 1 ? K extends keyof TDocument ? never : K : never
         
     | 
| 
       878 
878 
     | 
    
         
             
            				]?: MongoValue
         
     | 
| 
       879 
879 
     | 
    
         
             
            			}
         
     | 
| 
       880 
     | 
    
         
            -
             
     | 
| 
      
 880 
     | 
    
         
            +
            		: { [k: string]: MongoValue } & { [K in keyof TDocument as K extends keyof TProjection ? never : K]: TDocument[K] }
         
     | 
| 
      
 881 
     | 
    
         
            +
            	)
         
     | 
| 
       881 
882 
     | 
    
         | 
| 
       882 
883 
     | 
    
         
             
            type DeepFreeze<T> = { readonly [P in keyof T]: DeepFreeze<T[P]> }
         
     | 
| 
       883 
884 
     | 
    
         | 
| 
         @@ -885,9 +886,9 @@ declare global { 
     | 
|
| 
       885 
886 
     | 
    
         
             
            	type ScriptSuccess<T = unknown> = { ok: true } & T
         
     | 
| 
       886 
887 
     | 
    
         
             
            	type ScriptFailure = { ok: false, msg?: string }
         
     | 
| 
       887 
888 
     | 
    
         
             
            	type ScriptResponse<T = unknown> = ScriptSuccess<T> | ScriptFailure
         
     | 
| 
       888 
     | 
    
         
            -
            	type Scriptor<TArgs  
     | 
| 
      
 889 
     | 
    
         
            +
            	type Scriptor<TArgs = any> = { name: string, call: (args: TArgs) => unknown }
         
     | 
| 
       889 
890 
     | 
    
         
             
            	type Context = CliContext | SubscriptContext | ScriptorContext | BrainContext
         
     | 
| 
       890 
     | 
    
         
            -
            	type  
     | 
| 
      
 891 
     | 
    
         
            +
            	type MongoObjectId = { $oid: string }
         
     | 
| 
       891 
892 
     | 
    
         | 
| 
       892 
893 
     | 
    
         
             
            	interface PlayerFullsec {}
         
     | 
| 
       893 
894 
     | 
    
         
             
            	interface PlayerHighsec {}
         
     | 
| 
         @@ -978,7 +979,7 @@ declare global { 
     | 
|
| 
       978 
979 
     | 
    
         
             
            		us: <T extends MongoDocument>(query: MongoQuery<T> | MongoQuery<T>[], command: MongoUpdateCommand<T>) =>
         
     | 
| 
       979 
980 
     | 
    
         
             
            			{ n: number, ok: 0 | 1, opTime: { t: number }, nModified: number }[]
         
     | 
| 
       980 
981 
     | 
    
         | 
| 
       981 
     | 
    
         
            -
            		ObjectId: () =>  
     | 
| 
      
 982 
     | 
    
         
            +
            		ObjectId: () => MongoObjectId
         
     | 
| 
       982 
983 
     | 
    
         
             
            	}
         
     | 
| 
       983 
984 
     | 
    
         | 
| 
       984 
985 
     | 
    
         
             
            	/** Debug Log.
         
     | 
    
        package/package.json
    CHANGED
    
    
| 
         @@ -2,155 +2,95 @@ import babelGenerator from "@babel/generator" 
     | 
|
| 
       2 
2 
     | 
    
         
             
            import { parse } from "@babel/parser"
         
     | 
| 
       3 
3 
     | 
    
         
             
            import babelTraverse from "@babel/traverse"
         
     | 
| 
       4 
4 
     | 
    
         
             
            import t from "@babel/types"
         
     | 
| 
       5 
     | 
    
         
            -
            import { assert 
     | 
| 
      
 5 
     | 
    
         
            +
            import { assert } from "@samual/lib/assert"
         
     | 
| 
       6 
6 
     | 
    
         
             
            import { spliceString } from "@samual/lib/spliceString"
         
     | 
| 
       7 
7 
     | 
    
         
             
            import { tokenizer, tokTypes } from "acorn"
         
     | 
| 
       8 
8 
     | 
    
         
             
            import { resolve } from "import-meta-resolve"
         
     | 
| 
       9 
     | 
    
         
            -
            import { validDBMethods } from "../constants.js"
         
     | 
| 
       10 
9 
     | 
    
         
             
            const { default: traverse } = babelTraverse,
         
     | 
| 
       11 
10 
     | 
    
         
             
            	{ default: generate } = babelGenerator,
         
     | 
| 
       12 
     | 
    
         
            -
            	SUBSCRIPT_PREFIXES = ["s", "fs", "4s", "hs", "3s", "ms", "2s", "ls", "1s", "ns", "0s"] 
     | 
| 
       13 
     | 
    
         
            -
            	PREPROCESSOR_NAMES = [...SUBSCRIPT_PREFIXES, "D", "G", "FMCL", "db"]
         
     | 
| 
      
 11 
     | 
    
         
            +
            	SUBSCRIPT_PREFIXES = ["s", "fs", "4s", "hs", "3s", "ms", "2s", "ls", "1s", "ns", "0s"]
         
     | 
| 
       14 
12 
     | 
    
         
             
            async function preprocess(code, { uniqueId = "00000000000" } = {}) {
         
     | 
| 
       15 
     | 
    
         
            -
            	assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts: 
     | 
| 
       16 
     | 
    
         
            -
            	const  
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            		 
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            		 
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            		 
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
            	assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:26:36")
         
     | 
| 
      
 14 
     | 
    
         
            +
            	const tokensIterable = tokenizer(code, { ecmaVersion: "latest" })
         
     | 
| 
      
 15 
     | 
    
         
            +
            	for (const token of tokensIterable) {
         
     | 
| 
      
 16 
     | 
    
         
            +
            		assert("value" in token, "src/processScript/preprocess.ts:31:28")
         
     | 
| 
      
 17 
     | 
    
         
            +
            		if (token.type != tokTypes.privateId) continue
         
     | 
| 
      
 18 
     | 
    
         
            +
            		assert("string" == typeof token.value, "src/processScript/preprocess.ts:36:42")
         
     | 
| 
      
 19 
     | 
    
         
            +
            		if (!SUBSCRIPT_PREFIXES.includes(token.value)) continue
         
     | 
| 
      
 20 
     | 
    
         
            +
            		const nextToken = tokensIterable.getToken()
         
     | 
| 
      
 21 
     | 
    
         
            +
            		if (nextToken.type != tokTypes._in && nextToken.type != tokTypes.dot)
         
     | 
| 
      
 22 
     | 
    
         
            +
            			throw SyntaxError("Subscripts must be in the form of #fs.foo.bar")
         
     | 
| 
      
 23 
     | 
    
         
            +
            	}
         
     | 
| 
      
 24 
     | 
    
         
            +
            	const sourceCode = code
         
     | 
| 
      
 25 
     | 
    
         
            +
            	let lengthBefore, file, program
         
     | 
| 
      
 26 
     | 
    
         
            +
            	do {
         
     | 
| 
      
 27 
     | 
    
         
            +
            		lengthBefore = code.length
         
     | 
| 
      
 28 
     | 
    
         
            +
            		code = code
         
     | 
| 
      
 29 
     | 
    
         
            +
            			.replace(/^\s+/, "")
         
     | 
| 
      
 30 
     | 
    
         
            +
            			.replace(/^\/\/.*/, "")
         
     | 
| 
      
 31 
     | 
    
         
            +
            			.replace(/^\/\*[\s\S]*?\*\//, "")
         
     | 
| 
      
 32 
     | 
    
         
            +
            	} while (code.length != lengthBefore)
         
     | 
| 
      
 33 
     | 
    
         
            +
            	code = code.replace(/^function\s*\(/, "export default function (")
         
     | 
| 
      
 34 
     | 
    
         
            +
            	for (;;) {
         
     | 
| 
      
 35 
     | 
    
         
            +
            		let error
         
     | 
| 
      
 36 
     | 
    
         
            +
            		try {
         
     | 
| 
      
 37 
     | 
    
         
            +
            			file = parse(code, {
         
     | 
| 
      
 38 
     | 
    
         
            +
            				plugins: [
         
     | 
| 
      
 39 
     | 
    
         
            +
            					"typescript",
         
     | 
| 
      
 40 
     | 
    
         
            +
            					["decorators", { decoratorsBeforeExport: !0 }],
         
     | 
| 
      
 41 
     | 
    
         
            +
            					"doExpressions",
         
     | 
| 
      
 42 
     | 
    
         
            +
            					"functionBind",
         
     | 
| 
      
 43 
     | 
    
         
            +
            					"functionSent",
         
     | 
| 
      
 44 
     | 
    
         
            +
            					"partialApplication",
         
     | 
| 
      
 45 
     | 
    
         
            +
            					["pipelineOperator", { proposal: "hack", topicToken: "%" }],
         
     | 
| 
      
 46 
     | 
    
         
            +
            					"throwExpressions",
         
     | 
| 
      
 47 
     | 
    
         
            +
            					["recordAndTuple", { syntaxType: "hash" }],
         
     | 
| 
      
 48 
     | 
    
         
            +
            					"classProperties",
         
     | 
| 
      
 49 
     | 
    
         
            +
            					"classPrivateProperties",
         
     | 
| 
      
 50 
     | 
    
         
            +
            					"classPrivateMethods",
         
     | 
| 
      
 51 
     | 
    
         
            +
            					"logicalAssignment",
         
     | 
| 
      
 52 
     | 
    
         
            +
            					"numericSeparator",
         
     | 
| 
      
 53 
     | 
    
         
            +
            					"nullishCoalescingOperator",
         
     | 
| 
      
 54 
     | 
    
         
            +
            					"optionalChaining",
         
     | 
| 
      
 55 
     | 
    
         
            +
            					"optionalCatchBinding",
         
     | 
| 
      
 56 
     | 
    
         
            +
            					"objectRestSpread"
         
     | 
| 
      
 57 
     | 
    
         
            +
            				],
         
     | 
| 
      
 58 
     | 
    
         
            +
            				sourceType: "module"
         
     | 
| 
      
 59 
     | 
    
         
            +
            			})
         
     | 
| 
      
 60 
     | 
    
         
            +
            			break
         
     | 
| 
      
 61 
     | 
    
         
            +
            		} catch (error_) {
         
     | 
| 
      
 62 
     | 
    
         
            +
            			assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:89:42")
         
     | 
| 
      
 63 
     | 
    
         
            +
            			error = error_
         
     | 
| 
      
 64 
     | 
    
         
            +
            		}
         
     | 
| 
      
 65 
     | 
    
         
            +
            		if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
         
     | 
| 
      
 66 
     | 
    
         
            +
            			console.log(/.+/.exec(code.slice(error.pos))?.[0])
         
     | 
| 
      
 67 
     | 
    
         
            +
            			throw error
         
     | 
| 
      
 68 
     | 
    
         
            +
            		}
         
     | 
| 
      
 69 
     | 
    
         
            +
            		const codeSlice = code.slice(error.pos)
         
     | 
| 
      
 70 
     | 
    
         
            +
            		let match
         
     | 
| 
      
 71 
     | 
    
         
            +
            		if ((match = /^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(codeSlice)))
         
     | 
| 
      
 72 
     | 
    
         
            +
            			code = spliceString(code, JSON.stringify(sourceCode), error.pos, match[0].length)
         
     | 
| 
      
 73 
     | 
    
         
            +
            		else if ((match = /^#[0-4fhmln]?s\./.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
         
     | 
| 
      
 74 
     | 
    
         
            +
            		else if ((match = /^#D[^\w$]/.exec(codeSlice))) code = spliceString(code, "$", error.pos, 1)
         
     | 
| 
      
 75 
     | 
    
         
            +
            		else if ((match = /^#FMCL/.exec(codeSlice)))
         
     | 
| 
      
 76 
     | 
    
         
            +
            			code = spliceString(code, `$${uniqueId}$FMCL$`, error.pos, match[0].length)
         
     | 
| 
      
 77 
     | 
    
         
            +
            		else if ((match = /^#G/.exec(codeSlice)))
         
     | 
| 
      
 78 
     | 
    
         
            +
            			code = spliceString(code, `$${uniqueId}$GLOBAL$`, error.pos, match[0].length)
         
     | 
| 
      
 79 
     | 
    
         
            +
            		else {
         
     | 
| 
      
 80 
     | 
    
         
            +
            			if (!(match = /^#db\./.exec(codeSlice))) throw error
         
     | 
| 
      
 81 
     | 
    
         
            +
            			code = spliceString(code, "$", error.pos, 1)
         
     | 
| 
       28 
82 
     | 
    
         
             
            		}
         
     | 
| 
       29 
83 
     | 
    
         
             
            	}
         
     | 
| 
       30 
     | 
    
         
            -
            	 
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            			plugins: [
         
     | 
| 
       35 
     | 
    
         
            -
            				"typescript",
         
     | 
| 
       36 
     | 
    
         
            -
            				["decorators", { decoratorsBeforeExport: !0 }],
         
     | 
| 
       37 
     | 
    
         
            -
            				"doExpressions",
         
     | 
| 
       38 
     | 
    
         
            -
            				"functionBind",
         
     | 
| 
       39 
     | 
    
         
            -
            				"functionSent",
         
     | 
| 
       40 
     | 
    
         
            -
            				"partialApplication",
         
     | 
| 
       41 
     | 
    
         
            -
            				["pipelineOperator", { proposal: "hack", topicToken: "%" }],
         
     | 
| 
       42 
     | 
    
         
            -
            				"throwExpressions",
         
     | 
| 
       43 
     | 
    
         
            -
            				["recordAndTuple", { syntaxType: "hash" }],
         
     | 
| 
       44 
     | 
    
         
            -
            				"classProperties",
         
     | 
| 
       45 
     | 
    
         
            -
            				"classPrivateProperties",
         
     | 
| 
       46 
     | 
    
         
            -
            				"classPrivateMethods",
         
     | 
| 
       47 
     | 
    
         
            -
            				"logicalAssignment",
         
     | 
| 
       48 
     | 
    
         
            -
            				"numericSeparator",
         
     | 
| 
       49 
     | 
    
         
            -
            				"nullishCoalescingOperator",
         
     | 
| 
       50 
     | 
    
         
            -
            				"optionalChaining",
         
     | 
| 
       51 
     | 
    
         
            -
            				"optionalCatchBinding",
         
     | 
| 
       52 
     | 
    
         
            -
            				"objectRestSpread"
         
     | 
| 
       53 
     | 
    
         
            -
            			],
         
     | 
| 
       54 
     | 
    
         
            -
            			sourceType: "module"
         
     | 
| 
       55 
     | 
    
         
            -
            		}),
         
     | 
| 
       56 
     | 
    
         
            -
            		{
         
     | 
| 
       57 
     | 
    
         
            -
            			Program(path) {
         
     | 
| 
       58 
     | 
    
         
            -
            				program = path
         
     | 
| 
       59 
     | 
    
         
            -
            			},
         
     | 
| 
       60 
     | 
    
         
            -
            			Identifier(path) {
         
     | 
| 
       61 
     | 
    
         
            -
            				if (!path.node.name.startsWith(maybePrivatePrefix)) return
         
     | 
| 
       62 
     | 
    
         
            -
            				const name = path.node.name.slice(maybePrivatePrefix.length)
         
     | 
| 
       63 
     | 
    
         
            -
            				if ("ClassProperty" == path.parent.type && path.parent.key == path.node)
         
     | 
| 
       64 
     | 
    
         
            -
            					path.parentPath.replaceWith(
         
     | 
| 
       65 
     | 
    
         
            -
            						t.classPrivateProperty(
         
     | 
| 
       66 
     | 
    
         
            -
            							t.privateName(t.identifier(name)),
         
     | 
| 
       67 
     | 
    
         
            -
            							path.parent.value,
         
     | 
| 
       68 
     | 
    
         
            -
            							path.parent.decorators,
         
     | 
| 
       69 
     | 
    
         
            -
            							path.parent.static
         
     | 
| 
       70 
     | 
    
         
            -
            						)
         
     | 
| 
       71 
     | 
    
         
            -
            					)
         
     | 
| 
       72 
     | 
    
         
            -
            				else if ("MemberExpression" == path.parent.type)
         
     | 
| 
       73 
     | 
    
         
            -
            					if (path.parent.property == path.node) {
         
     | 
| 
       74 
     | 
    
         
            -
            						assert(!path.parent.computed, "src/processScript/preprocess.ts:95:36")
         
     | 
| 
       75 
     | 
    
         
            -
            						path.replaceWith(t.privateName(t.identifier(name)))
         
     | 
| 
       76 
     | 
    
         
            -
            					} else {
         
     | 
| 
       77 
     | 
    
         
            -
            						assert(path.parent.object == path.node, "src/processScript/preprocess.ts:98:46")
         
     | 
| 
       78 
     | 
    
         
            -
            						if ("db" == name) {
         
     | 
| 
       79 
     | 
    
         
            -
            							if (path.parent.computed)
         
     | 
| 
       80 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       81 
     | 
    
         
            -
            									"Index notation cannot be used on #db, must be in the form of #db.<DB method name>"
         
     | 
| 
       82 
     | 
    
         
            -
            								)
         
     | 
| 
       83 
     | 
    
         
            -
            							if ("Identifier" != path.parent.property.type)
         
     | 
| 
       84 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       85 
     | 
    
         
            -
            									`Expected DB method name to be an Identifier, got ${path.parent.property.type} instead`
         
     | 
| 
       86 
     | 
    
         
            -
            								)
         
     | 
| 
       87 
     | 
    
         
            -
            							if (!validDBMethods.includes(path.parent.property.name))
         
     | 
| 
       88 
     | 
    
         
            -
            								throw Error("Invalid DB method #db." + path.parent.property.name)
         
     | 
| 
       89 
     | 
    
         
            -
            							path.node.name = "$db"
         
     | 
| 
       90 
     | 
    
         
            -
            						} else {
         
     | 
| 
       91 
     | 
    
         
            -
            							assert(SUBSCRIPT_PREFIXES.includes(name), "src/processScript/preprocess.ts:112:49")
         
     | 
| 
       92 
     | 
    
         
            -
            							if (path.parent.computed)
         
     | 
| 
       93 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       94 
     | 
    
         
            -
            									`Index notation cannot be used for subscripts, must be in the form of #${name}.foo.bar`
         
     | 
| 
       95 
     | 
    
         
            -
            								)
         
     | 
| 
       96 
     | 
    
         
            -
            							if ("Identifier" != path.parent.property.type)
         
     | 
| 
       97 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       98 
     | 
    
         
            -
            									`Expected subscript user name to be Identifier but got ${path.parent.property.type} instead`
         
     | 
| 
       99 
     | 
    
         
            -
            								)
         
     | 
| 
       100 
     | 
    
         
            -
            							if ("MemberExpression" != path.parentPath.parent.type)
         
     | 
| 
       101 
     | 
    
         
            -
            								throw Error(`Subscripts must be in the form of #${name}.foo.bar`)
         
     | 
| 
       102 
     | 
    
         
            -
            							if (path.parentPath.parent.computed)
         
     | 
| 
       103 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       104 
     | 
    
         
            -
            									`Index notation cannot be used for subscripts, must be in the form of #${name}.foo.bar`
         
     | 
| 
       105 
     | 
    
         
            -
            								)
         
     | 
| 
       106 
     | 
    
         
            -
            							if ("Identifier" != path.parentPath.parent.property.type)
         
     | 
| 
       107 
     | 
    
         
            -
            								throw Error(
         
     | 
| 
       108 
     | 
    
         
            -
            									`Expected subscript subname to be Identifier but got ${path.parent.property.type} instead`
         
     | 
| 
       109 
     | 
    
         
            -
            								)
         
     | 
| 
       110 
     | 
    
         
            -
            							"CallExpression" == path.parentPath.parentPath?.parent.type &&
         
     | 
| 
       111 
     | 
    
         
            -
            							"scripts" == path.parent.property.name &&
         
     | 
| 
       112 
     | 
    
         
            -
            							"quine" == path.parentPath.parent.property.name
         
     | 
| 
       113 
     | 
    
         
            -
            								? ensure(
         
     | 
| 
       114 
     | 
    
         
            -
            										path.parentPath.parentPath.parentPath,
         
     | 
| 
       115 
     | 
    
         
            -
            										"src/processScript/preprocess.ts:134:54"
         
     | 
| 
       116 
     | 
    
         
            -
            									).replaceWith(t.stringLiteral(sourceCode))
         
     | 
| 
       117 
     | 
    
         
            -
            								: (path.node.name = "$" + name)
         
     | 
| 
       118 
     | 
    
         
            -
            						}
         
     | 
| 
       119 
     | 
    
         
            -
            					}
         
     | 
| 
       120 
     | 
    
         
            -
            				else if (
         
     | 
| 
       121 
     | 
    
         
            -
            					"BinaryExpression" == path.parent.type &&
         
     | 
| 
       122 
     | 
    
         
            -
            					path.parent.left == path.node &&
         
     | 
| 
       123 
     | 
    
         
            -
            					"in" == path.parent.operator
         
     | 
| 
       124 
     | 
    
         
            -
            				)
         
     | 
| 
       125 
     | 
    
         
            -
            					path.replaceWith(t.privateName(t.identifier(name)))
         
     | 
| 
       126 
     | 
    
         
            -
            				else if ("ClassMethod" == path.parent.type && path.parent.key == path.node) {
         
     | 
| 
       127 
     | 
    
         
            -
            					assert("constructor" != path.parent.kind, "src/processScript/preprocess.ts:142:47")
         
     | 
| 
       128 
     | 
    
         
            -
            					path.parentPath.replaceWith(
         
     | 
| 
       129 
     | 
    
         
            -
            						t.classPrivateMethod(
         
     | 
| 
       130 
     | 
    
         
            -
            							path.parent.kind,
         
     | 
| 
       131 
     | 
    
         
            -
            							t.privateName(t.identifier(name)),
         
     | 
| 
       132 
     | 
    
         
            -
            							path.parent.params,
         
     | 
| 
       133 
     | 
    
         
            -
            							path.parent.body,
         
     | 
| 
       134 
     | 
    
         
            -
            							path.parent.static
         
     | 
| 
       135 
     | 
    
         
            -
            						)
         
     | 
| 
       136 
     | 
    
         
            -
            					)
         
     | 
| 
       137 
     | 
    
         
            -
            				} else if ("FMCL" == name) path.node.name = `$${uniqueId}$FMCL$`
         
     | 
| 
       138 
     | 
    
         
            -
            				else if ("G" == name) path.node.name = `$${uniqueId}$GLOBAL$`
         
     | 
| 
       139 
     | 
    
         
            -
            				else {
         
     | 
| 
       140 
     | 
    
         
            -
            					if ("D" != name) {
         
     | 
| 
       141 
     | 
    
         
            -
            						if ("db" == name) throw Error("Invalid #db syntax, must be in the form of #db.<DB method name>")
         
     | 
| 
       142 
     | 
    
         
            -
            						assert(SUBSCRIPT_PREFIXES.includes(name), "src/processScript/preprocess.ts:161:51 " + name)
         
     | 
| 
       143 
     | 
    
         
            -
            						throw Error(`Invalid subscript syntax, must be in the form of #${name}.foo.bar`)
         
     | 
| 
       144 
     | 
    
         
            -
            					}
         
     | 
| 
       145 
     | 
    
         
            -
            					path.node.name = "$D"
         
     | 
| 
       146 
     | 
    
         
            -
            				}
         
     | 
| 
       147 
     | 
    
         
            -
            			}
         
     | 
| 
      
 84 
     | 
    
         
            +
            	traverse(file, {
         
     | 
| 
      
 85 
     | 
    
         
            +
            		Program(path) {
         
     | 
| 
      
 86 
     | 
    
         
            +
            			program = path
         
     | 
| 
      
 87 
     | 
    
         
            +
            			path.skip()
         
     | 
| 
       148 
88 
     | 
    
         
             
            		}
         
     | 
| 
       149 
     | 
    
         
            -
            	)
         
     | 
| 
      
 89 
     | 
    
         
            +
            	})
         
     | 
| 
       150 
90 
     | 
    
         
             
            	const needRecord = program.scope.hasGlobal("Record"),
         
     | 
| 
       151 
91 
     | 
    
         
             
            		needTuple = program.scope.hasGlobal("Tuple")
         
     | 
| 
       152 
92 
     | 
    
         
             
            	;(needRecord || needTuple) &&
         
     | 
| 
       153 
     | 
    
         
            -
            		program. 
     | 
| 
      
 93 
     | 
    
         
            +
            		file.program.body.unshift(
         
     | 
| 
       154 
94 
     | 
    
         
             
            			t.importDeclaration(
         
     | 
| 
       155 
95 
     | 
    
         
             
            				needRecord
         
     | 
| 
       156 
96 
     | 
    
         
             
            					? needTuple
         
     | 
| 
         @@ -164,7 +104,7 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) { 
     | 
|
| 
       164 
104 
     | 
    
         
             
            			)
         
     | 
| 
       165 
105 
     | 
    
         
             
            		)
         
     | 
| 
       166 
106 
     | 
    
         
             
            	program.scope.hasGlobal("Proxy") &&
         
     | 
| 
       167 
     | 
    
         
            -
            		program. 
     | 
| 
      
 107 
     | 
    
         
            +
            		file.program.body.unshift(
         
     | 
| 
       168 
108 
     | 
    
         
             
            			t.importDeclaration(
         
     | 
| 
       169 
109 
     | 
    
         
             
            				[t.importDefaultSpecifier(t.identifier("Proxy"))],
         
     | 
| 
       170 
110 
     | 
    
         
             
            				t.stringLiteral(resolve("proxy-polyfill/src/proxy.js", import.meta.url).slice(7))
         
     | 
| 
         @@ -174,6 +114,6 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) { 
     | 
|
| 
       174 
114 
     | 
    
         
             
            		throw Error(
         
     | 
| 
       175 
115 
     | 
    
         
             
            			"Scripts that only contain a single function declaration are no longer supported.\nPrefix the function declaration with `export default`."
         
     | 
| 
       176 
116 
     | 
    
         
             
            		)
         
     | 
| 
       177 
     | 
    
         
            -
            	return { code: generate( 
     | 
| 
      
 117 
     | 
    
         
            +
            	return { code: generate(file).code }
         
     | 
| 
       178 
118 
     | 
    
         
             
            }
         
     | 
| 
       179 
119 
     | 
    
         
             
            export { preprocess }
         
     |