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.
- package/README.md +15 -11
- package/dist/Compiler.d.ts +38 -38
- package/dist/CompilerError.d.ts +33 -33
- package/dist/Scope.d.ts +31 -25
- package/dist/bin.cjs +99 -58
- package/dist/bin.d.ts +1 -1
- package/dist/handlers/BlockStatement.d.ts +2 -2
- package/dist/handlers/CallExpression.d.ts +4 -4
- package/dist/handlers/File.d.ts +2 -2
- package/dist/handlers/ForStatement.d.ts +2 -2
- package/dist/handlers/Function.d.ts +5 -5
- package/dist/handlers/Identifier.d.ts +2 -2
- package/dist/handlers/IfStatement.d.ts +2 -2
- package/dist/handlers/Literal.d.ts +5 -5
- package/dist/handlers/Object.d.ts +8 -7
- package/dist/handlers/OperationExpressions.d.ts +9 -9
- package/dist/handlers/Program.d.ts +2 -2
- package/dist/handlers/Statements.d.ts +7 -7
- package/dist/handlers/SwitchStatement.d.ts +2 -2
- package/dist/handlers/TemplateExpression.d.ts +2 -2
- package/dist/handlers/Typescript.d.ts +8 -7
- package/dist/handlers/VariableDeclaration.d.ts +3 -3
- package/dist/handlers/WhileStatement.d.ts +3 -3
- package/dist/handlers/index.d.ts +17 -17
- package/dist/index.cjs +4170 -3164
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +4164 -3158
- package/dist/initScope.d.ts +5 -5
- package/dist/instructions/AddressResolver.d.ts +12 -12
- package/dist/instructions/ControlInstructions.d.ts +10 -10
- package/dist/instructions/EndInstruction.d.ts +6 -4
- package/dist/instructions/InstructionBase.d.ts +15 -15
- package/dist/instructions/JumpInstruction.d.ts +22 -16
- package/dist/instructions/OperationInstruction.d.ts +5 -5
- package/dist/instructions/SetCounterInstruction.d.ts +5 -5
- package/dist/instructions/SetInstruction.d.ts +8 -8
- package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -4
- package/dist/instructions/index.d.ts +9 -9
- package/dist/macros/Asm.d.ts +4 -4
- package/dist/macros/DynamicArray.d.ts +30 -23
- package/dist/macros/Function.d.ts +14 -12
- package/dist/macros/GetGlobal.d.ts +5 -5
- package/dist/macros/Math.d.ts +4 -4
- package/dist/macros/Memory.d.ts +4 -4
- package/dist/macros/Namespace.d.ts +15 -12
- package/dist/macros/Other.d.ts +4 -4
- package/dist/macros/Unchecked.d.ts +7 -0
- package/dist/macros/commands/ApplyStatus.d.ts +4 -4
- package/dist/macros/commands/Control.d.ts +4 -4
- package/dist/macros/commands/Cutscene.d.ts +4 -4
- package/dist/macros/commands/Draw.d.ts +4 -4
- package/dist/macros/commands/DrawFlush.d.ts +4 -4
- package/dist/macros/commands/End.d.ts +4 -4
- package/dist/macros/commands/Explosion.d.ts +4 -4
- package/dist/macros/commands/Fetch.d.ts +4 -4
- package/dist/macros/commands/FlushMessage.d.ts +4 -4
- package/dist/macros/commands/GetBlock.d.ts +4 -4
- package/dist/macros/commands/GetFlag.d.ts +4 -4
- package/dist/macros/commands/GetLink.d.ts +4 -4
- package/dist/macros/commands/Lookup.d.ts +4 -4
- package/dist/macros/commands/PackColor.d.ts +4 -4
- package/dist/macros/commands/Print.d.ts +4 -4
- package/dist/macros/commands/PrintFlush.d.ts +4 -4
- package/dist/macros/commands/Radar.d.ts +6 -6
- package/dist/macros/commands/Sensor.d.ts +4 -4
- package/dist/macros/commands/SetBlock.d.ts +4 -4
- package/dist/macros/commands/SetFlag.d.ts +4 -4
- package/dist/macros/commands/SetRate.d.ts +4 -4
- package/dist/macros/commands/SetRule.d.ts +4 -4
- package/dist/macros/commands/SpawnUnit.d.ts +4 -4
- package/dist/macros/commands/SpawnWave.d.ts +4 -4
- package/dist/macros/commands/Stop.d.ts +4 -4
- package/dist/macros/commands/UnitBind.d.ts +4 -4
- package/dist/macros/commands/UnitControl.d.ts +4 -4
- package/dist/macros/commands/UnitLocate.d.ts +4 -4
- package/dist/macros/commands/UnitRadar.d.ts +4 -4
- package/dist/macros/commands/Wait.d.ts +4 -4
- package/dist/macros/commands/index.d.ts +30 -30
- package/dist/macros/index.d.ts +8 -6
- package/dist/macros/util.d.ts +17 -17
- package/dist/operators.d.ts +46 -25
- package/dist/types.d.ts +259 -220
- package/dist/utils/constants.d.ts +8 -6
- package/dist/utils/general.d.ts +26 -26
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/instruction.d.ts +9 -5
- package/dist/utils/value.d.ts +40 -36
- package/dist/values/AssignmentValue.d.ts +10 -0
- package/dist/values/BaseValue.d.ts +10 -10
- package/dist/values/DestructuringValue.d.ts +32 -30
- package/dist/values/FunctionValue.d.ts +57 -50
- package/dist/values/JumpOutValue.d.ts +36 -0
- package/dist/values/LazyValue.d.ts +11 -9
- package/dist/values/LiteralValue.d.ts +18 -14
- package/dist/values/ObjectValue.d.ts +23 -20
- package/dist/values/SenseableValue.d.ts +24 -24
- package/dist/values/StoreValue.d.ts +22 -21
- package/dist/values/VoidValue.d.ts +16 -13
- package/dist/values/index.d.ts +9 -8
- package/lib/commands.d.ts +59 -32
- package/lib/eslib/lib.es5.d.ts +36 -0
- package/lib/globals.d.ts +5 -5
- package/lib/helpers.d.ts +18 -2
- package/lib/index.d.ts +1 -1
- package/lib/macros.d.ts +150 -0
- package/lib/traits.d.ts +5 -5
- package/package.json +31 -27
- package/dist/assertions.d.ts +0 -28
- package/dist/bin.cjs.map +0 -1
- package/dist/discardedName.d.ts +0 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/utils.d.ts +0 -45
- 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
|
-
[][docs]
|
|
4
4
|
|
|
5
5
|
# **JavaScript [MLog](https://mindustrygame.github.io/wiki/logic/0-introduction/) Compiler**
|
|
6
6
|
|
|
7
7
|
[][ci]
|
|
8
8
|
[][npm]
|
|
9
|
-
[][docs]
|
|
10
|
+
[][unreleased docs]
|
|
11
|
+
[][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
|
|
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
|
-
##
|
|
47
|
+
## Examples
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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/
|
|
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
|
-
[
|
|
70
|
+
[docs]: https://mlogjs.github.io/mlogjs/
|
|
71
|
+
[unreleased docs]: https://mlogjs.netlify.app
|
|
72
|
+
[discord]: https://discord.gg/SvgjCtZnR5
|
package/dist/Compiler.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { CompilerError } from "./CompilerError";
|
|
2
|
-
import { es, IScope, IValue, TEOutput, THandler, TValueInstructions } from "./types";
|
|
3
|
-
|
|
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 {};
|
package/dist/CompilerError.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
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>;
|
package/dist/handlers/File.d.ts
CHANGED
|
@@ -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
|
|
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<
|
|
3
|
-
export declare const TSTypeAssertion: THandler<
|
|
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>;
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -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";
|