mlogjs 0.5.2 → 0.6.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 (79) hide show
  1. package/README.md +2 -2
  2. package/dist/{index.cjs → Compiler-7GMG4MDr.js} +1746 -452
  3. package/dist/Compiler.d.ts +8 -12
  4. package/dist/CompilerError.d.ts +13 -3
  5. package/dist/Scope.d.ts +8 -8
  6. package/dist/bin/files.d.ts +18 -0
  7. package/dist/bin.mjs +170 -0
  8. package/dist/handlers/Import.d.ts +5 -0
  9. package/dist/handlers/Literal.d.ts +2 -2
  10. package/dist/handlers/Typescript.d.ts +2 -2
  11. package/dist/handlers/index.d.ts +1 -0
  12. package/dist/index.mjs +3 -4267
  13. package/dist/instructions/AddressResolver.d.ts +4 -4
  14. package/dist/instructions/ControlInstructions.d.ts +3 -3
  15. package/dist/instructions/InstructionBase.d.ts +1 -0
  16. package/dist/instructions/JumpInstruction.d.ts +5 -5
  17. package/dist/instructions/index.d.ts +0 -1
  18. package/dist/macros/DynamicArray.d.ts +4 -4
  19. package/dist/macros/Function.d.ts +2 -2
  20. package/dist/macros/GetBuildings.d.ts +4 -0
  21. package/dist/macros/GetColor.d.ts +4 -0
  22. package/dist/macros/Marker.d.ts +4 -0
  23. package/dist/macros/Namespace.d.ts +16 -0
  24. package/dist/macros/Queries.d.ts +10 -0
  25. package/dist/macros/StringView.d.ts +4 -0
  26. package/dist/macros/commands/Effect.d.ts +4 -0
  27. package/dist/macros/commands/Format.d.ts +4 -0
  28. package/dist/macros/commands/LocalePrint.d.ts +4 -0
  29. package/dist/macros/commands/PlayMusic.d.ts +4 -0
  30. package/dist/macros/commands/PlaySound.d.ts +4 -0
  31. package/dist/macros/commands/PrintChar.d.ts +4 -0
  32. package/dist/macros/commands/Query.d.ts +4 -0
  33. package/dist/macros/commands/SetProp.d.ts +4 -0
  34. package/dist/macros/commands/SpawnBullet.d.ts +4 -0
  35. package/dist/macros/commands/Sync.d.ts +6 -0
  36. package/dist/macros/commands/UnpackColor.d.ts +4 -0
  37. package/dist/macros/commands/WeatherSense.d.ts +4 -0
  38. package/dist/macros/commands/WeatherSet.d.ts +4 -0
  39. package/dist/macros/commands/index.d.ts +13 -0
  40. package/dist/macros/index.d.ts +7 -1
  41. package/dist/macros/util.d.ts +5 -2
  42. package/dist/modules.d.ts +8 -0
  43. package/dist/operators.d.ts +1 -1
  44. package/dist/types.d.ts +84 -59
  45. package/dist/utils/constants.d.ts +9 -4
  46. package/dist/utils/general.d.ts +8 -9
  47. package/dist/utils/instruction.d.ts +5 -1
  48. package/dist/utils/value.d.ts +14 -5
  49. package/dist/values/AssignmentValue.d.ts +1 -1
  50. package/dist/values/BaseValue.d.ts +4 -2
  51. package/dist/values/DestructuringValue.d.ts +5 -7
  52. package/dist/values/FunctionValue.d.ts +8 -6
  53. package/dist/values/JumpOutValue.d.ts +4 -4
  54. package/dist/values/LazyValue.d.ts +3 -3
  55. package/dist/values/LiteralValue.d.ts +2 -3
  56. package/dist/values/ObjectValue.d.ts +6 -11
  57. package/dist/values/StoreValue.d.ts +10 -5
  58. package/dist/values/VoidValue.d.ts +2 -1
  59. package/dist/values/index.d.ts +0 -1
  60. package/lib/commands.d.ts +776 -730
  61. package/lib/eslib/lib.es2015.collection.d.ts +50 -39
  62. package/lib/eslib/lib.es2015.core.d.ts +59 -0
  63. package/lib/eslib/lib.es2015.d.ts +0 -3
  64. package/lib/eslib/lib.es2015.generator.d.ts +54 -53
  65. package/lib/eslib/lib.es2015.iterable.d.ts +9 -6
  66. package/lib/eslib/lib.es5.d.ts +53 -6
  67. package/lib/globals.d.ts +309 -18
  68. package/lib/helpers.d.ts +86 -52
  69. package/lib/kinds.d.ts +42 -7
  70. package/lib/macros.d.ts +53 -18
  71. package/lib/traits.d.ts +308 -146
  72. package/lib/util.d.ts +144 -48
  73. package/lib/world.d.ts +1197 -0
  74. package/package.json +27 -35
  75. package/dist/bin.cjs +0 -111
  76. package/dist/initScope.d.ts +0 -5
  77. package/dist/instructions/ZeroSpaceInstruction.d.ts +0 -4
  78. package/dist/values/SenseableValue.d.ts +0 -24
  79. /package/dist/{bin.d.ts → bin/index.d.ts} +0 -0
