hackmud-script-manager 0.21.1-afae871 → 0.21.1-d4bf990

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 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-afae871")
66
+ console.log("0.21.1-d4bf990")
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-afae871")}\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`
414
+ `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1-d4bf990")}\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) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
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("${sourceDirectory}/${user}/${script}").default\n`
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.21.1-afae871",
3
+ "version": "0.21.1-d4bf990",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -1,21 +1,21 @@
1
- import babelGenerator from "@babel/generator"
1
+ import awpz3osbzbgie0diqla53jdp from "@babel/generator"
2
2
  import { parse } from "@babel/parser"
3
- import babelPluginProposalDecorators from "@babel/plugin-proposal-decorators"
4
- import babelPluginProposalDestructuringPrivate from "@babel/plugin-proposal-destructuring-private"
5
- import babelPluginProposalExplicitResourceManagement from "@babel/plugin-proposal-explicit-resource-management"
6
- import babelPluginTransformClassProperties from "@babel/plugin-transform-class-properties"
7
- import babelPluginTransformClassStaticBlock from "@babel/plugin-transform-class-static-block"
8
- import babelPluginTransformExponentiationOperator from "@babel/plugin-transform-exponentiation-operator"
9
- import babelPluginTransformJsonStrings from "@babel/plugin-transform-json-strings"
10
- import babelPluginTransformLogicalAssignmentOperators from "@babel/plugin-transform-logical-assignment-operators"
11
- import babelPluginTransformNullishCoalescingOperator from "@babel/plugin-transform-nullish-coalescing-operator"
12
- import babelPluginTransformNumericSeparator from "@babel/plugin-transform-numeric-separator"
13
- import babelPluginTransformObjectRestSpread from "@babel/plugin-transform-object-rest-spread"
14
- import babelPluginTransformOptionalCatchBinding from "@babel/plugin-transform-optional-catch-binding"
15
- import babelPluginTransformOptionalChaining from "@babel/plugin-transform-optional-chaining"
16
- import babelPluginTransformPrivatePropertyInObject from "@babel/plugin-transform-private-property-in-object"
17
- import babelPluginTransformUnicodeSetsRegex from "@babel/plugin-transform-unicode-sets-regex"
18
- import babelTraverse from "@babel/traverse"
3
+ import n7j5rk65x3x68f0977sx3p32 from "@babel/plugin-proposal-decorators"
4
+ import ta0frirmi3s2jq08l6cht3uk from "@babel/plugin-proposal-destructuring-private"
5
+ import k3l88m4rzomnxi1nyaws0uf4 from "@babel/plugin-proposal-explicit-resource-management"
6
+ import d8vrbov1hvzild8irq5ej6a5 from "@babel/plugin-transform-class-properties"
7
+ import yluenyq31jclk2gspvfqqhdw from "@babel/plugin-transform-class-static-block"
8
+ import s83tktwy1wj5yii2modwcpsu from "@babel/plugin-transform-exponentiation-operator"
9
+ import gjxa6uc9geesg3fse9p6nz2t from "@babel/plugin-transform-json-strings"
10
+ import hpo770a0fczabe5gqnfx5zuh from "@babel/plugin-transform-logical-assignment-operators"
11
+ import kzbxvgtuqrrh91fwlvcsrheu from "@babel/plugin-transform-nullish-coalescing-operator"
12
+ import meo269rn6bx4ct4wluvbjqan from "@babel/plugin-transform-numeric-separator"
13
+ import o997fnadhqb0j0fcvivsfr58 from "@babel/plugin-transform-object-rest-spread"
14
+ import sy7mwdqgoccmlrptsvyavb2g from "@babel/plugin-transform-optional-catch-binding"
15
+ import ylulmkigu6sywpswowfw2ont from "@babel/plugin-transform-optional-chaining"
16
+ import apo7v29f7l9cy104xqjwyavh from "@babel/plugin-transform-private-property-in-object"
17
+ import e4n14nj86a5rtu8hkil6ioxe from "@babel/plugin-transform-unicode-sets-regex"
18
+ import ons4yi64j2vp9u6vpqkt1emx 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 { format } = prettier,
42
- { default: generate } = babelGenerator,
43
- { default: traverse } = babelTraverse
41
+ const generate = awpz3osbzbgie0diqla53jdp.default,
42
+ babelPluginProposalDecorators = n7j5rk65x3x68f0977sx3p32.default,
43
+ babelPluginProposalDestructuringPrivate = ta0frirmi3s2jq08l6cht3uk.default,
44
+ babelPluginProposalExplicitResourceManagement = k3l88m4rzomnxi1nyaws0uf4.default,
45
+ babelPluginTransformClassProperties = d8vrbov1hvzild8irq5ej6a5.default,
46
+ babelPluginTransformClassStaticBlock = yluenyq31jclk2gspvfqqhdw.default,
47
+ babelPluginTransformExponentiationOperator = s83tktwy1wj5yii2modwcpsu.default,
48
+ babelPluginTransformJsonStrings = gjxa6uc9geesg3fse9p6nz2t.default,
49
+ babelPluginTransformLogicalAssignmentOperators = hpo770a0fczabe5gqnfx5zuh.default,
50
+ babelPluginTransformNullishCoalescingOperator = kzbxvgtuqrrh91fwlvcsrheu.default,
51
+ babelPluginTransformNumericSeparator = meo269rn6bx4ct4wluvbjqan.default,
52
+ babelPluginTransformObjectRestSpread = o997fnadhqb0j0fcvivsfr58.default,
53
+ babelPluginTransformOptionalCatchBinding = sy7mwdqgoccmlrptsvyavb2g.default,
54
+ babelPluginTransformOptionalChaining = ylulmkigu6sywpswowfw2ont.default,
55
+ babelPluginTransformPrivatePropertyInObject = apo7v29f7l9cy104xqjwyavh.default,
56
+ babelPluginTransformUnicodeSetsRegex = e4n14nj86a5rtu8hkil6ioxe.default,
57
+ traverse = ons4yi64j2vp9u6vpqkt1emx.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:81:36")
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:162:36")
135
+ assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:159:36")
121
136
  const plugins = [
122
- [babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
123
- [babelPluginTransformClassProperties.default],
124
- [babelPluginTransformClassStaticBlock.default],
125
- [babelPluginTransformPrivatePropertyInObject.default],
126
- [babelPluginTransformLogicalAssignmentOperators.default],
127
- [babelPluginTransformNumericSeparator.default],
128
- [babelPluginTransformNullishCoalescingOperator.default],
129
- [babelPluginTransformOptionalChaining.default],
130
- [babelPluginTransformOptionalCatchBinding.default],
131
- [babelPluginTransformJsonStrings.default],
132
- [babelPluginTransformObjectRestSpread.default],
133
- [babelPluginTransformExponentiationOperator.default],
134
- [babelPluginTransformUnicodeSetsRegex.default],
135
- [babelPluginProposalDestructuringPrivate.default],
136
- [babelPluginProposalExplicitResourceManagement.default]
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
- (await import("@babel/plugin-transform-typescript")).default,
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.default],
166
- [babelPluginProposalFunctionBind.default],
167
- [babelPluginProposalFunctionSent.default],
168
- [babelPluginProposalPartialApplication.default],
169
- [babelPluginProposalPipelineOperator.default, { proposal: "hack", topicToken: "%" }],
170
- [babelPluginProposalThrowExpressions.default],
171
- [babelPluginProposalRecordAndTuple.default, { syntaxType: "hash", importPolyfill: !0 }]
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.default, { allowDeclareFields: !0, optimizeConstEnums: !0 }],
197
- [babelPluginProposalDoExpressions.default],
198
- [babelPluginProposalFunctionBind.default],
199
- [babelPluginProposalFunctionSent.default],
200
- [babelPluginProposalPartialApplication.default],
201
- [babelPluginProposalPipelineOperator.default, { proposal: "hack", topicToken: "%" }],
202
- [babelPluginProposalThrowExpressions.default],
203
- [babelPluginProposalRecordAndTuple.default, { syntaxType: "hash", importPolyfill: !0 }]
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:326:60")
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:356:51")
301
+ assert("ObjectProperty" == property.type, "src/processScript/index.ts:353:51")
287
302
  renameVariables(property.value)
