mlogjs 0.3.0 → 0.4.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 (278) hide show
  1. package/dist/Compiler.d.ts +39 -0
  2. package/dist/CompilerError.d.ts +33 -0
  3. package/dist/Scope.d.ts +24 -0
  4. package/dist/assertions.d.ts +28 -0
  5. package/dist/bin.cjs +7 -14
  6. package/dist/bin.cjs.map +1 -1
  7. package/dist/bin.d.ts +1 -0
  8. package/dist/handlers/BlockStatement.d.ts +2 -0
  9. package/dist/handlers/CallExpression.d.ts +4 -0
  10. package/dist/handlers/File.d.ts +2 -0
  11. package/dist/handlers/ForStatement.d.ts +2 -0
  12. package/dist/handlers/Function.d.ts +5 -0
  13. package/dist/handlers/Identifier.d.ts +2 -0
  14. package/dist/handlers/IfStatement.d.ts +2 -0
  15. package/dist/handlers/Literal.d.ts +5 -0
  16. package/dist/handlers/Object.d.ts +6 -0
  17. package/dist/handlers/OperationExpressions.d.ts +8 -0
  18. package/dist/handlers/Program.d.ts +2 -0
  19. package/dist/handlers/Statements.d.ts +5 -0
  20. package/dist/handlers/SwitchStatement.d.ts +2 -0
  21. package/dist/handlers/TemplateExpression.d.ts +2 -0
  22. package/dist/handlers/Typescript.d.ts +7 -0
  23. package/dist/handlers/VariableDeclaration.d.ts +3 -0
  24. package/dist/handlers/WhileStatement.d.ts +3 -0
  25. package/dist/handlers/index.d.ts +17 -0
  26. package/dist/index.cjs +1037 -315
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.mjs +1037 -315
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/initScope.d.ts +5 -0
  32. package/dist/instructions/AddressResolver.d.ts +12 -0
  33. package/dist/instructions/ControlInstructions.d.ts +10 -0
  34. package/dist/instructions/EndInstruction.d.ts +4 -0
  35. package/dist/instructions/InstructionBase.d.ts +14 -0
  36. package/dist/instructions/JumpInstruction.d.ts +16 -0
  37. package/dist/instructions/OperationInstruction.d.ts +5 -0
  38. package/dist/instructions/SetCounterInstruction.d.ts +5 -0
  39. package/dist/instructions/SetInstruction.d.ts +6 -0
  40. package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -0
  41. package/dist/instructions/index.d.ts +9 -0
  42. package/dist/{types/macros/RawValue.d.ts → macros/Asm.d.ts} +1 -1
  43. package/dist/macros/Function.d.ts +13 -0
  44. package/dist/macros/GetGlobal.d.ts +5 -0
  45. package/dist/macros/Math.d.ts +5 -0
  46. package/dist/macros/Memory.d.ts +5 -0
  47. package/dist/macros/Namespace.d.ts +13 -0
  48. package/dist/macros/Other.d.ts +5 -0
  49. package/dist/macros/commands/ApplyStatus.d.ts +5 -0
  50. package/dist/macros/commands/Control.d.ts +5 -0
  51. package/dist/macros/commands/Cutscene.d.ts +5 -0
  52. package/dist/macros/commands/Draw.d.ts +5 -0
  53. package/dist/macros/commands/DrawFlush.d.ts +5 -0
  54. package/dist/macros/commands/End.d.ts +5 -0
  55. package/dist/macros/commands/Explosion.d.ts +5 -0
  56. package/dist/macros/commands/Fetch.d.ts +5 -0
  57. package/dist/macros/commands/FlushMessage.d.ts +5 -0
  58. package/dist/macros/commands/GetBlock.d.ts +5 -0
  59. package/dist/macros/commands/GetFlag.d.ts +5 -0
  60. package/dist/macros/commands/GetLink.d.ts +5 -0
  61. package/dist/macros/commands/Lookup.d.ts +5 -0
  62. package/dist/macros/commands/PackColor.d.ts +5 -0
  63. package/dist/macros/commands/Print.d.ts +5 -0
  64. package/dist/macros/commands/PrintFlush.d.ts +5 -0
  65. package/dist/macros/commands/Radar.d.ts +7 -0
  66. package/dist/macros/commands/Sensor.d.ts +5 -0
  67. package/dist/macros/commands/SetBlock.d.ts +5 -0
  68. package/dist/macros/commands/SetFlag.d.ts +5 -0
  69. package/dist/macros/commands/SetRate.d.ts +5 -0
  70. package/dist/macros/commands/SetRule.d.ts +5 -0
  71. package/dist/macros/commands/SpawnUnit.d.ts +5 -0
  72. package/dist/macros/commands/SpawnWave.d.ts +5 -0
  73. package/dist/macros/commands/Stop.d.ts +5 -0
  74. package/dist/macros/commands/UnitBind.d.ts +5 -0
  75. package/dist/macros/commands/UnitControl.d.ts +5 -0
  76. package/dist/macros/commands/UnitLocate.d.ts +5 -0
  77. package/dist/macros/commands/UnitRadar.d.ts +5 -0
  78. package/dist/macros/commands/Wait.d.ts +5 -0
  79. package/dist/macros/commands/index.d.ts +30 -0
  80. package/dist/macros/index.d.ts +6 -0
  81. package/dist/macros/util.d.ts +18 -0
  82. package/dist/operators.d.ts +25 -0
  83. package/dist/types/Compiler.d.ts +17 -4
  84. package/dist/types/CompilerError.d.ts +28 -4
  85. package/dist/types/assertions.d.ts +28 -0
  86. package/dist/types/handlers/CallExpression.d.ts +1 -0
  87. package/dist/types/handlers/SwitchStatement.d.ts +2 -0
  88. package/dist/types/handlers/index.d.ts +1 -0
  89. package/dist/types/index.d.ts +1 -0
  90. package/dist/types/instructions/ControlInstructions.d.ts +3 -1
  91. package/dist/types/instructions/InstructionBase.d.ts +5 -1
  92. package/dist/types/instructions/JumpInstruction.d.ts +1 -0
  93. package/dist/types/macros/Asm.d.ts +5 -0
  94. package/dist/types/macros/Namespace.d.ts +0 -3
  95. package/dist/types/macros/commands/ApplyStatus.d.ts +5 -0
  96. package/dist/types/macros/commands/Control.d.ts +2 -2
  97. package/dist/types/macros/commands/Cutscene.d.ts +5 -0
  98. package/dist/types/macros/commands/Draw.d.ts +2 -2
  99. package/dist/types/macros/commands/Explosion.d.ts +5 -0
  100. package/dist/types/macros/commands/Fetch.d.ts +5 -0
  101. package/dist/types/macros/commands/FlushMessage.d.ts +5 -0
  102. package/dist/types/macros/commands/GetBlock.d.ts +5 -0
  103. package/dist/types/macros/commands/GetFlag.d.ts +5 -0
  104. package/dist/types/macros/commands/Lookup.d.ts +2 -2
  105. package/dist/types/macros/commands/PackColor.d.ts +5 -0
  106. package/dist/types/macros/commands/Radar.d.ts +2 -2
  107. package/dist/types/macros/commands/SetBlock.d.ts +5 -0
  108. package/dist/types/macros/commands/SetFlag.d.ts +5 -0
  109. package/dist/types/macros/commands/SetRate.d.ts +5 -0
  110. package/dist/types/macros/commands/SetRule.d.ts +5 -0
  111. package/dist/types/macros/commands/SpawnUnit.d.ts +5 -0
  112. package/dist/types/macros/commands/SpawnWave.d.ts +5 -0
  113. package/dist/types/macros/commands/Stop.d.ts +5 -0
  114. package/dist/types/macros/commands/UnitControl.d.ts +3 -3
  115. package/dist/types/macros/commands/UnitLocate.d.ts +2 -2
  116. package/dist/types/macros/commands/index.d.ts +15 -0
  117. package/dist/types/macros/util.d.ts +18 -0
  118. package/dist/types/types.d.ts +14 -0
  119. package/dist/types/utils.d.ts +19 -2
  120. package/dist/types/values/BaseValue.d.ts +2 -0
  121. package/dist/types/values/FunctionValue.d.ts +1 -1
  122. package/dist/types/values/ObjectValue.d.ts +1 -1
  123. package/dist/types.d.ts +238 -0
  124. package/dist/utils.d.ts +47 -0
  125. package/dist/values/BaseValue.d.ts +9 -0
  126. package/dist/values/DestructuringValue.d.ts +17 -0
  127. package/dist/values/FunctionValue.d.ts +47 -0
  128. package/dist/values/LiteralValue.d.ts +13 -0
  129. package/dist/values/ObjectValue.d.ts +23 -0
  130. package/dist/values/SenseableValue.d.ts +23 -0
  131. package/dist/{types/values/StackValue.d.ts → values/StoreValue.d.ts} +5 -6
  132. package/dist/values/ValueOwner.d.ts +27 -0
  133. package/dist/values/VoidValue.d.ts +16 -0
  134. package/dist/values/index.d.ts +7 -0
  135. package/lib/commands.d.ts +849 -418
  136. package/lib/eslib/lib.es2015.core.d.ts +3 -0
  137. package/lib/globals.d.ts +331 -19
  138. package/lib/helpers.d.ts +14 -0
  139. package/lib/kinds.d.ts +3 -2
  140. package/lib/memory.d.ts +1 -1
  141. package/lib/traits.d.ts +6 -0
  142. package/lib/util.d.ts +16 -0
  143. package/package.json +15 -16
  144. package/build/Compiler.js +0 -105
  145. package/build/Compiler.js.map +0 -1
  146. package/build/CompilerError.js +0 -11
  147. package/build/CompilerError.js.map +0 -1
  148. package/build/Scope.js +0 -71
  149. package/build/Scope.js.map +0 -1
  150. package/build/bin.js +0 -75
  151. package/build/bin.js.map +0 -1
  152. package/build/handlers/BlockStatement.js +0 -14
  153. package/build/handlers/BlockStatement.js.map +0 -1
  154. package/build/handlers/CallExpression.js +0 -20
  155. package/build/handlers/CallExpression.js.map +0 -1
  156. package/build/handlers/File.js +0 -9
  157. package/build/handlers/File.js.map +0 -1
  158. package/build/handlers/ForStatement.js +0 -32
  159. package/build/handlers/ForStatement.js.map +0 -1
  160. package/build/handlers/Function.js +0 -47
  161. package/build/handlers/Function.js.map +0 -1
  162. package/build/handlers/Identifier.js +0 -8
  163. package/build/handlers/Identifier.js.map +0 -1
  164. package/build/handlers/IfStatement.js +0 -25
  165. package/build/handlers/IfStatement.js.map +0 -1
  166. package/build/handlers/Literal.js +0 -15
  167. package/build/handlers/Literal.js.map +0 -1
  168. package/build/handlers/Object.js +0 -55
  169. package/build/handlers/Object.js.map +0 -1
  170. package/build/handlers/OperationExpressions.js +0 -38
  171. package/build/handlers/OperationExpressions.js.map +0 -1
  172. package/build/handlers/Program.js +0 -9
  173. package/build/handlers/Program.js.map +0 -1
  174. package/build/handlers/Statements.js +0 -30
  175. package/build/handlers/Statements.js.map +0 -1
  176. package/build/handlers/TemplateExpression.js +0 -18
  177. package/build/handlers/TemplateExpression.js.map +0 -1
  178. package/build/handlers/VariableDeclaration.js +0 -72
  179. package/build/handlers/VariableDeclaration.js.map +0 -1
  180. package/build/handlers/WhileStatement.js +0 -23
  181. package/build/handlers/WhileStatement.js.map +0 -1
  182. package/build/handlers/index.js +0 -32
  183. package/build/handlers/index.js.map +0 -1
  184. package/build/index.js +0 -8
  185. package/build/index.js.map +0 -1
  186. package/build/initScope.js +0 -40
  187. package/build/initScope.js.map +0 -1
  188. package/build/instructions/AddressResolver.js +0 -31
  189. package/build/instructions/AddressResolver.js.map +0 -1
  190. package/build/instructions/ControlInstructions.js +0 -23
  191. package/build/instructions/ControlInstructions.js.map +0 -1
  192. package/build/instructions/EndInstruction.js +0 -11
  193. package/build/instructions/EndInstruction.js.map +0 -1
  194. package/build/instructions/InstructionBase.js +0 -21
  195. package/build/instructions/InstructionBase.js.map +0 -1
  196. package/build/instructions/JumpInstruction.js +0 -22
  197. package/build/instructions/JumpInstruction.js.map +0 -1
  198. package/build/instructions/OperationInstruction.js +0 -11
  199. package/build/instructions/OperationInstruction.js.map +0 -1
  200. package/build/instructions/SetCounterInstruction.js +0 -11
  201. package/build/instructions/SetCounterInstruction.js.map +0 -1
  202. package/build/instructions/SetInstruction.js +0 -11
  203. package/build/instructions/SetInstruction.js.map +0 -1
  204. package/build/instructions/ZeroSpaceInstruction.js +0 -11
  205. package/build/instructions/ZeroSpaceInstruction.js.map +0 -1
  206. package/build/instructions/index.js +0 -26
  207. package/build/instructions/index.js.map +0 -1
  208. package/build/macros/Building.js +0 -89
  209. package/build/macros/Building.js.map +0 -1
  210. package/build/macros/Function.js +0 -20
  211. package/build/macros/Function.js.map +0 -1
  212. package/build/macros/Math.js +0 -62
  213. package/build/macros/Math.js.map +0 -1
  214. package/build/macros/Memory.js +0 -63
  215. package/build/macros/Memory.js.map +0 -1
  216. package/build/macros/Namespace.js +0 -111
  217. package/build/macros/Namespace.js.map +0 -1
  218. package/build/macros/Other.js +0 -21
  219. package/build/macros/Other.js.map +0 -1
  220. package/build/macros/RawValue.js +0 -17
  221. package/build/macros/RawValue.js.map +0 -1
  222. package/build/macros/commands/Control.js +0 -26
  223. package/build/macros/commands/Control.js.map +0 -1
  224. package/build/macros/commands/Draw.js +0 -40
  225. package/build/macros/commands/Draw.js.map +0 -1
  226. package/build/macros/commands/DrawFlush.js +0 -18
  227. package/build/macros/commands/DrawFlush.js.map +0 -1
  228. package/build/macros/commands/GetLink.js +0 -25
  229. package/build/macros/commands/GetLink.js.map +0 -1
  230. package/build/macros/commands/Lookup.js +0 -25
  231. package/build/macros/commands/Lookup.js.map +0 -1
  232. package/build/macros/commands/Print.js +0 -18
  233. package/build/macros/commands/Print.js.map +0 -1
  234. package/build/macros/commands/PrintFlush.js +0 -18
  235. package/build/macros/commands/PrintFlush.js.map +0 -1
  236. package/build/macros/commands/Radar.js +0 -65
  237. package/build/macros/commands/Radar.js.map +0 -1
  238. package/build/macros/commands/Sensor.js +0 -21
  239. package/build/macros/commands/Sensor.js.map +0 -1
  240. package/build/macros/commands/UnitBind.js +0 -18
  241. package/build/macros/commands/UnitBind.js.map +0 -1
  242. package/build/macros/commands/UnitControl.js +0 -73
  243. package/build/macros/commands/UnitControl.js.map +0 -1
  244. package/build/macros/commands/UnitLocate.js +0 -76
  245. package/build/macros/commands/UnitLocate.js.map +0 -1
  246. package/build/macros/commands/UnitRadar.js +0 -48
  247. package/build/macros/commands/UnitRadar.js.map +0 -1
  248. package/build/macros/commands/Wait.js +0 -19
  249. package/build/macros/commands/Wait.js.map +0 -1
  250. package/build/macros/commands/index.js +0 -33
  251. package/build/macros/commands/index.js.map +0 -1
  252. package/build/macros/index.js +0 -40
  253. package/build/macros/index.js.map +0 -1
  254. package/build/operators.js +0 -102
  255. package/build/operators.js.map +0 -1
  256. package/build/types.js +0 -28
  257. package/build/types.js.map +0 -1
  258. package/build/utils.js +0 -18
  259. package/build/utils.js.map +0 -1
  260. package/build/values/BaseValue.js +0 -112
  261. package/build/values/BaseValue.js.map +0 -1
  262. package/build/values/FunctionValue.js +0 -116
  263. package/build/values/FunctionValue.js.map +0 -1
  264. package/build/values/LiteralValue.js +0 -89
  265. package/build/values/LiteralValue.js.map +0 -1
  266. package/build/values/ObjectValue.js +0 -55
  267. package/build/values/ObjectValue.js.map +0 -1
  268. package/build/values/StoreValue.js +0 -32
  269. package/build/values/StoreValue.js.map +0 -1
  270. package/build/values/TempValue.js +0 -78
  271. package/build/values/TempValue.js.map +0 -1
  272. package/build/values/VoidValue.js +0 -32
  273. package/build/values/VoidValue.js.map +0 -1
  274. package/build/values/index.js +0 -23
  275. package/build/values/index.js.map +0 -1
  276. package/dist/types/macros/Building.d.ts +0 -10
  277. package/dist/types/macros/Entities.d.ts +0 -11
  278. package/dist/types/values/TempValue.d.ts +0 -19