package/package.json CHANGED
@@ -1,59 +1,51 @@
1
1
  {
2
2
  "name": "mlogjs",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
7
- "bin": "./dist/bin.cjs",
5
+ "main": "./dist/index.mjs",
6
+ "bin": "./dist/bin.mjs",
8
7
  "types": "./dist/index.d.ts",
9
8
  "scripts": {
10
9
  "clean": "rm -rf ../docs dist build",
11
10
  "build": "rollup -c",
12
11
  "build:dev": "rollup -c --environment DEV",
13
- "dev": "ts-node src/bin",
14
- "test": "jest",
15
- "lint": "eslint src/**/*.ts",
16
- "coverage": "jest --coverage",
17
- "start": "pnpm run build && pnpm i -g . && mlogjs",
12
+ "test": "vitest run",
18
13
  "prepublishOnly": "pnpm run build"
19
14
  },
20
15
  "repository": {
21
16
  "type": "git",
22
- "url": "git+https://github.com/weisrc/mlogjs.git"
17
+ "url": "git+https://github.com/mlogjs/mlogjs.git"
23
18
  },
24
- "keywords": [],
25
- "author": "str1z",
19
+ "keywords": [
20
+ "mindustry",
21
+ "mindustry-logic",
22
+ "mlog"
23
+ ],
26
24
  "license": "MIT",
27
25
  "bugs": {
28
- "url": "https://github.com/weisrc/mlogjs/issues"
26
+ "url": "https://github.com/mlogjs/mlogjs/issues"
29
27
  },
30
- "homepage": "https://github.com/weisrc/mlogjs#readme",
28
+ "homepage": "https://github.com/mlogjs/mlogjs#readme",
31
29
  "engines": {
32
- "node": ">=16"
30
+ "node": ">=22"
33
31
  },
32
+ "type": "module",
34
33
  "dependencies": {
35
- "@babel/parser": "^7.20.7",
36
- "@babel/types": "^7.20.7",
37
- "chalk": "^4.1.2",
34
+ "@babel/parser": "^8.0.8",
35
+ "@babel/types": "^8.0.8",
36
+ "chalk": "^6.0.1",
38
37
  "cli-highlight": "^2.1.11",
39
- "yargs": "^17.6.2"
38
+ "yargs": "^18.2.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@rollup/plugin-alias": "^4.0.2",
43
- "@rollup/plugin-typescript": "^11.0.0",
44
- "@types/jest": "^29.2.5",
45
- "@types/node": "^16.18.10",
46
- "@types/yargs": "^17.0.19",
47
- "@typescript-eslint/eslint-plugin": "^5.48.2",
48
- "@typescript-eslint/parser": "^5.48.2",
49
- "eslint": "^8.32.0",
50
- "jest": "^29.3.1",
51
- "npm-run-all": "^4.1.5",
52
- "rollup": "^3.10.0",
53
- "ts-jest": "^29.0.5",
54
- "ts-node": "^10.9.1",
55
- "tslib": "^2.4.1",
56
- "typescript": "*"
41
+ "@rollup/plugin-typescript": "^12.3.1",
42
+ "@types/jest": "^30.0.0",
43
+ "@types/node": "^22.20.5",
44
+ "@types/yargs": "^17.0.35",
45
+ "rollup": "^4.65.0",
46
+ "tslib": "^2.6.2",
47
+ "typescript": "^6.0.3",
48
+ "vitest": "^5.0.5"
57
49
  },
58
50
  "files": [
59
51
  "build",
@@ -62,4 +54,4 @@
62
54
  "LICENSE",
63
55
  "README.md"
64
56
  ]
65
- }
57
+ }
package/dist/bin.cjs DELETED
@@ -1,111 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var fs = require('fs');
5
- var helpers = require('yargs/helpers');
6
- var index_cjs = require('./index.cjs');
7
- var cliHighlight = require('cli-highlight');
8
- var yargs = require('yargs');
9
- var chalk = require('chalk');
10
- var path = require('path');
11
-
12
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
13
- yargs(helpers.hideBin(process.argv))
14
- .command("setup [dir]", "Copies the compiler type definitions in the current folder", yargs => {
15
- return yargs
16
- .positional("dir", {
17
- default: ".",
18
- type: "string",
19
- describe: "The directory where the type definitions folder will be copied",
20
- })
21
- .option("tsconfig", {
22
- type: "boolean",
23
- default: false,
24
- describe: "Wether a tsconfig.json file should be created in the current directory",
25
- });
26
- }, argv => {
27
- // this approach depends on the fact that the
28
- // output bin.cjs file is one folder bellow the package folder
29
- const currentPath = __dirname.replace(/\\/g, "/");
30
- const parent = currentPath.split("/").slice(0, -1).join("/");
31
- const libPath = path.join(parent, "lib");
32
- const dir = path.resolve(process.cwd(), argv.dir);
33
- const target = path.join(dir, "lib");
34
- fs.cpSync(libPath, target, {
35
- recursive: true,
36
- });
37
- if (!argv.tsconfig)
38
- return;
39
- const tsconfigPath = path.join(dir, "tsconfig.json");
40
- const json = {
41
- compilerOptions: {
42
- allowJs: true,
43
- checkJs: true,
44
- moduleDetection: "force",
45
- noEmit: true,
46
- noLib: true,
47
- target: "ESNext",
48
- },
49
- include: ["./lib", "*.js", "*.ts"],
50
- exclude: ["node_modules"],
51
- };
52
- fs.writeFileSync(tsconfigPath, JSON.stringify(json, null, "\t"));
53
- })
54
- .command("$0 [path] [out]", "compiles your Javascript file to MLog", yargs => {
55
- return yargs
56
- .positional("path", {
57
- describe: "path of the file to compile",
58
- type: "string",
59
- })
60
- .positional("out", {
61
- describe: "path of the output file",
62
- type: "string",
63
- })
64
- .option("compact-names", {
65
- type: "boolean",
66
- default: false,
67
- describe: "Wether the compiler should preserve or compact variable and function names",
68
- });
69
- }, argv => {
70
- const path$1 = argv.path;
71
- if (!path$1)
72
- return console.log("missing required path argument");
73
- if (!fs.existsSync(path$1))
74
- return console.log(`file at ${path$1} does not exist`);
75
- const out = argv.out ?? defaultOutPath(path$1);
76
- if (path$1 == out)
77
- return console.log("The out path cannot be the same as the input path");
78
- const compiler = new index_cjs.Compiler({
79
- compactNames: argv["compact-names"],
80
- });
81
- const code = fs.readFileSync(path$1, "utf8");
82
- const [output, error] = compiler.compile(code);
83
- if (error) {
84
- if (!error.loc) {
85
- console.log(error.inner ?? error);
86
- return;
87
- }
88
- const { start, end } = error.loc;
89
- const lines = code.split("\n");
90
- console.log(chalk.cyanBright([path.resolve(path$1), start.line, start.column].join(":")));
91
- for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
92
- const n = i + 1;
93
- if (n !== start.line)
94
- continue;
95
- const head = chalk.gray(`${n} | `.padStart(6, " "));
96
- console.log(head + cliHighlight.highlight(lines[i], { language: "js" }));
97
- console.log(chalk.red(" ".repeat(6 + start.column) + "^ " + error.message));
98
- }
99
- return;
100
- }
101
- fs.writeFileSync(out, output);
102
- console.log(`Success: Compiled ${path$1}. Your compiled code is at ${out}.`);
103
- })
104
- .help()
105
- .scriptName("mlogjs")
106
- .demandCommand()
107
- .parse();
108
- function defaultOutPath(path$1) {
109
- const parsed = path.parse(path$1);
110
- return path.join(parsed.dir, `${parsed.name}.mlog`);
111
- }
@@ -1,5 +0,0 @@
1
- import { Scope } from "./Scope";
2
- /**
3
- * Adds all the compiler globals to `scope`
4
- */
5
- export declare function initScope(scope: Scope): void;
@@ -1,4 +0,0 @@
1
- import { InstructionBase } from "./InstructionBase";
2
- export declare class ZeroSpaceInstruction extends InstructionBase {
3
- toString(): string;
4
- }
@@ -1,24 +0,0 @@
1
- import { EMutability, IScope, IValue, TEOutput, TValueInstructions } from "../types";
2
- import { StoreValue } from "./StoreValue";
3
- /**
4
- * Senseable values are "objects" in the mlog runtime that
5
- * have special properties that can be accessed
6
- * via the `sense` instruction.
7
- *
8
- * This class extends `StoreValue` to allow dynamic behavior
9
- * that is not possible with object macros.
10
- *
11
- * Note that these values are constant by default, so make sure
12
- * to set that field to `EMutability.mutable` if you want them to be assignable. Example:
13
- * ```
14
- * const value = new SenseableValue(name, EMutability.mutable);
15
- * ```
16
- */
17
- export declare class SenseableValue extends StoreValue {
18
- constructor(name: string, mutability?: EMutability);
19
- static from(scope: IScope, out?: TEOutput, mutability?: EMutability): SenseableValue;
20
- static out(scope: IScope, out?: TEOutput, mutability?: EMutability): IValue;
21
- get(scope: IScope, prop: IValue, out?: TEOutput): TValueInstructions<IValue>;
22
- debugString(): string;
23
- hasProperty(scope: IScope, prop: IValue): boolean;
24
- }
File without changes