mlogjs 0.4.9 → 0.5.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 (114) hide show
  1. package/README.md +15 -11
  2. package/dist/Compiler.d.ts +38 -38
  3. package/dist/CompilerError.d.ts +33 -33
  4. package/dist/Scope.d.ts +31 -25
  5. package/dist/bin.cjs +99 -58
  6. package/dist/bin.d.ts +1 -1
  7. package/dist/handlers/BlockStatement.d.ts +2 -2
  8. package/dist/handlers/CallExpression.d.ts +4 -4
  9. package/dist/handlers/File.d.ts +2 -2
  10. package/dist/handlers/ForStatement.d.ts +2 -2
  11. package/dist/handlers/Function.d.ts +5 -5
  12. package/dist/handlers/Identifier.d.ts +2 -2
  13. package/dist/handlers/IfStatement.d.ts +2 -2
  14. package/dist/handlers/Literal.d.ts +5 -5
  15. package/dist/handlers/Object.d.ts +8 -7
  16. package/dist/handlers/OperationExpressions.d.ts +9 -9
  17. package/dist/handlers/Program.d.ts +2 -2
  18. package/dist/handlers/Statements.d.ts +7 -7
  19. package/dist/handlers/SwitchStatement.d.ts +2 -2
  20. package/dist/handlers/TemplateExpression.d.ts +2 -2
  21. package/dist/handlers/Typescript.d.ts +8 -7
  22. package/dist/handlers/VariableDeclaration.d.ts +3 -3
  23. package/dist/handlers/WhileStatement.d.ts +3 -3
  24. package/dist/handlers/index.d.ts +17 -17
  25. package/dist/index.cjs +4170 -3164
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.mjs +4164 -3158
  28. package/dist/initScope.d.ts +5 -5
  29. package/dist/instructions/AddressResolver.d.ts +12 -12
  30. package/dist/instructions/ControlInstructions.d.ts +10 -10
  31. package/dist/instructions/EndInstruction.d.ts +6 -4
  32. package/dist/instructions/InstructionBase.d.ts +15 -15
  33. package/dist/instructions/JumpInstruction.d.ts +22 -16
  34. package/dist/instructions/OperationInstruction.d.ts +5 -5
  35. package/dist/instructions/SetCounterInstruction.d.ts +5 -5
  36. package/dist/instructions/SetInstruction.d.ts +8 -8
  37. package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -4
  38. package/dist/instructions/index.d.ts +9 -9
  39. package/dist/macros/Asm.d.ts +4 -4
  40. package/dist/macros/DynamicArray.d.ts +30 -23
  41. package/dist/macros/Function.d.ts +14 -12
  42. package/dist/macros/GetGlobal.d.ts +5 -5
  43. package/dist/macros/Math.d.ts +4 -4
  44. package/dist/macros/Memory.d.ts +4 -4
  45. package/dist/macros/Namespace.d.ts +15 -12
  46. package/dist/macros/Other.d.ts +4 -4
  47. package/dist/macros/Unchecked.d.ts +7 -0
  48. package/dist/macros/commands/ApplyStatus.d.ts +4 -4
  49. package/dist/macros/commands/Control.d.ts +4 -4
  50. package/dist/macros/commands/Cutscene.d.ts +4 -4
  51. package/dist/macros/commands/Draw.d.ts +4 -4
  52. package/dist/macros/commands/DrawFlush.d.ts +4 -4
  53. package/dist/macros/commands/End.d.ts +4 -4
  54. package/dist/macros/commands/Explosion.d.ts +4 -4
  55. package/dist/macros/commands/Fetch.d.ts +4 -4
  56. package/dist/macros/commands/FlushMessage.d.ts +4 -4
  57. package/dist/macros/commands/GetBlock.d.ts +4 -4
  58. package/dist/macros/commands/GetFlag.d.ts +4 -4
  59. package/dist/macros/commands/GetLink.d.ts +4 -4
  60. package/dist/macros/commands/Lookup.d.ts +4 -4
  61. package/dist/macros/commands/PackColor.d.ts +4 -4
  62. package/dist/macros/commands/Print.d.ts +4 -4
  63. package/dist/macros/commands/PrintFlush.d.ts +4 -4
  64. package/dist/macros/commands/Radar.d.ts +6 -6
  65. package/dist/macros/commands/Sensor.d.ts +4 -4
  66. package/dist/macros/commands/SetBlock.d.ts +4 -4
  67. package/dist/macros/commands/SetFlag.d.ts +4 -4
  68. package/dist/macros/commands/SetRate.d.ts +4 -4
  69. package/dist/macros/commands/SetRule.d.ts +4 -4
  70. package/dist/macros/commands/SpawnUnit.d.ts +4 -4
  71. package/dist/macros/commands/SpawnWave.d.ts +4 -4
  72. package/dist/macros/commands/Stop.d.ts +4 -4
  73. package/dist/macros/commands/UnitBind.d.ts +4 -4
  74. package/dist/macros/commands/UnitControl.d.ts +4 -4
  75. package/dist/macros/commands/UnitLocate.d.ts +4 -4
  76. package/dist/macros/commands/UnitRadar.d.ts +4 -4
  77. package/dist/macros/commands/Wait.d.ts +4 -4
  78. package/dist/macros/commands/index.d.ts +30 -30
  79. package/dist/macros/index.d.ts +8 -6
  80. package/dist/macros/util.d.ts +17 -17
  81. package/dist/operators.d.ts +46 -25
  82. package/dist/types.d.ts +259 -220
  83. package/dist/utils/constants.d.ts +8 -6
  84. package/dist/utils/general.d.ts +26 -26
  85. package/dist/utils/index.d.ts +4 -4
  86. package/dist/utils/instruction.d.ts +9 -5
  87. package/dist/utils/value.d.ts +40 -36
  88. package/dist/values/AssignmentValue.d.ts +10 -0
  89. package/dist/values/BaseValue.d.ts +10 -10
  90. package/dist/values/DestructuringValue.d.ts +32 -30
  91. package/dist/values/FunctionValue.d.ts +57 -50
  92. package/dist/values/JumpOutValue.d.ts +36 -0
  93. package/dist/values/LazyValue.d.ts +11 -9
  94. package/dist/values/LiteralValue.d.ts +18 -14
  95. package/dist/values/ObjectValue.d.ts +23 -20
  96. package/dist/values/SenseableValue.d.ts +24 -24
  97. package/dist/values/StoreValue.d.ts +22 -21
  98. package/dist/values/VoidValue.d.ts +16 -13
  99. package/dist/values/index.d.ts +9 -8
  100. package/lib/commands.d.ts +59 -32
  101. package/lib/eslib/lib.es5.d.ts +36 -0
  102. package/lib/globals.d.ts +5 -5
  103. package/lib/helpers.d.ts +18 -2
  104. package/lib/index.d.ts +1 -1
  105. package/lib/macros.d.ts +150 -0
  106. package/lib/traits.d.ts +5 -5
  107. package/package.json +31 -27
  108. package/dist/assertions.d.ts +0 -28
  109. package/dist/bin.cjs.map +0 -1
  110. package/dist/discardedName.d.ts +0 -5
  111. package/dist/index.cjs.map +0 -1
  112. package/dist/index.mjs.map +0 -1
  113. package/dist/utils.d.ts +0 -45
  114. package/lib/memory.d.ts +0 -17
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  <div markdown="1" align="center">
2
2
 