@@ -0,0 +1,39 @@
1
+ import { CompilerError } from "./CompilerError";
2
+ import { es, IScope, IValue, 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): TValueInstructions<IValue | null>;
25
+ handleEval(scope: IScope, node: es.Node): TValueInstructions;
26
+ handleConsume(scope: IScope, node: es.Node): TValueInstructions;
27
+ /**
28
+ * Handles many nodes in order.
29
+ *
30
+ * The usage of this method over a regular loop over an array of nodes
31
+ * is only required if the code inside the loop generates
32
+ * instructions that are not tracked by the compiler
33
+ * handler methods ({@link handle}, {@link handleEval}, {@link handleConsume}
34
+ * and {@link handleMany})
35
+ *
36
+ */
37
+ handleMany<T extends es.Node>(scope: IScope, nodes: T[], handler?: (node: T) => TValueInstructions<IValue | null>): TValueInstructions<null>;
38
+ }
39
+ export {};
@@ -0,0 +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 {};
@@ -0,0 +1,24 @@
1
+ import { SenseableValue } from "./values";
2
+ import { AddressResolver } from "./instructions";
3
+ import { IFunctionValue, IInstruction, IOwnedValue, IScope, IValue, IValueOwner } 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, IValueOwner | null>;
11
+ break: AddressResolver;
12
+ continue: AddressResolver;
13
+ function: IFunctionValue;
14
+ constructor(values: Record<string, IValueOwner | null>, parent?: IScope | null, stacked?: boolean, ntemp?: number, name?: string, inst?: IInstruction[]);
15
+ copy(): IScope;
16
+ createScope(): IScope;
17
+ createFunction(name: string, stacked?: boolean): IScope;
18
+ has(identifier: string): boolean;
19
+ get(identifier: string): IOwnedValue;
20
+ set<T extends IValue>(...args: [name: string, value: T] | [owner: IValueOwner<T>]): T;
21
+ hardSet<T extends IValue>(...args: [name: string, value: T] | [owner: IValueOwner<T>]): T;
22
+ make(identifier: string, name: string): SenseableValue;
23
+ makeTempName(): string;
24
+ }
@@ -0,0 +1,28 @@
1
+ import { IValue } from "./types";
2
+ import { LiteralValue, ObjectValue, StoreValue } from "./values";
3
+ /** Asserts that `value` is a `LiteralValue` that contains a string */
4
+ export declare function assertStringLiteral(value: IValue | undefined, name: string): asserts value is LiteralValue & {
5
+ data: string;
6
+ };
7
+ /** Asserts that `value` is a string literal that is part of a given set of `members`*/
8
+ export declare function assertLiteralOneOf<T extends readonly string[]>(value: IValue | undefined, members: T, name: string): asserts value is LiteralValue & {
9
+ data: T[number];
10
+ };
11
+ /** Asserts that `value` is either a store or a literal */
12
+ export declare function assertIsRuntimeValue(value: IValue | undefined, name: string): asserts value is LiteralValue | StoreValue;
13
+ /** Asserts that `value` is an `ObjectValue` */
14
+ export declare function assertIsObjectMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
15
+ /** Asserts that `value` is an `ObjectValue` that has a length property */
16
+ export declare function assertIsArrayMacro(value: IValue | undefined, name: string): asserts value is ObjectValue;
17
+ /** Helper type used to describe the overloads of a macro function. See {@link assertObjectFields} */
18
+ export declare type TOverloadDescriptor<K extends string> = Record<K, (string | IParameterDescriptor)[]>;
19
+ /** Describes an object destructuring paremeter. Generally used with `assertObjectFields` */
20
+ export interface IParameterDescriptor {
21
+ key: string;
22
+ name?: string;
23
+ default?: string;
24
+ /** Throw an error on invalid values */
25
+ validate?(value: IValue): void;
26
+ }
27
+ /** Asserts that all of the fields described are present on `value`*/
28
+ export declare function assertObjectFields(value: ObjectValue, fields: (string | IParameterDescriptor)[]): (IValue | string)[];
package/dist/bin.cjs CHANGED
@@ -43,29 +43,22 @@ yargs__default["default"](helpers.hideBin(process.argv))
43
43
  compactNames: argv["compact-names"],
