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.
- package/README.md +2 -2
- package/dist/{index.cjs → Compiler-7GMG4MDr.js} +1746 -452
- package/dist/Compiler.d.ts +8 -12
- package/dist/CompilerError.d.ts +13 -3
- package/dist/Scope.d.ts +8 -8
- package/dist/bin/files.d.ts +18 -0
- package/dist/bin.mjs +170 -0
- package/dist/handlers/Import.d.ts +5 -0
- package/dist/handlers/Literal.d.ts +2 -2
- package/dist/handlers/Typescript.d.ts +2 -2
- package/dist/handlers/index.d.ts +1 -0
- package/dist/index.mjs +3 -4267
- package/dist/instructions/AddressResolver.d.ts +4 -4
- package/dist/instructions/ControlInstructions.d.ts +3 -3
- package/dist/instructions/InstructionBase.d.ts +1 -0
- package/dist/instructions/JumpInstruction.d.ts +5 -5
- package/dist/instructions/index.d.ts +0 -1
- package/dist/macros/DynamicArray.d.ts +4 -4
- package/dist/macros/Function.d.ts +2 -2
- package/dist/macros/GetBuildings.d.ts +4 -0
- package/dist/macros/GetColor.d.ts +4 -0
- package/dist/macros/Marker.d.ts +4 -0
- package/dist/macros/Namespace.d.ts +16 -0
- package/dist/macros/Queries.d.ts +10 -0
- package/dist/macros/StringView.d.ts +4 -0
- package/dist/macros/commands/Effect.d.ts +4 -0
- package/dist/macros/commands/Format.d.ts +4 -0
- package/dist/macros/commands/LocalePrint.d.ts +4 -0
- package/dist/macros/commands/PlayMusic.d.ts +4 -0
- package/dist/macros/commands/PlaySound.d.ts +4 -0
- package/dist/macros/commands/PrintChar.d.ts +4 -0
- package/dist/macros/commands/Query.d.ts +4 -0
- package/dist/macros/commands/SetProp.d.ts +4 -0
- package/dist/macros/commands/SpawnBullet.d.ts +4 -0
- package/dist/macros/commands/Sync.d.ts +6 -0
- package/dist/macros/commands/UnpackColor.d.ts +4 -0
- package/dist/macros/commands/WeatherSense.d.ts +4 -0
- package/dist/macros/commands/WeatherSet.d.ts +4 -0
- package/dist/macros/commands/index.d.ts +13 -0
- package/dist/macros/index.d.ts +7 -1
- package/dist/macros/util.d.ts +5 -2
- package/dist/modules.d.ts +8 -0
- package/dist/operators.d.ts +1 -1
- package/dist/types.d.ts +84 -59
- package/dist/utils/constants.d.ts +9 -4
- package/dist/utils/general.d.ts +8 -9
- package/dist/utils/instruction.d.ts +5 -1
- package/dist/utils/value.d.ts +14 -5
- package/dist/values/AssignmentValue.d.ts +1 -1
- package/dist/values/BaseValue.d.ts +4 -2
- package/dist/values/DestructuringValue.d.ts +5 -7
- package/dist/values/FunctionValue.d.ts +8 -6
- package/dist/values/JumpOutValue.d.ts +4 -4
- package/dist/values/LazyValue.d.ts +3 -3
- package/dist/values/LiteralValue.d.ts +2 -3
- package/dist/values/ObjectValue.d.ts +6 -11
- package/dist/values/StoreValue.d.ts +10 -5
- package/dist/values/VoidValue.d.ts +2 -1
- package/dist/values/index.d.ts +0 -1
- package/lib/commands.d.ts +776 -730
- package/lib/eslib/lib.es2015.collection.d.ts +50 -39
- package/lib/eslib/lib.es2015.core.d.ts +59 -0
- package/lib/eslib/lib.es2015.d.ts +0 -3
- package/lib/eslib/lib.es2015.generator.d.ts +54 -53
- package/lib/eslib/lib.es2015.iterable.d.ts +9 -6
- package/lib/eslib/lib.es5.d.ts +53 -6
- package/lib/globals.d.ts +309 -18
- package/lib/helpers.d.ts +86 -52
- package/lib/kinds.d.ts +42 -7
- package/lib/macros.d.ts +53 -18
- package/lib/traits.d.ts +308 -146
- package/lib/util.d.ts +144 -48
- package/lib/world.d.ts +1197 -0
- package/package.json +27 -35
- package/dist/bin.cjs +0 -111
- package/dist/initScope.d.ts +0 -5
- package/dist/instructions/ZeroSpaceInstruction.d.ts +0 -4
- package/dist/values/SenseableValue.d.ts +0 -24
- /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.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Compiler that compiles Javascript to Mindustry Logic Code.",
|
|
5
|
-
"main": "./dist/index.
|
|
6
|
-
"
|
|
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
|
-
"
|
|
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/
|
|
17
|
+
"url": "git+https://github.com/mlogjs/mlogjs.git"
|
|
23
18
|
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mindustry",
|
|
21
|
+
"mindustry-logic",
|
|
22
|
+
"mlog"
|
|
23
|
+
],
|
|
26
24
|
"license": "MIT",
|
|
27
25
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
26
|
+
"url": "https://github.com/mlogjs/mlogjs/issues"
|
|
29
27
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
28
|
+
"homepage": "https://github.com/mlogjs/mlogjs#readme",
|
|
31
29
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
30
|
+
"node": ">=22"
|
|
33
31
|
},
|
|
32
|
+
"type": "module",
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"@babel/parser": "^
|
|
36
|
-
"@babel/types": "^
|
|
37
|
-
"chalk": "^
|
|
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": "^
|
|
38
|
+
"yargs": "^18.2.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@rollup/plugin-
|
|
43
|
-
"@
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
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
|
-
}
|
package/dist/initScope.d.ts
DELETED
|
@@ -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
|