3
- [![mlogjs](https://mlogjs.github.io/mlogjs/logo.png)][docs]
3
+ [![mlogjs](https://mlogjs.netlify.app/logo.png)][docs]
4
4
 
5
5
  # **JavaScript [MLog](https://mindustrygame.github.io/wiki/logic/0-introduction/) Compiler**
6
6
 
7
7
  [![ci](https://github.com/weisrc/mlogjs/actions/workflows/ci.yml/badge.svg)][ci]
8
8
  [![npm](https://img.shields.io/npm/v/mlogjs?color=cb3837&logo=npm)][npm]
9
- [![docs](https://img.shields.io/badge/docs-mlogjs-41B883?logo=readthedocs)][docs]
9
+ [![docs](https://img.shields.io/badge/docs-stable-41B883?logo=readthedocs)][docs]
10
+ [![unreleased docs](https://img.shields.io/badge/docs-unreleased-41B883?logo=readthedocs)][unreleased docs]
11
+ [![chat](https://img.shields.io/badge/chat-discord-blue?logo=discord)][discord]
10
12
 
11
13
  </div>
12
14
 
@@ -17,7 +19,7 @@
17
19
  - Fully Typed API
18
20
  - Macros
19
21
  - All Instructions and Variables
20
- - An [online editor]
22
+ - An online editor integrated to the docs
21
23
 
22
24
  ## Installation
23
25
 
@@ -42,16 +44,17 @@ printFlush();
42
44
  mlogjs hello.js
43
45
  ```
44
46
 
45
- ## Resources
47
+ ## Examples
46
48
 
47
- - [Discord](https://discord.gg/SvgjCtZnR5)
48
- - [Documentation][docs]
49
- - [NPM package][npm]
50
- - [GitHub Action CI][ci]
49
+ You can find other usage examples [here](https://github.com/mlogjs/mlogjs/tree/main/compiler/test/examples).
50
+
51
+ ## Changelog
52
+
53
+ Changes for each release are documented in the [CHANGELOG](https://github.com/mlogjs/mlogjs/blob/main/compiler/CHANGELOG.md).
51
54
 
52
55
  ## Contribute
53
56
 
54
- Having trouble? [Ask for help on discord](https://discord.gg/DxXkqsWx)
57
+ Having trouble? [Ask for help on discord](https://discord.gg/2VudfNUp)
55
58
  or [open an issue](https://github.com/mlogjs/mlogjs/issues/new)
56
59
 
57
60
  Help and suggestions are welcomed!
@@ -64,5 +67,6 @@ MIT
64
67
 
65
68
  [npm]: https://www.npmjs.com/package/mlogjs
66
69
  [ci]: https://github.com/mlogjs/mlogjs/actions/workflows/ci.yml
67
- [docs]: https://mlogjs.github.io/mlogjs
68
- [online editor]: https://mlogjs.github.io/mlogjs/editor.html
70
+ [docs]: https://mlogjs.github.io/mlogjs/
71
+ [unreleased docs]: https://mlogjs.netlify.app
72
+ [discord]: https://discord.gg/SvgjCtZnR5
@@ -1,38 +1,38 @@
1
- import { CompilerError } from "./CompilerError";
2
- import { es, IScope, IValue, TEOutput, THandler, TValueInstructions } from "./types";
3
- declare type THandlerMap = {
4
- [k in es.Node["type"]]?: THandler<IValue | null>;
5
- };
6
- export interface CompilerOptions {
7
- stackName?: string;
8
- /** Wether the compiler should preserve or compact variable and function names*/
9
- compactNames?: boolean;
10
- sourcemap?: boolean;
11
- }
12
- export declare class Compiler {
13
- protected stackName?: string;
14
- protected usingStack: boolean;
15
- protected handlers: THandlerMap;
16
- readonly compactNames: boolean;
17
- readonly sourcemap: boolean;
18
- constructor({ stackName, compactNames, sourcemap, }?: CompilerOptions);
19
- compile(script: string): [string, null, es.SourceLocation[] | undefined] | [null, CompilerError];
20
- protected resolve(valueInst: TValueInstructions<IValue | null>): void;
21
- protected serialize(resLines: TValueInstructions<IValue | null>): string;
22
- protected parse(script: string): import("@babel/parser").ParseResult<es.File>;
23
- protected mapSources(valueInst: TValueInstructions<IValue | null>): es.SourceLocation[];
24
- handle(scope: IScope, node: es.Node, handler?: THandler<IValue | null> | undefined, out?: TEOutput): TValueInstructions<IValue | null>;
25
- handleEval(scope: IScope, node: es.Node, out?: TEOutput): TValueInstructions;
26
- /**
27
- * Handles many nodes in order.
28
- *
29
- * The usage of this method over a regular loop over an array of nodes
30
- * is only required if the code inside the loop generates
31
- * instructions that are not tracked by the compiler
32
- * handler methods ({@link handle}, {@link handleEval}
33
- * and {@link handleMany})
34
- *
35
- */
36
- handleMany<T extends es.Node>(scope: IScope, nodes: T[], handler?: (node: T) => TValueInstructions<IValue | null>): TValueInstructions<null>;
37
- }
38
- export {};
1
+ import { CompilerError } from "./CompilerError";
2
+ import { es, IScope, IValue, TEOutput, THandler, TValueInstructions } from "./types";
3
+ type THandlerMap = {
4
+ [k in es.Node["type"]]?: THandler<IValue | null>;
5
+ };
6
+ export interface CompilerOptions {
7
+ stackName?: string;
8
+ /** Wether the compiler should preserve or compact variable and function names*/
9
+ compactNames?: boolean;
10
+ sourcemap?: boolean;
11
+ }
12
+ export declare class Compiler {
13
+ protected stackName?: string;
14
+ protected usingStack: boolean;
15
+ protected handlers: THandlerMap;
16
+ readonly compactNames: boolean;
17
+ readonly sourcemap: boolean;
18
+ constructor({ stackName, compactNames, sourcemap, }?: CompilerOptions);
19
+ compile(script: string): [string, null, es.SourceLocation[] | undefined] | [null, CompilerError];
20
+ protected resolve(valueInst: TValueInstructions<IValue | null>): void;
21
+ protected serialize(resLines: TValueInstructions<IValue | null>): string;
22
+ protected parse(script: string): import("@babel/parser").ParseResult<es.File>;
23
+ protected mapSources(valueInst: TValueInstructions<IValue | null>): es.SourceLocation[];
24
+ handle(scope: IScope, node: es.Node, handler?: THandler<IValue | null> | undefined, out?: TEOutput): TValueInstructions<IValue | null>;
25
+ handleEval(scope: IScope, node: es.Node, out?: TEOutput): TValueInstructions;
26
+ /**
27
+ * Handles many nodes in order.
28
+ *
29
+ * The usage of this method over a regular loop over an array of nodes
30
+ * is only required if the code inside the loop generates
31
+ * instructions that are not tracked by the compiler
32
+ * handler methods ({@link handle}, {@link handleEval}
33
+ * and {@link handleMany})
34
+ *
35
+ */
36
+ handleMany<T extends es.Node>(scope: IScope, nodes: T[], handler?: (node: T) => TValueInstructions<IValue | null>): TValueInstructions<null>;
37
+ }
38
+ export {};
@@ -1,33 +1,33 @@
1
- import { es } from "./types";
2
- /**
3
- * Error thrown by the babel parser.
4
- *
5
- * It doesn't export the type so we are writing it ourselves
6
- */
7
- export interface ParsingError extends Error {
8
- code: string;
9
- reasonCode: string;
10
- loc: {
11
- line: number;
12
- column: number;
13
- };
14
- }
15
- declare type CompilerErrorSource = es.Node | es.SourceLocation | {
16
- line: number;
17
- column: number;
18
- };
19
- export declare class CompilerError extends Error {
20
- protected _loc?: es.SourceLocation;
21
- /**
22
- * The error that preceded this `CompilerError`.
23
- *
24
- * If it's not `undefined` it means that `this` is just wrapping the error to
25
- * append extra data like the node stack
26
- * */
27
- inner?: unknown;
28
- constructor(message: string, source?: CompilerErrorSource);
29
- get loc(): es.SourceLocation | undefined;
30
- set loc(value: CompilerErrorSource | undefined);
31
- static from(error: unknown, source?: CompilerErrorSource): CompilerError;
32
- }
33
- export {};
1
+ import { es } from "./types";
2
+ /**
3
+ * Error thrown by the babel parser.
4
+ *
5
+ * It doesn't export the type so we are writing it ourselves
6
+ */
7
+ export interface ParsingError extends Error {
8
+ code: string;
9
+ reasonCode: string;
10
+ loc: {
11
+ line: number;
12
+ column: number;
13
+ };
14
+ }
15
+ type CompilerErrorSource = es.Node | es.SourceLocation | {
16
+ line: number;
17
+ column: number;
18
+ };
19
+ export declare class CompilerError extends Error {
20
+ protected _loc?: es.SourceLocation;
21
+ /**
22
+ * The error that preceded this `CompilerError`.
23
+ *
24
+ * If it's not `undefined` it means that `this` is just wrapping the error to
25
+ * append extra data like the node stack
26
+ * */
27
+ inner?: unknown;
28
+ constructor(message: string, source?: CompilerErrorSource);
29
+ get loc(): es.SourceLocation | undefined;
30
+ set loc(value: CompilerErrorSource | undefined);
31
+ static from(error: unknown, source?: CompilerErrorSource): CompilerError;
32
+ }
33
+ export {};
package/dist/Scope.d.ts CHANGED
@@ -1,25 +1,31 @@
1
- import { SenseableValue } from "./values";
2
- import { AddressResolver } from "./instructions";
3
- import { IFunctionValue, IInstruction, INamedValue, IScope, IValue } from "./types";
4
- export declare class Scope implements IScope {
5
- parent: IScope | null;
6
- stacked: boolean;
7
- ntemp: number;
8
- name: string;
9
- inst: IInstruction[];
10
- data: Record<string, IValue | null>;
11
- break: AddressResolver;
12
- continue: AddressResolver;
13
- function: IFunctionValue;
14
- label?: string;
15
- constructor(values: Record<string, IValue | null>, parent?: IScope | null, stacked?: boolean, ntemp?: number, name?: string, inst?: IInstruction[]);
16
- copy(): IScope;
17
- createScope(): IScope;
18
- createFunction(name: string, stacked?: boolean): IScope;
19
- has(identifier: string): boolean;
20
- get(identifier: string): INamedValue;
21
- set<T extends IValue>(name: string, value: T): T;
22
- hardSet<T extends IValue>(name: string, value: T): T;
23
- make(identifier: string, name: string): SenseableValue;
24
- makeTempName(): string;
25
- }
1
+ import { SenseableValue } from "./values";
2
+ import { AddressResolver } from "./instructions";
3
+ import { IFunctionValue, IInstruction, INamedValue, IScope, IValue } from "./types";
4
+ export declare class Scope implements IScope {
5
+ parent: IScope | null;
6
+ stacked: boolean;
7
+ ntemp: number;
8
+ name: string;
9
+ inst: IInstruction[];
10
+ operationCache: Record<string, IValue>;
11
+ cacheDependencies: Record<string, string[]>;
12
+ data: Record<string, IValue | null>;
13
+ break: AddressResolver;
14
+ continue: AddressResolver;
15
+ function: IFunctionValue;
16
+ label?: string;
17
+ checkIndexes: boolean;
18
+ constructor(values: Record<string, IValue | null>, parent?: IScope | null, stacked?: boolean, ntemp?: number, name?: string, inst?: IInstruction[], operationCache?: Record<string, IValue>, cacheDependencies?: Record<string, string[]>);
19
+ copy(): IScope;
20
+ createScope(): IScope;
21
+ createFunction(name: string, stacked?: boolean): IScope;
22
+ has(identifier: string): boolean;
23
+ get(identifier: string): INamedValue;
24
+ set<T extends IValue>(name: string, value: T): T;
25
+ hardSet<T extends IValue>(name: string, value: T): T;
26
+ make(identifier: string, name: string): SenseableValue;
27
+ makeTempName(): string;
28
+ addCachedOperation(op: string, result: IValue, left: IValue, right?: IValue | undefined): void;
29
+ getCachedOperation(op: string, left: IValue, right?: IValue | undefined): IValue | undefined;
30
+ clearDependentCache(value: IValue): void;
31
+ }
package/dist/bin.cjs CHANGED
@@ -9,62 +9,103 @@ var yargs = require('yargs');
9
9
  var chalk = require('chalk');
10
10
  var path = require('path');
11
11
 
12
- yargs(helpers.hideBin(process.argv))
13
- .command("$0 [path] [out]", "compiles your Javascript file to MLog", yargs => {
14
- return yargs
15
- .positional("path", {
16
- describe: "path of the file to compile",
17
- type: "string",
18
- })
19
- .positional("out", {
20
- describe: "path of the output file",
21
- type: "string",
22
- })
23
- .option("compact-names", {
24
- type: "boolean",
25
- default: false,
26
- describe: "Wether the compiler should preserve or compact variable and function names",
27
- });
28
- }, argv => {
29
- const path$1 = argv.path;
30
- if (!path$1)
31
- return console.log("missing required path argument");
32
- if (!fs.existsSync(path$1))
33
- return console.log(`file at ${path$1} does not exist`);
34
- const out = argv.out ?? defaultOutPath(path$1);
35
- if (path$1 == out)
36
- return console.log("The out path cannot be the same as the input path");
37
- const compiler = new index_cjs.Compiler({
38
- compactNames: argv["compact-names"],
39
- });
40
- const code = fs.readFileSync(path$1, "utf8");
41
- const [output, error] = compiler.compile(code);
42
- if (error) {
43
- if (!error.loc) {
44
- console.log(error.inner ?? error);
45
- return;
46
- }
47
- const { start, end } = error.loc;
48
- const lines = code.split("\n");
49
- console.log(chalk.cyanBright([path.resolve(path$1), start.line, start.column].join(":")));
50
- for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
51
- const n = i + 1;
52
- if (n !== start.line)
53
- continue;
54
- const head = chalk.gray(`${n} | `.padStart(6, " "));
55
- console.log(head + cliHighlight.highlight(lines[i], { language: "js" }));
56
- console.log(chalk.red(" ".repeat(6 + start.column) + "^ " + error.message));
57
- }
58
- return;
59
- }
60
- fs.writeFileSync(out, output);
61
- console.log(`Success: Compiled ${path$1}. Your compiled code is at ${out}.`);
62
- })
63
- .help()
64
- .scriptName("mlogjs")
65
- .demandCommand()
66
- .parse();
67
- function defaultOutPath(path$1) {
68
- const parsed = path.parse(path$1);
69
- return path.join(parsed.dir, `${parsed.name}.mlog`);
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`);
70
111
  }
package/dist/bin.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,2 +1,2 @@
1
- import { IValue, THandler } from "../types";
2
- export declare const BlockStatement: THandler<IValue | null>;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const BlockStatement: THandler<IValue | null>;
@@ -1,4 +1,4 @@
1
- import { IValue, THandler } from "../types";
2
- export declare const CallExpression: THandler<IValue | null>;
3
- export declare const NewExpression: THandler<IValue | null>;
4
- export declare const TaggedTemplateExpression: THandler<IValue | null>;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const CallExpression: THandler<IValue | null>;
3
+ export declare const NewExpression: THandler<IValue | null>;
4
+ export declare const TaggedTemplateExpression: THandler<IValue | null>;
@@ -1,2 +1,2 @@
1
- import { IValue, THandler } from "../types";
2
- export declare const File: THandler<IValue | null>;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const File: THandler<IValue | null>;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const ForStatement: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const ForStatement: THandler<null>;
@@ -1,5 +1,5 @@
1
- import { THandler } from "../types";
2
- export declare const ArrowFunctionExpression: THandler;
3
- export declare const FunctionDeclaration: THandler;
4
- export declare const FunctionExpression: THandler;
5
- export declare const ObjectMethod: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const ArrowFunctionExpression: THandler;
3
+ export declare const FunctionDeclaration: THandler;
4
+ export declare const FunctionExpression: THandler;
5
+ export declare const ObjectMethod: THandler;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const Identifier: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const Identifier: THandler;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const IfStatement: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const IfStatement: THandler<null>;
@@ -1,5 +1,5 @@
1
- import { THandler } from "../types";
2
- export declare const NumericLiteral: THandler<import("../types").IValue>;
3
- export declare const StringLiteral: THandler<import("../types").IValue>;
4
- export declare const NullLiteral: THandler;
5
- export declare const BooleanLiteral: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const NumericLiteral: THandler<import("../types").IValue>;
3
+ export declare const StringLiteral: THandler<import("../types").IValue>;
4
+ export declare const NullLiteral: THandler;
5
+ export declare const BooleanLiteral: THandler;
@@ -1,7 +1,8 @@
1
- import { IValue, THandler } from "../types";
2
- export declare const ObjectExpression: THandler;
3
- export declare const ArrayExpression: THandler;
4
- export declare const MemberExpression: THandler;
5
- export declare const ArrayPattern: THandler;
6
- export declare const ObjectPattern: THandler;
7
- export declare const OptionalMemberExpression: THandler<IValue>;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const ObjectExpression: THandler;
3
+ export declare const ArrayExpression: THandler;
4
+ export declare const MemberExpression: THandler;
5
+ export declare const ArrayPattern: THandler;
6
+ export declare const ObjectPattern: THandler;
7
+ export declare const OptionalMemberExpression: THandler;
8
+ export declare const AssignmentPattern: THandler<IValue>;
@@ -1,9 +1,9 @@
1
- import { THandler } from "../types";
2
- export declare const LRExpression: THandler;
3
- export declare const BinaryExpression: THandler;
4
- export declare const LogicalExpression: THandler;
5
- export declare const AssignmentExpression: THandler;
6
- export declare const UnaryExpression: THandler;
7
- export declare const UpdateExpression: THandler;
8
- export declare const ConditionalExpression: THandler;
9
- export declare const SequenceExpression: THandler;
1
+ import { THandler } from "../types";
2
+ export declare const LRExpression: THandler;
3
+ export declare const BinaryExpression: THandler;
4
+ export declare const LogicalExpression: THandler;
5
+ export declare const AssignmentExpression: THandler;
6
+ export declare const UnaryExpression: THandler;
7
+ export declare const UpdateExpression: THandler;
8
+ export declare const ConditionalExpression: THandler;
9
+ export declare const SequenceExpression: THandler;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const Program: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const Program: THandler<null>;
@@ -1,7 +1,7 @@
1
- import { IValue, THandler } from "../types";
2
- export declare const ExpressionStatement: THandler<IValue | null>;
3
- export declare const BreakStatement: THandler<null>;
4
- export declare const ContinueStatement: THandler<null>;
5
- export declare const ReturnStatement: THandler<IValue | null>;
6
- export declare const EmptyStatement: THandler<null>;
7
- export declare const LabeledStatement: THandler<null>;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const ExpressionStatement: THandler<IValue | null>;
3
+ export declare const BreakStatement: THandler<null>;
4
+ export declare const ContinueStatement: THandler<null>;
5
+ export declare const ReturnStatement: THandler<IValue | null>;
6
+ export declare const EmptyStatement: THandler<null>;
7
+ export declare const LabeledStatement: THandler<null>;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const SwitchStatement: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const SwitchStatement: THandler<null>;
@@ -1,2 +1,2 @@
1
- import { THandler } from "../types";
2
- export declare const TemplateLiteral: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const TemplateLiteral: THandler<null>;
@@ -1,7 +1,8 @@
1
- import { THandler } from "../types";
2
- export declare const TSAsExpression: THandler<import("../types").IValue>;
3
- export declare const TSTypeAssertion: THandler<import("../types").IValue>;
4
- export declare const TSInterfaceDeclaration: THandler<null>;
5
- export declare const TSTypeAliasDeclaration: THandler<null>;
6
- export declare const TSEnumDeclaration: THandler<null>;
7
- export declare const TSNonNullExpression: THandler;
1
+ import { IValue, THandler } from "../types";
2
+ export declare const TSAsExpression: THandler<IValue>;
3
+ export declare const TSTypeAssertion: THandler<IValue>;
4
+ export declare const TSInterfaceDeclaration: THandler<null>;
5
+ export declare const TSTypeAliasDeclaration: THandler<null>;
6
+ export declare const TSEnumDeclaration: THandler<null>;
7
+ export declare const TSNonNullExpression: THandler;
8
+ export declare const TSSatisfiesExpression: THandler<IValue | null>;
@@ -1,3 +1,3 @@
1
- import { THandler } from "../types";
2
- export declare const VariableDeclaration: THandler<null>;
3
- export declare const VariableDeclarator: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const VariableDeclaration: THandler<null>;
3
+ export declare const VariableDeclarator: THandler<null>;
@@ -1,3 +1,3 @@
1
- import { THandler } from "../types";
2
- export declare const WhileStatement: THandler<null>;
3
- export declare const DoWhileStatement: THandler<null>;
1
+ import { THandler } from "../types";
2
+ export declare const WhileStatement: THandler<null>;
3
+ export declare const DoWhileStatement: THandler<null>;
@@ -1,17 +1,17 @@
1
- export * from "./Program";
2
- export * from "./VariableDeclaration";
3
- export * from "./Literal";
4
- export * from "./OperationExpressions";
5
- export * from "./Identifier";
6
- export * from "./Statements";
7
- export * from "./IfStatement";
8
- export * from "./SwitchStatement";
9
- export * from "./WhileStatement";
10
- export * from "./ForStatement";
11
- export * from "./Function";
12
- export * from "./CallExpression";
13
- export * from "./Object";
14
- export * from "./TemplateExpression";
15
- export * from "./BlockStatement";
16
- export * from "./File";
17
- export * from "./Typescript";
1
+ export * from "./Program";
2
+ export * from "./VariableDeclaration";
3
+ export * from "./Literal";
4
+ export * from "./OperationExpressions";
5
+ export * from "./Identifier";
6
+ export * from "./Statements";
7
+ export * from "./IfStatement";
8
+ export * from "./SwitchStatement";
9
+ export * from "./WhileStatement";
10
+ export * from "./ForStatement";
11
+ export * from "./Function";
12
+ export * from "./CallExpression";
13
+ export * from "./Object";
14
+ export * from "./TemplateExpression";
15
+ export * from "./BlockStatement";
16
+ export * from "./File";
17
+ export * from "./Typescript";