288
303
  }
289
304
  break
@@ -1,5 +1,5 @@
1
- import babelGenerator from "@babel/generator"
2
- import babelTraverse from "@babel/traverse"
1
+ import awpz3osbzbgie0diqla53jdp from "@babel/generator"
2
+ import ons4yi64j2vp9u6vpqkt1emx 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 { default: generate } = babelGenerator,
11
- { default: traverse } = babelTraverse,
10
+ const generate = awpz3osbzbgie0diqla53jdp.default,
11
+ traverse = ons4yi64j2vp9u6vpqkt1emx.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:46:36")
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:115:60")
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:249:62")
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:354:61")
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:485:43")
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:507:4"
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 babelGenerator from "@babel/generator"
1
+ import awpz3osbzbgie0diqla53jdp from "@babel/generator"
2
2
  import { parse } from "@babel/parser"
3
- import babelTraverse from "@babel/traverse"
3
+ import ons4yi64j2vp9u6vpqkt1emx 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 { default: traverse } = babelTraverse,
9
- { default: generate } = babelGenerator
8
+ const generate = awpz3osbzbgie0diqla53jdp.default,
9
+ traverse = ons4yi64j2vp9u6vpqkt1emx.default
10
10
  async function preprocess(code, { uniqueId = "00000000000" } = {}) {
11
- assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:23:36")
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:67:42")
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 babelTraverse from "@babel/traverse"
1
+ import ons4yi64j2vp9u6vpqkt1emx 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 { default: traverse } = babelTraverse,
7
+ const traverse = ons4yi64j2vp9u6vpqkt1emx.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:111:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:116:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:121:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:129:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:134:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:139:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
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:199:69")
145
- assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:200:72")
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:206:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
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:256:64")
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:274:64")
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:288:27 program is empty")
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:294:51 ${specifier.type} is currently unsupported`
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:408:59")
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:412:51 declarator.id.type was "${declarator.id.type}"`
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:431:23")
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:434:56")
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:491:37")
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:503:22")
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:506:55")
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:701:30")
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
@@ -658,7 +723,17 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
658
723
  !parent.superClass && thisIsReferenced && (parent.superClass = t.identifier("Object"))
659
724
  },
