@bikky/compiler 0.0.7 → 0.0.9

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 (52) hide show
  1. package/Libraries/BiscuitLibraries.d.ts +2 -2
  2. package/Libraries/BiscuitLibraries.js +2 -2
  3. package/Libraries/GlobalTypes.d.ts +25 -27
  4. package/Libraries/MixinCode.d.ts +13 -13
  5. package/Libraries/MixinCode.js +92 -92
  6. package/Source/ASTBuilder.d.ts +36 -0
  7. package/Source/ASTBuilder.d.ts.map +1 -0
  8. package/Source/ASTBuilder.js +180 -0
  9. package/Source/ASTHelper.d.ts +67 -73
  10. package/Source/ASTHelper.d.ts.map +1 -1
  11. package/Source/ASTHelper.js +320 -343
  12. package/Source/ASTInterface/Class.d.ts +38 -0
  13. package/Source/ASTInterface/Class.d.ts.map +1 -0
  14. package/Source/ASTInterface/Class.js +256 -0
  15. package/Source/ASTInterface/Crawler.d.ts +8 -0
  16. package/Source/ASTInterface/Crawler.d.ts.map +1 -0
  17. package/Source/ASTInterface/Crawler.js +55 -0
  18. package/Source/ASTInterface/Tokens.d.ts +78 -0
  19. package/Source/ASTInterface/Tokens.d.ts.map +1 -0
  20. package/Source/ASTInterface/Tokens.js +49 -0
  21. package/Source/ASTSearcher.d.ts +20 -0
  22. package/Source/ASTSearcher.d.ts.map +1 -0
  23. package/Source/ASTSearcher.js +116 -0
  24. package/Source/ASTTraverser.d.ts +10 -0
  25. package/Source/ASTTraverser.d.ts.map +1 -0
  26. package/Source/ASTTraverser.js +74 -0
  27. package/Transformers/CompilerInsertions.js +23 -22
  28. package/Transformers/MacroTransformer.d.ts +2 -2
  29. package/Transformers/MacroTransformer.d.ts.map +1 -1
  30. package/Transformers/MacroTransformer.js +282 -272
  31. package/Transformers/MixinTransformer.d.ts +2 -3
  32. package/Transformers/MixinTransformer.d.ts.map +1 -1
  33. package/Transformers/MixinTransformer.js +320 -123
  34. package/Transformers/{Macros.d.ts → SuperTransformer.d.ts} +3 -3
  35. package/Transformers/SuperTransformer.d.ts.map +1 -0
  36. package/Transformers/{SuperTransform.js → SuperTransformer.js} +139 -117
  37. package/bin/Microsoft.NodejsTools.WebRole.dll +0 -0
  38. package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
  39. package/obj/Debug/BiscuitCompiler.njsproj.FileListAbsolute.txt +3 -3
  40. package/package.json +6 -5
  41. package/tsconfig.build.libs.json +1 -1
  42. package/tsconfig.build.libs.tsbuildinfo +1 -1
  43. package/tsconfig.build.src.json +1 -1
  44. package/tsconfig.build.src.tsbuildinfo +1 -1
  45. package/tsconfig.json +10 -11
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/ASTHelper.d.ts +0 -74
  48. package/ASTHelper.d.ts.map +0 -1
  49. package/Transformers/Macros.d.ts.map +0 -1
  50. package/Transformers/SuperTransform.d.ts +0 -3
  51. package/Transformers/SuperTransform.d.ts.map +0 -1
  52. package/tsconfig.build.tsbuildinfo +0 -1
@@ -1,3 +1,3 @@
1
- /// <reference path="GlobalTypes.d.ts" />
2
- import "./MixinCode.js";
1
+ /// <reference path="GlobalTypes.d.ts" />
2
+ import "./MixinCode.js";
3
3
  //# sourceMappingURL=BiscuitLibraries.d.ts.map
