storm-lua-minify 0.3.0 → 0.9.0

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.
Files changed (43) hide show
  1. package/README.md +119 -41
  2. package/dist/aggregateSpecialization.js +406 -0
  3. package/dist/ast2lua.js +156 -68
  4. package/dist/astWalk.js +162 -0
  5. package/dist/callGraph.js +372 -0
  6. package/dist/cli.js +53 -58
  7. package/dist/cliOptions.js +36 -0
  8. package/dist/cliProgress.js +87 -0
  9. package/dist/config.js +73 -0
  10. package/dist/constantFold.js +798 -0
  11. package/dist/controlFlow.js +266 -0
  12. package/dist/functionRewrites.js +580 -0
  13. package/dist/generatedAst.js +108 -0
  14. package/dist/generatedNode.js +23 -0
  15. package/dist/interproceduralAnalysis.js +842 -0
  16. package/dist/interproceduralConstants.js +120 -0
  17. package/dist/luaString.js +157 -0
  18. package/dist/minifier.js +1178 -44
  19. package/dist/optimizerAnalysis.js +43 -0
  20. package/dist/optimizerDiagnostics.js +65 -0
  21. package/dist/optimizerFacts.js +529 -0
  22. package/dist/optimizerPass.js +96 -0
  23. package/dist/optimizerTransaction.js +56 -0
  24. package/dist/optimizerValueDomain.js +180 -0
  25. package/dist/options.js +233 -0
  26. package/dist/progress.js +2 -0
  27. package/dist/removeUnused.js +145 -0
  28. package/dist/renamer.js +223 -54
  29. package/dist/resolver.js +28 -11
  30. package/dist/runtimeEnvironment.js +105 -0
  31. package/dist/sourceMetadata.js +314 -0
  32. package/dist/statementDataflow.js +259 -0
  33. package/dist/statementScheduler.js +595 -0
  34. package/dist/symbolLiveness.js +92 -0
  35. package/dist/tableEffects.js +356 -0
  36. package/dist/transform.js +10 -371
  37. package/dist/valueFlow.js +409 -0
  38. package/dist/wholeProgramExports.js +646 -0
  39. package/dist/wholeProgramFieldRenames.js +583 -0
  40. package/dist/wholeProgramFields.js +672 -0
  41. package/dist/wholeProgramObjects.js +783 -0
  42. package/package.json +11 -2
  43. package/dist/index.js +0 -27
package/dist/config.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseConfiguration = parseConfiguration;
7
+ exports.loadConfiguration = loadConfiguration;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const options_1 = require("./options");
10
+ const booleanKeys = new Map([
11
+ ...options_1.optimizationOptionDefinitions.map((definition) => [definition.name, definition.key]),
12
+ ["require-wrapper", "requireWrapper"],
13
+ ["allow-introspection-changes", "allowIntrospectionChanges"],
14
+ ["allow-observable-table-read-changes", "allowObservableTableReadChanges"],
15
+ ["assume-annotations", "assumeAnnotations"],
16
+ ["collect-optimization-diagnostics", "collectOptimizationDiagnostics"],
17
+ ]);
18
+ const nonBooleanKeys = new Set([
19
+ "runtime-profile",
20
+ "required-whitespace",
21
+ "never-rename-globals",
22
+ "source-mapping-url-style",
23
+ ]);
24
+ function objectOf(value, path) {
25
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
26
+ throw new Error(`${path} must contain a JSON object`);
27
+ }
28
+ return value;
29
+ }
30
+ function parseConfiguration(value, path = "configuration") {
31
+ const input = objectOf(value, path);
32
+ const mode = {};
33
+ let sourceMappingUrlStyle;
34
+ Object.entries(input).forEach(([externalName, rawValue]) => {
35
+ const booleanKey = booleanKeys.get(externalName);
36
+ if (booleanKey !== undefined) {
37
+ if (typeof rawValue !== "boolean")
38
+ throw new Error(`${path}: ${externalName} must be boolean`);
39
+ mode[booleanKey] = rawValue;
40
+ return;
41
+ }
42
+ if (!nonBooleanKeys.has(externalName))
43
+ throw new Error(`${path}: unknown option ${externalName}`);
44
+ if (externalName === "runtime-profile") {
45
+ if (rawValue !== "stormworks" && rawValue !== "lua53")
46
+ throw new Error(`${path}: runtime-profile must be stormworks or lua53`);
47
+ mode.runtimeProfile = rawValue;
48
+ return;
49
+ }
50
+ if (externalName === "required-whitespace") {
51
+ if (rawValue !== "space" && rawValue !== "lf")
52
+ throw new Error(`${path}: required-whitespace must be space or LF`);
53
+ mode.requiredWhitespace = rawValue === "space" ? " " : "\n";
54
+ return;
55
+ }
56
+ if (externalName === "never-rename-globals") {
57
+ if (!Array.isArray(rawValue) ||
58
+ !rawValue.every((name) => typeof name === "string"))
59
+ throw new Error(`${path}: never-rename-globals must be an array of strings`);
60
+ mode.neverRenameGlobals = new Set(rawValue);
61
+ return;
62
+ }
63
+ if (rawValue !== "legacy" && rawValue !== "line" && rawValue !== "strict")
64
+ throw new Error(`${path}: source-mapping-url-style must be legacy, line, or strict`);
65
+ sourceMappingUrlStyle = rawValue;
66
+ });
67
+ return { mode, sourceMappingUrlStyle };
68
+ }
69
+ function loadConfiguration(path) {
70
+ if (!fs_1.default.existsSync(path))
71
+ throw new Error(`Configuration file not found: ${path}`);
72
+ return parseConfiguration(JSON.parse(fs_1.default.readFileSync(path, "utf8")), path);
73
+ }