660
725
  VariableDeclaration({ node: variableDeclaration }) {
661
- "const" == variableDeclaration.kind && (variableDeclaration.kind = "let")
726
+ if ("const" == variableDeclaration.kind) {
727
+ variableDeclaration.kind = "let"
728
+ variableDeclaration.extra = { ...variableDeclaration.extra, usedToBeConst: !0 }
729
+ }
730
+ },
731
+ AssignmentExpression({ node: assignment, scope }) {
732
+ const lhs = assignment.left
733
+ if ("Identifier" != lhs.type) return
734
+ const binding = scope.getBinding(lhs.name)
735
+ if (binding?.path?.parentPath?.node?.extra?.usedToBeConst)
736
+ throw Error(`Reassignment to const variable ${lhs.name} is not allowed!`)
662
737
  },
663
738
  ThisExpression: path => {
664
739
  path.replaceWith(t.identifier("undefined"))
@@ -684,23 +759,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
684
759
  }
685
760
  function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
686
761
  for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
687
- assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:811:60")
762
+ assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:928:60")
688
763
  assert("Identifier" == referencePath.parent.property.type)
689
764
  assert(
690
765
  "MemberExpression" == referencePath.parentPath.parentPath?.node.type,
691
- "src/processScript/transform.ts:813:81"
766
+ "src/processScript/transform.ts:930:81"
692
767
  )
693
768
  assert(
694
769
  "Identifier" == referencePath.parentPath.parentPath.node.property.type,
695
- "src/processScript/transform.ts:814:83"
770
+ "src/processScript/transform.ts:931:83"
696
771
  )
697
772
  assert(
698
773
  /^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
699
- `src/processScript/transform.ts:818:8 invalid user "${referencePath.parent.property.name}" in subscript`
774
+ `src/processScript/transform.ts:935:8 invalid user "${referencePath.parent.property.name}" in subscript`
700
775
  )
701
776
  assert(
702
777
  /^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
703
- `src/processScript/transform.ts:823:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
778
+ `src/processScript/transform.ts:940:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
704
779
  )
705
780
  if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
706
781
  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"