@@ -1,3 +1,3 @@
1
- /// <reference path="./GlobalTypes.d.ts" />
2
- import "./MixinCode.js";
1
+ /// <reference path="./GlobalTypes.d.ts" />
2
+ import "./MixinCode.js";
3
3
  //# sourceMappingURL=BiscuitLibraries.js.map
@@ -1,45 +1,43 @@
1
1
 
2
- declare module BikkyTypes {
2
+ type Writable<T> = { -readonly [P in keyof T]: T[P] }
3
3
 
4
- type Writable<T> = { -readonly [P in keyof T]: T[P] }
4
+ type GetConstraints<Extras> = Extras extends (Function & { prototype: infer Constraints })[] ? Constraints : never;
5
+ type UnionToIntersection<U> =
6
+ (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
7
+ type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
5
8
 
6
- type GetConstraints<Extras> = Extras extends (Function & { prototype: infer Constraints })[] ? Constraints : never;
7
- type UnionToIntersection<U> =
8
- (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
9
- type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
9
+ type Class<T> = (new (...args: any[]) => T);
10
+ type AbstractClass<T> = Function & { prototype: T };
11
+ type ClassObject<T> = T extends (new (...args: any[]) => infer C) ? C : never;
12
+ type AbstractClassObject<T> = T extends (Function & { prototype: infer C }) ? C : never;
13
+ type AbstractClassArguments<T> = T extends abstract new (...args: infer A) => any ? A : never;
14
+ type ClassArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
10
15
 
11
- type Class<T> = (new (...args: any[]) => T);
12
- type AbstractClass<T> = Function & { prototype: T };
13
- type ClassObject<T> = T extends (new (...args: any[]) => infer C) ? C : never;
14
- type AbstractClassObject<T> = T extends (Function & { prototype: infer C }) ? C : never;
15
- type AbstractClassArguments<T> = T extends abstract new (...args: infer A) => any ? A : never;
16
- type ClassArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
16
+ type ConstructArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
17
+ type Prototype<T> = (Function & { prototype: T });
18
+ type ObjectType<T> = T extends (new (...args: any[]) => infer C) ? C : never;
17
19
 
18
- type ConstructArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
19
- type Prototype<T> = (Function & { prototype: T });
20
- type ObjectType<T> = T extends (new (...args: any[]) => infer C) ? C : never;
21
- }
22
20
  //Unfortunately Typescript doesn't currently support the following typing (as in the decorator's typing
23
21
  // information will not properly alter typescript's typing information):
24
22
  //First set of params are the ones supplied in the decorator, like: @mixin(common, extra1, extra2);
25
23
  declare function mixin<
26
24
  Super extends Object,
27
- Extras extends BikkyTypes.Prototype<any>[]
28
- >(common: BikkyTypes.Prototype<Super>, ...constraints: Extras): (
25
+ Extras extends Prototype<any>[]
26
+ >(common: Prototype<Super>, ...constraints: Extras): (
29
27
  //Second set of params are the class the decorator is decorating, in this case the mixin.
30
28
  <
31
29
  MixinClass extends Function & { prototype: Object },
32
- Mixin extends BikkyTypes.Prototype<MixinClass>,
33
- ConstructorArgs extends BikkyTypes.ConstructArguments<Mixin>,
30
+ Mixin extends Prototype<MixinClass>,
31
+ ConstructorArgs extends ConstructArguments<Mixin>,
34
32
  >
35
33
  (mixin: MixinClass) => MixinClass & {
36
34
  //We return a mix function that takes the class that the mixin
37
35
  // is to be mixed onto. We want to ensure that the new class
38
36
  // fulfills all the requirements listed with the decorator.
39
37
  mix: <
40
- Core extends BikkyTypes.AllConstraints<Super, BikkyTypes.GetConstraints<Extras>>
38
+ Core extends AllConstraints<Super, GetConstraints<Extras>>
41
39
  >
42
- (core: BikkyTypes.Prototype<Core>) =>
40
+ (core: Prototype<Core>) =>
43
41
  //Lastly we return a function that requires the mixin's constructor arguments and returns
44
42
  // an object which is a combination of the mixin and the provided core class.
45
43
  (new (...args: ConstructorArgs) => Core & Mixin);
@@ -50,10 +48,10 @@ declare function mixin<
50
48
  // decorators are updated.
51
49
  declare function makeMixer<
52
50
  MixinClass extends (new (...args: any[]) => object),
53
- Mixin extends BikkyTypes.ClassObject<MixinClass>,
54
- ConstructorArgs extends BikkyTypes.ConstructArguments<MixinClass>,
55
- Super extends Object, Extras extends BikkyTypes.Prototype<any>[]>
56
- (mixin: MixinClass, common: BikkyTypes.Prototype<Super>, ...constraints: Extras): (
57
- <Core extends BikkyTypes.AllConstraints<Super, BikkyTypes.GetConstraints<Extras>>>(core: { new(...args: any[]): Core } ) =>
51
+ Mixin extends ClassObject<MixinClass>,
52
+ ConstructorArgs extends ConstructArguments<MixinClass>,
53
+ Super extends Object, Extras extends Prototype<any>[]>
54
+ (mixin: MixinClass, common: Prototype<Super>, ...constraints: Extras): (
55
+ <Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: { new(...args: any[]): Core } ) =>
58
56
  (new (...args: ConstructorArgs) => Core & Mixin));
59
57
 
@@ -1,14 +1,14 @@
1
- type GetConstraints<Extras> = Extras extends (Function & {
2
- prototype: infer Constraints;
3
- })[] ? Constraints : never;
4
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
5
- type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
6
- type Class<T> = (Function & {
7
- prototype: T;
8
- });
9
- export declare function makeMixerFoo<Mixin extends Object, Super extends Object, Extras extends Class<any>[]>(mixin: Class<Mixin>, common: Class<Super>, ...constraints: Extras): <Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: Function & {
10
- prototype: Core;
11
- }) => new (id: string, name: string, data: any, instance?: any) => Core & Mixin;
12
- export declare function MixableClass<Base extends Class<Object>>(param: Base): Base;
13
- export {};
1
+ type GetConstraints<Extras> = Extras extends (Function & {
2
+ prototype: infer Constraints;
3
+ })[] ? Constraints : never;
4
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
5
+ type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
6
+ type Class<T> = (Function & {
7
+ prototype: T;
8
+ });
9
+ export declare function makeMixerFoo<Mixin extends Object, Super extends Object, Extras extends Class<any>[]>(mixin: Class<Mixin>, common: Class<Super>, ...constraints: Extras): <Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: Function & {
10
+ prototype: Core;
11
+ }) => new (id: string, name: string, data: any, instance?: any) => Core & Mixin;
12
+ export declare function MixableClass<Base extends Class<Object>>(param: Base): Base;
13
+ export {};
14
14
  //# sourceMappingURL=MixinCode.d.ts.map
@@ -1,24 +1,24 @@
1
- //Propertydescriptor is needed to preserve getters and setters, otherwise we trigger them.
2
- // We assign functions directly though to preserve the prototype chain when using super() [it's not working].
3
- function duplicatePrototype(prototype, parent) {
4
- var names = Array.from(Object.getOwnPropertyNames(prototype));
5
- names.push(...Object.getOwnPropertySymbols(prototype));
6
- var result = { __proto__: parent };
7
- for (let i = names.length - 1; i >= 0; i--) {
8
- let name = names[i];
9
- var descriptor = Object.getOwnPropertyDescriptor(prototype, name);
10
- Object.defineProperty(result, name, descriptor);
11
- }
12
- return result;
13
- }
14
- var mixingObject = [];
15
- var mixingBases = [];
16
- var mixingBaseProtos = [];
17
- //The following parameter type allows abstract classes, where as new () => Core doesn't.
18
- export function makeMixerFoo(mixin, common, ...constraints) {
19
- if (typeof mixin !== "function" || !mixin.prototype)
20
- throw new Error("Can only mix classes into other classes.");
21
- return function mix(core) {
1
+ //Propertydescriptor is needed to preserve getters and setters, otherwise we trigger them.
2
+ // We assign functions directly though to preserve the prototype chain when using super() [it's not working].
3
+ function duplicatePrototype(prototype, parent) {
4
+ var names = Array.from(Object.getOwnPropertyNames(prototype));
5
+ names.push(...Object.getOwnPropertySymbols(prototype));
6
+ var result = { __proto__: parent };
7
+ for (let i = names.length - 1; i >= 0; i--) {
8
+ let name = names[i];
9
+ var descriptor = Object.getOwnPropertyDescriptor(prototype, name);
10
+ Object.defineProperty(result, name, descriptor);
11
+ }
12
+ return result;
13
+ }
14
+ var mixingObject = [];
15
+ var mixingBases = [];
16
+ var mixingBaseProtos = [];
17
+ //The following parameter type allows abstract classes, where as new () => Core doesn't.
18
+ export function makeMixerFoo(mixin, common, ...constraints) {
19
+ if (typeof mixin !== "function" || !mixin.prototype)
20
+ throw new Error("Can only mix classes into other classes.");
21
+ return function mix(core) {
22
22
  var newClass = eval(`
23
23
  function Mixin_${mixin.name}(...args) {
24
24
  //This allows us to change the prototype which the constructor uses for creating
@@ -35,75 +35,75 @@ export function makeMixerFoo(mixin, common, ...constraints) {
35
35
  return object;
36
36
  };
37
37
  Mixin_${mixin.name}
38
- `);
39
- var originalPrototypes = [];
40
- var current = mixin;
41
- originalPrototypes.push(current.prototype);
42
- current = current.prototype;
43
- while (mixingBaseProtos.indexOf(current.__proto__) < 0 && current.__proto__ != Object.prototype) {
44
- originalPrototypes.push(current.__proto__);
45
- current = current.__proto__;
46
- }
47
- var newPrototypes = [];
48
- while (originalPrototypes.length > 0) {
49
- current = originalPrototypes.pop();
50
- let originalClass = current;
51
- var prototype = newPrototypes.length == 0 ? core.prototype : newPrototypes[0];
52
- let newmix = duplicatePrototype(current, prototype);
53
- var edits = {
54
- //We override the original isA so that this class appears to be a movable as well as other types.
55
- isA(other) {
56
- if (other.prototype == originalClass) {
57
- return true;
58
- }
59
- else {
60
- return super.isA(other);
61
- }
62
- },
63
- };
64
- Object.assign(newmix, edits);
65
- newmix.__proto__ = prototype;
66
- //This ensures any super calls in the edits to the prototype resolve correctly, because
67
- // they're based on the original object the function is defined in, not the prototype the
68
- // function ends up on.
69
- edits.__proto__ = prototype;
70
- newPrototypes.unshift(newmix);
71
- }
72
- newClass.prototype = newPrototypes[0];
73
- newClass.prototype.constructor = newClass;
74
- //I wanted to do this on object creation rather than having it be inherited, but that caused a problem with the value
75
- // not being accessible in the constructor, which is necessary because the constructor can call other functons.
76
- if (mixin.Super) {
77
- //console.log("Configuring", mixin.name, "to have a parent that is", newClass.prototype.__proto__.constructor.name);
78
- newClass.prototype[mixin.Super] = core.prototype;
79
- }
80
- //newClass.__proto__ = newPrototypes[0];
81
- return newClass;
82
- };
83
- }
84
- export function MixableClass(param) {
85
- //This is done to preserve super calls in mixins.
86
- class Mixbase extends param {
87
- //@ts-ignore we don't need to call super in this child class.
88
- constructor(...args) {
89
- //We can't override the class' object using .call or .apply, but we can override it in the base class.
90
- var object = mixingObject[0];
91
- return object;
92
- }
93
- }
94
- ;
95
- mixingBases.push(Mixbase);
96
- mixingBaseProtos.push(Mixbase.prototype);
97
- return Mixbase;
98
- }
99
- if (typeof global !== "undefined") {
100
- global.Mixable = MixableClass;
101
- global.makeMixer = makeMixerFoo;
102
- }
103
- else {
104
- Mixable = MixableClass;
105
- makeMixer = makeMixerFoo;
106
- window.Mixable = MixableClass;
107
- window.makeMixer = makeMixerFoo;
108
- }
38
+ `);
39
+ var originalPrototypes = [];
40
+ var current = mixin;
41
+ originalPrototypes.push(current.prototype);
42
+ current = current.prototype;
43
+ while (mixingBaseProtos.indexOf(current.__proto__) < 0 && current.__proto__ != Object.prototype) {
44
+ originalPrototypes.push(current.__proto__);
45
+ current = current.__proto__;
46
+ }
47
+ var newPrototypes = [];
48
+ while (originalPrototypes.length > 0) {
49
+ current = originalPrototypes.pop();
50
+ let originalClass = current;
51
+ var prototype = newPrototypes.length == 0 ? core.prototype : newPrototypes[0];
52
+ let newmix = duplicatePrototype(current, prototype);
53
+ var edits = {
54
+ //We override the original isA so that this class appears to be a movable as well as other types.
55
+ isA(other) {
56
+ if (other.prototype == originalClass) {
57
+ return true;
58
+ }
59
+ else {
60
+ return super.isA(other);
61
+ }
62
+ },
63
+ };
64
+ Object.assign(newmix, edits);
65
+ newmix.__proto__ = prototype;
66
+ //This ensures any super calls in the edits to the prototype resolve correctly, because
67
+ // they're based on the original object the function is defined in, not the prototype the
68
+ // function ends up on.
69
+ edits.__proto__ = prototype;
70
+ newPrototypes.unshift(newmix);
71
+ }
72
+ newClass.prototype = newPrototypes[0];
73
+ newClass.prototype.constructor = newClass;
74
+ //I wanted to do this on object creation rather than having it be inherited, but that caused a problem with the value
75
+ // not being accessible in the constructor, which is necessary because the constructor can call other functons.
76
+ if (mixin.Super) {
77
+ //console.log("Configuring", mixin.name, "to have a parent that is", newClass.prototype.__proto__.constructor.name);
78
+ newClass.prototype[mixin.Super] = core.prototype;
79
+ }
80
+ //newClass.__proto__ = newPrototypes[0];
81
+ return newClass;
82
+ };
83
+ }
84
+ export function MixableClass(param) {
85
+ //This is done to preserve super calls in mixins.
86
+ class Mixbase extends param {
87
+ //@ts-ignore we don't need to call super in this child class.
88
+ constructor(...args) {
89
+ //We can't override the class' object using .call or .apply, but we can override it in the base class.
90
+ var object = mixingObject[0];
91
+ return object;
92
+ }
93
+ }
94
+ ;
95
+ mixingBases.push(Mixbase);
96
+ mixingBaseProtos.push(Mixbase.prototype);
97
+ return Mixbase;
98
+ }
99
+ if (typeof global !== "undefined") {
100
+ global.Mixable = MixableClass;
101
+ global.makeMixer = makeMixerFoo;
102
+ }
103
+ else {
104
+ Mixable = MixableClass;
105
+ makeMixer = makeMixerFoo;
106
+ window.Mixable = MixableClass;
107
+ window.makeMixer = makeMixerFoo;
108
+ }
109
109
  //# sourceMappingURL=MixinCode.js.map
@@ -0,0 +1,36 @@
1
+ import * as ts from "typescript";
2
+ import { ArithmeticSymbols, AssignmentSymbols, BitwiseOperators, ComparisonOperators, LogicalOperators } from "./ASTInterface/Tokens";
3
+ type AnyExpr = Expression | ts.Expression;
4
+ declare class Expression<NodeType extends ts.Node = ts.Expression> {
5
+ ast: NodeType;
6
+ constructor(ast: NodeType);
7
+ isExpression(): this is Expression<ts.Expression>;
8
+ getExpression(): ts.Expression;
9
+ DOT(other: string | ts.MemberName | Expression<ts.MemberName>): Expression<ts.Expression>;
10
+ LOOKUP(other: number | ts.Expression | Expression): Expression<ts.Expression>;
11
+ OP(op: keyof typeof ComparisonOperators | keyof typeof LogicalOperators | keyof typeof BitwiseOperators | keyof typeof ArithmeticSymbols, other: ts.Expression | Expression): Expression<ts.Expression>;
12
+ ASGN(op: keyof typeof AssignmentSymbols, other: ts.Expression | Expression): Expression<ts.AssignmentExpression<ts.EqualsToken>>;
13
+ toAST(): NodeType;
14
+ }
15
+ export declare function EXP(exp: ts.Expression | Expression): Expression<ts.Expression>;
16
+ export declare function VAR(id: string, val?: ts.Expression | Expression): Expression<ts.VariableStatement>;
17
+ export declare function LET(id: string, val?: ts.Expression | Expression): Expression<ts.VariableStatement>;
18
+ export declare function NOT(exp: Expression | ts.Expression): Expression<ts.Expression>;
19
+ export declare function SUPER(): Expression<ts.SuperExpression>;
20
+ export declare function THIS(): Expression<ts.ThisExpression>;
21
+ export declare function CALL(name: AnyExpr, ...args: AnyExpr[]): Expression<ts.CallExpression>;
22
+ export declare function METHOD_CALL(parent: AnyExpr, name: ts.MemberName | Expression<ts.MemberName>, ...args: AnyExpr[]): Expression;
23
+ export declare function FUNC_CALL(name: AnyExpr, ...args: AnyExpr[]): Expression;
24
+ export declare function FUNC_BIND(name: AnyExpr, newThis: AnyExpr): Expression<ts.Expression>;
25
+ export declare function TYPEOF(other: ts.Expression): Expression<ts.TypeOfExpression>;
26
+ export declare function ID(name: string): Expression<ts.Identifier>;
27
+ export declare function LITERAL(name: string): Expression<ts.StringLiteral>;
28
+ export declare function IF(ifs: ts.Expression | Expression, then: ts.Statement | Statement, elses?: ts.Statement | Statement): ts.IfStatement;
29
+ declare class Statement {
30
+ statements: (ts.Expression | Expression)[];
31
+ LINE(exp: ts.Expression | Expression): void;
32
+ toAST(): ts.Block;
33
+ }
34
+ export declare function STATEMENT(): Statement;
35
+ export {};
36
+ //# sourceMappingURL=ASTBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTBuilder.d.ts","sourceRoot":"","sources":["ASTBuilder.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STATEMENT = exports.IF = exports.LITERAL = exports.ID = exports.TYPEOF = exports.FUNC_BIND = exports.FUNC_CALL = exports.METHOD_CALL = exports.CALL = exports.THIS = exports.SUPER = exports.NOT = exports.LET = exports.VAR = exports.EXP = void 0;
4
+ const ts = require("typescript");
5
+ const Tokens_1 = require("./ASTInterface/Tokens");
6
+ const Crawler_1 = require("./ASTInterface/Crawler");
7
+ `EXP(SUPER().ACCESS(Name)).OP(!==, "undefined")`;
8
+ function getAST(item) {
9
+ if (typeof item === "string")
10
+ return Crawler_1.Crawler.getContext().factory.createStringLiteral(item);
11
+ if (item instanceof Expression || item instanceof Statement)
12
+ return item.toAST();
13
+ return item;
14
+ }
15
+ class Expression {
16
+ constructor(ast) {
17
+ this.ast = ast;
18
+ }
19
+ isExpression() {
20
+ return ts.isExpression(this.ast);
21
+ }
22
+ getExpression() {
23
+ if (!ts.isExpression(this.ast))
24
+ throw new Error("Error, node requires expression but this is not.");
25
+ return this.ast;
26
+ }
27
+ DOT(other) {
28
+ if (!this.ast)
29
+ throw new Error("Can't dot access undefined.");
30
+ return new Expression(Crawler_1.Crawler.getContext().factory.createPropertyAccessExpression(this.getExpression(), getAST(other)));
31
+ }
32
+ LOOKUP(other) {
33
+ if (!this.ast)
34
+ throw new Error("Can't [] access undefined.");
35
+ return new Expression(Crawler_1.Crawler.getContext().factory.createElementAccessExpression(this.getExpression(), typeof other === "number" ? other : getAST(other)));
36
+ }
37
+ OP(op, other) {
38
+ other = getAST(other);
39
+ if (!this.ast)
40
+ throw new Error("Can't use nothing as lhs of operator expression..");
41
+ if (op in Tokens_1.ComparisonOperators) {
42
+ let opType = Tokens_1.ComparisonOperators[op];
43
+ return new Expression(Crawler_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), opType, other));
44
+ }
45
+ if (op in Tokens_1.LogicalOperators) {
46
+ switch (op) {
47
+ case "||":
48
+ return new Expression(Crawler_1.Crawler.getContext().factory.createLogicalOr(this.getExpression(), other));
49
+ break;
50
+ case "&&":
51
+ return new Expression(Crawler_1.Crawler.getContext().factory.createLogicalAnd(this.getExpression(), other));
52
+ break;
53
+ case "!":
54
+ break;
55
+ }
56
+ }
57
+ return this;
58
+ }
59
+ ASGN(op, other) {
60
+ other = getAST(other);
61
+ if (ts.isVariableStatement(this.ast)) {
62
+ if (op != "=")
63
+ throw new Error("Cannot declare variable with assignment operator other than =.");
64
+ let dec = this.ast.declarationList.declarations[0];
65
+ ts.factory.updateVariableDeclaration(dec, dec.name, dec.exclamationToken, dec.type, other);
66
+ return this;
67
+ }
68
+ switch (op) {
69
+ case "=":
70
+ return new Expression(Crawler_1.Crawler.getContext().factory.createAssignment(this.getExpression(), other));
71
+ break;
72
+ default:
73
+ return new Expression(Crawler_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), Tokens_1.AssignmentSymbols[op], other));
74
+ break;
75
+ }
76
+ return this;
77
+ }
78
+ toAST() {
79
+ return this.ast;
80
+ }
81
+ ;
82
+ }
83
+ function EXP(exp) {
84
+ if (exp instanceof Expression)
85
+ return exp;
86
+ return new Expression(exp);
87
+ }
88
+ exports.EXP = EXP;
89
+ function VAR(id, val) {
90
+ val = val instanceof Expression ? val.toAST() : val;
91
+ if (val && ts.isVariableStatement(val))
92
+ throw new Error("Can't use variable declaration as initialiser for another variable declaration.");
93
+ let dec = ts.factory.createVariableDeclaration(id, void 0, void 0, val);
94
+ let node = ts.factory.createVariableStatement([], ts.factory.createVariableDeclarationList([dec]));
95
+ return new Expression(node);
96
+ }
97
+ exports.VAR = VAR;
98
+ function LET(id, val) {
99
+ val = val instanceof Expression ? val.toAST() : val;
100
+ if (val && ts.isVariableStatement(val))
101
+ throw new Error("Can't use variable declaration as initialiser for another variable declaration.");
102
+ let dec = ts.factory.createVariableDeclaration(id, void 0, void 0, val);
103
+ let node = ts.factory.createVariableStatement([], ts.factory.createVariableDeclarationList([dec], ts.NodeFlags.Let));
104
+ return new Expression(node);
105
+ }
106
+ exports.LET = LET;
107
+ function NOT(exp) {
108
+ if (!(exp instanceof Expression))
109
+ exp = new Expression(exp);
110
+ if (ts.isVariableStatement(exp.ast))
111
+ throw new Error("Cannot NOT a variable declaration.");
112
+ exp.ast = Crawler_1.Crawler.getContext().factory.createLogicalNot(exp.ast);
113
+ return exp;
114
+ }
115
+ exports.NOT = NOT;
116
+ function SUPER() {
117
+ return new Expression(Crawler_1.Crawler.getContext().factory.createSuper());
118
+ }
119
+ exports.SUPER = SUPER;
120
+ function THIS() {
121
+ return new Expression(Crawler_1.Crawler.getContext().factory.createThis());
122
+ }
123
+ exports.THIS = THIS;
124
+ ///Call a function.
125
+ function CALL(name, ...args) {
126
+ return new Expression(Crawler_1.Crawler.getContext().factory.createCallExpression(getAST(name), undefined, args.map((e) => getAST(e))));
127
+ }
128
+ exports.CALL = CALL;
129
+ ///Call parent.method.call
130
+ function METHOD_CALL(parent, name, ...args) {
131
+ if (!(parent instanceof Expression))
132
+ parent = new Expression(parent);
133
+ return CALL(parent.DOT(name).DOT(ID("call")), ...args);
134
+ }
135
+ exports.METHOD_CALL = METHOD_CALL;
136
+ function FUNC_CALL(name, ...args) {
137
+ if (!(name instanceof Expression))
138
+ name = new Expression(name);
139
+ return CALL(name.DOT(ID("call")), ...args);
140
+ }
141
+ exports.FUNC_CALL = FUNC_CALL;
142
+ function FUNC_BIND(name, newThis) {
143
+ if (!(name instanceof Expression))
144
+ name = new Expression(name);
145
+ return FUNC_CALL(name, ID("bind"), newThis);
146
+ }
147
+ exports.FUNC_BIND = FUNC_BIND;
148
+ function TYPEOF(other) {
149
+ return new Expression(Crawler_1.Crawler.getContext().factory.createTypeOfExpression(other));
150
+ }
151
+ exports.TYPEOF = TYPEOF;
152
+ function ID(name) {
153
+ return new Expression(Crawler_1.Crawler.getContext().factory.createIdentifier(name));
154
+ }
155
+ exports.ID = ID;
156
+ function LITERAL(name) {
157
+ return new Expression(Crawler_1.Crawler.getContext().factory.createStringLiteral(name));
158
+ }
159
+ exports.LITERAL = LITERAL;
160
+ function IF(ifs, then, elses) {
161
+ return Crawler_1.Crawler.getContext().factory.createIfStatement(getAST(ifs), getAST(then), elses ? getAST(elses) : elses);
162
+ }
163
+ exports.IF = IF;
164
+ class Statement {
165
+ constructor() {
166
+ this.statements = [];
167
+ }
168
+ LINE(exp) {
169
+ this.statements.push(exp);
170
+ }
171
+ toAST() {
172
+ let statements = this.statements.map((e) => Crawler_1.Crawler.getContext().factory.createExpressionStatement(getAST(e)));
173
+ return Crawler_1.Crawler.getContext().factory.createBlock(statements);
174
+ }
175
+ }
176
+ function STATEMENT() {
177
+ return new Statement;
178
+ }
179
+ exports.STATEMENT = STATEMENT;
180
+ //# sourceMappingURL=ASTBuilder.js.map