44
44
  });
45
45
  const code = fs.readFileSync(path$1, "utf8");
46
- const [output, error, [node]] = compiler.compile(code);
46
+ const [output, error] = compiler.compile(code);
47
47
  if (error) {
48
- if (!(error instanceof index_cjs.CompilerError)) {
49
- console.error(error);
48
+ if (!error.loc) {
49
+ console.log(error.inner ?? error);
50
50
  return;
51
51
  }
52
- let start = error.loc;
53
- let end = start;
54
- if (node) {
55
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
56
- start = node.loc.start;
57
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58
- end = node.loc.end;
59
- }
52
+ const { start, end } = error.loc;
60
53
  const lines = code.split("\n");
61
54
  console.log(chalk__default["default"].cyanBright([path.resolve(path$1), start.line, start.column].join(":")));
62
55
  for (let i = Math.max(start.line - 3, 0); i < Math.min(end.line + 2, lines.length); i++) {
63
56
  const n = i + 1;
57
+ if (n !== start.line)
58
+ continue;
64
59
  const head = chalk__default["default"].gray(`${n} | `.padStart(6, " "));
65
60
  console.log(head + cliHighlight.highlight(lines[i], { language: "js" }));
66
- if (n === start.line) {
67
- console.log(chalk__default["default"].red(" ".repeat(6 + start.column) + "^ " + error.message));
68
- }
61
+ console.log(chalk__default["default"].red(" ".repeat(6 + start.column) + "^ " + error.message));
69
62
  }
70
63
  return;
71
64
  }
package/dist/bin.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.cjs","sources":["../src/bin.ts"],"sourcesContent":[null],"names":["yargs","hideBin","path","existsSync","Compiler","readFileSync","CompilerError","chalk","resolve","highlight","writeFileSync","parse","join"],"mappings":";;;;;;;;;;;;;;;;AAQAA,yBAAK,CAACC,eAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,KAAA,OAAO,CACN,iBAAiB,EACjB,uCAAuC,EACvC,KAAK,IAAG;AACN,IAAA,OAAO,KAAK;SACT,UAAU,CAAC,MAAM,EAAE;AAClB,QAAA,QAAQ,EAAE,6BAA6B;AACvC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,UAAU,CAAC,KAAK,EAAE;AACjB,QAAA,QAAQ,EAAE,yBAAyB;AACnC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,MAAM,CAAC,eAAe,EAAE;AACvB,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,QAAQ,EACN,4EAA4E;AAC/E,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AAG,CAAG,CAAA,CAAA,CAC9D,CAAC;AACJ,CAAC,CACF;AACA,KAAA,IAAI,EAAE;KACN,UAAU,CAAC,QAAQ,CAAC;AACpB,KAAA,aAAa,EAAE;AACf,KAAA,KAAK,EAAE,CAAC;AAEX,SAAS,cAAc,CAACA,MAAY,EAAA;AAClC,IAAA,MAAM,MAAM,GAAGS,UAAK,CAACT,MAAI,CAAC,CAAC;AAC3B,IAAA,OAAOU,SAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAG,EAAA,MAAM,CAAC,IAAI,CAAO,KAAA,CAAA,CAAC,CAAC;AACjD;;"}
1
+ {"version":3,"file":"bin.cjs","sources":["../src/bin.ts"],"sourcesContent":[null],"names":["yargs","hideBin","path","existsSync","Compiler","readFileSync","chalk","resolve","highlight","writeFileSync","parse","join"],"mappings":";;;;;;;;;;;;;;;;AAQAA,yBAAK,CAACC,eAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,KAAA,OAAO,CACN,iBAAiB,EACjB,uCAAuC,EACvC,KAAK,IAAG;AACN,IAAA,OAAO,KAAK;SACT,UAAU,CAAC,MAAM,EAAE;AAClB,QAAA,QAAQ,EAAE,6BAA6B;AACvC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,UAAU,CAAC,KAAK,EAAE;AACjB,QAAA,QAAQ,EAAE,yBAAyB;AACnC,QAAA,IAAI,EAAE,QAAQ;KACf,CAAC;SACD,MAAM,CAAC,eAAe,EAAE;AACvB,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,QAAQ,EACN,4EAA4E;AAC/E,KAAA,CAAC,CAAC;AACP,CAAC,EACD,IAAI,IAAG;AACL,IAAA,MAAMC,MAAI,GAAG,IAAI,CAAC,IAAI,CAAC;AACvB,IAAA,IAAI,CAACA,MAAI;AAAE,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChE,IAAA,IAAI,CAACC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 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { IValue, THandler } from "../types";
2
+ export declare const BlockStatement: THandler<IValue | null>;
@@ -0,0 +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>;
@@ -0,0 +1,2 @@
1
+ import { IValue, THandler } from "../types";
2
+ export declare const File: THandler<IValue | null>;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const ForStatement: THandler<null>;
@@ -0,0 +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;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const Identifier: THandler;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const IfStatement: THandler<null>;
@@ -0,0 +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;
@@ -0,0 +1,6 @@
1
+ import { 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;
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const Program: THandler<null>;
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const SwitchStatement: THandler<null>;
@@ -0,0 +1,2 @@
1
+ import { THandler } from "../types";
2
+ export declare const TemplateLiteral: THandler<null>;
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,3 @@
1
+ import { THandler } from "../types";
2
+ export declare const VariableDeclaration: THandler<null>;
3
+ export declare const VariableDeclarator: THandler<null>;
@@ -0,0 +1,3 @@
1
+ import { THandler } from "../types";
2
+ export declare const WhileStatement: THandler<null>;
3
+ export declare const DoWhileStatement: THandler<null>;
@@ -0,0 +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";