@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
@@ -0,0 +1,38 @@
1
+ import * as ts from "typescript";
2
+ import { NamedExpression } from "../ASTHelper";
3
+ type APICallback<T, R = T> = (obj: T | null) => R | null;
4
+ export declare class Decorator extends NamedExpression {
5
+ base: ts.Decorator;
6
+ constructor(base: ts.Decorator | ts.Identifier | string);
7
+ update(): ts.Decorator;
8
+ }
9
+ export declare class Class extends NamedExpression {
10
+ base: ts.ClassDeclaration | ts.ClassExpression;
11
+ modifiers: ts.Modifier[];
12
+ decorators: Decorator[];
13
+ extends: ts.HeritageClause | undefined;
14
+ implements: ts.HeritageClause[];
15
+ members: (ts.ClassElement)[];
16
+ typeParams: ts.TypeParameterDeclaration[];
17
+ constructor(base: ts.ClassDeclaration | ts.ClassExpression | string | ts.Identifier);
18
+ hasExtends(): boolean;
19
+ setExtends(extend: ts.ExpressionWithTypeArguments): void;
20
+ unshiftDecorator(...dec: Decorator[]): this;
21
+ pushDecorator(...dec: Decorator[]): this;
22
+ decorator(identifier: string | ts.Identifier, cb: APICallback<Decorator>): this;
23
+ decorator(cb: APICallback<Decorator>): this;
24
+ unshift(...members: ts.ClassElement[]): this;
25
+ push(...members: ts.ClassElement[]): this;
26
+ property(identifier: string | ts.Identifier | ts.PropertyDeclaration, cb: APICallback<ts.PropertyDeclaration, ts.ClassElement>): this;
27
+ property(cb: APICallback<ts.PropertyDeclaration, ts.ClassElement>): this;
28
+ method(identifier: string | ts.Identifier | ts.MethodDeclaration, cb: APICallback<ts.MethodDeclaration, ts.ClassElement>): this;
29
+ method(cb: APICallback<ts.MethodDeclaration, ts.ClassElement>): this;
30
+ update(): ts.ClassDeclaration | ts.ClassExpression;
31
+ }
32
+ export declare module Class {
33
+ function getModifiers(node: ts.ClassDeclaration): ts.Modifier[];
34
+ function getDecorators(node: ts.ClassDeclaration): ts.Decorator[];
35
+ function onClass(repl: (val: Class) => (Class | ts.Node | ts.Node[])): void;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=Class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Class.d.ts","sourceRoot":"","sources":["Class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,KAAI,CAAC,GAAG,IAAI,CAAC;AAExD,qBAAa,SAAU,SAAQ,eAAe;IAC1C,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC;gBAEP,IAAI,EAAE,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,UAAU,GAAG,MAAM;IAqBvD,MAAM;CAUT;AAED,qBAAa,KAAM,SAAQ,eAAe;IACtC,IAAI,EAAE,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,eAAe,CAAC;IAE/C,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAM;IAC9B,UAAU,EAA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iB,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI;IAC/H,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI;IAuCpE,MAAM;CAgBT;AAGD,sBAAc,KAAK,CAAC;IAEhB,SAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,iBAErD;IAED,SAAgB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,kBAEtD;IAID,SAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,QAE1E;CAeJ"}
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Class = exports.Decorator = void 0;
4
+ const ts = require("typescript");
5
+ const ASTHelper_1 = require("../ASTHelper");
6
+ const Crawler_1 = require("./Crawler");
7
+ class Decorator extends ASTHelper_1.NamedExpression {
8
+ constructor(base) {
9
+ if (typeof base === "string")
10
+ base = ts.factory.createIdentifier(base);
11
+ let name;
12
+ if (ts.isDecorator(base)) {
13
+ if (ts.isCallExpression(base.expression)) {
14
+ //Call expression's expression is an identifier
15
+ name = base.expression.expression;
16
+ }
17
+ else {
18
+ //If not a call expression it's just an identifier (because no brackets)
19
+ name = base.expression;
20
+ }
21
+ }
22
+ else {
23
+ name = base;
24
+ base = ts.factory.createDecorator(base);
25
+ }
26
+ super(name);
27
+ this.base = base;
28
+ }
29
+ update() {
30
+ if (ts.isCallExpression(this.base.expression)) {
31
+ ts.factory.updateCallExpression(this.base.expression, this.name, this.base.expression.typeArguments, this.base.expression.arguments);
32
+ return this.base;
33
+ }
34
+ else {
35
+ ts.factory.updateDecorator(this.base, this.name);
36
+ return this.base;
37
+ }
38
+ }
39
+ }
40
+ exports.Decorator = Decorator;
41
+ class Class extends ASTHelper_1.NamedExpression {
42
+ constructor(base) {
43
+ if (typeof base === "string")
44
+ base = ts.factory.createIdentifier(base);
45
+ super(ts.isIdentifier(base) ? base : base.name);
46
+ this.modifiers = [];
47
+ this.decorators = [];
48
+ this.implements = [];
49
+ this.members = [];
50
+ this.typeParams = [];
51
+ if (ts.isClassDeclaration(base)) {
52
+ this.base = base;
53
+ if (this.base.heritageClauses) {
54
+ for (var clause of this.base.heritageClauses) {
55
+ if (clause.token == ts.SyntaxKind.ExtendsKeyword) {
56
+ this.extends = clause;
57
+ }
58
+ else {
59
+ this.implements.push(clause);
60
+ }
61
+ }
62
+ }
63
+ this.members = Array.from(this.base.members);
64
+ this.decorators = Class.getDecorators(this.base).map((e) => new Decorator(e));
65
+ this.modifiers = Class.getModifiers(this.base);
66
+ }
67
+ else {
68
+ this.base = ts.factory.createClassDeclaration(undefined, undefined, undefined, undefined, []);
69
+ }
70
+ }
71
+ hasExtends() {
72
+ return !!this.extends;
73
+ }
74
+ setExtends(extend) {
75
+ this.extends = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [extend]);
76
+ }
77
+ unshiftDecorator(...dec) {
78
+ this.decorators.unshift(...dec);
79
+ return this;
80
+ }
81
+ pushDecorator(...dec) {
82
+ this.decorators.push(...dec);
83
+ return this;
84
+ }
85
+ decorator(identifier, cb) {
86
+ let name;
87
+ if (typeof identifier === "function") {
88
+ cb = identifier;
89
+ name = null;
90
+ }
91
+ else {
92
+ name = (typeof identifier === "string") ? identifier : identifier.text;
93
+ }
94
+ for (let i = 0; i < this.decorators.length; i++) {
95
+ let decorator = this.decorators[i];
96
+ if (name) {
97
+ let decoratorName = decorator.name.text;
98
+ if (decoratorName != name) {
99
+ continue;
100
+ }
101
+ }
102
+ let newDec = cb(decorator);
103
+ if (newDec) {
104
+ this.decorators.splice(i, 1, newDec);
105
+ }
106
+ else {
107
+ this.decorators.splice(i, 1);
108
+ }
109
+ return this;
110
+ }
111
+ if (name) {
112
+ let newDec = cb(null);
113
+ if (newDec) {
114
+ this.decorators.push(newDec);
115
+ }
116
+ }
117
+ return this;
118
+ }
119
+ unshift(...members) {
120
+ this.members.unshift(...members);
121
+ return this;
122
+ }
123
+ push(...members) {
124
+ this.members.push(...members);
125
+ return this;
126
+ }
127
+ property(identifier, cb) {
128
+ let name;
129
+ if (typeof identifier === "function") {
130
+ cb = identifier;
131
+ name = null;
132
+ }
133
+ else {
134
+ if (typeof identifier === "string") {
135
+ name = identifier;
136
+ }
137
+ else if (ts.isIdentifier(identifier)) {
138
+ name = identifier.text;
139
+ }
140
+ else {
141
+ name = identifier.name.getText();
142
+ }
143
+ }
144
+ for (let i = 0; i < this.members.length; i++) {
145
+ let property = this.members[i];
146
+ if (!ts.isPropertyDeclaration(property)) {
147
+ continue;
148
+ }
149
+ if (name) {
150
+ let nameTag = property.name;
151
+ let propertyName;
152
+ if (ts.isIdentifier(nameTag)) {
153
+ propertyName = nameTag.text;
154
+ }
155
+ else {
156
+ propertyName = nameTag.getText();
157
+ }
158
+ if (propertyName != name) {
159
+ continue;
160
+ }
161
+ }
162
+ let newProp = cb(property);
163
+ if (newProp) {
164
+ this.members.splice(i, 1, newProp);
165
+ }
166
+ else {
167
+ this.members.splice(i, 1);
168
+ }
169
+ return this;
170
+ }
171
+ if (name) {
172
+ let newDec = cb(null);
173
+ if (newDec) {
174
+ this.members.push(newDec);
175
+ }
176
+ }
177
+ return this;
178
+ }
179
+ method(identifier, cb) {
180
+ let name;
181
+ if (typeof identifier === "function") {
182
+ cb = identifier;
183
+ name = null;
184
+ }
185
+ else {
186
+ name = (typeof identifier === "string") ? identifier : ts.isIdentifier(identifier) ? identifier.text : identifier.name.getText();
187
+ }
188
+ for (let i = 0; i < this.members.length; i++) {
189
+ let property = this.members[i];
190
+ if (!ts.isMethodDeclaration(property)) {
191
+ continue;
192
+ }
193
+ if (name) {
194
+ let propertyName = property.name.getText();
195
+ if (propertyName != name) {
196
+ continue;
197
+ }
198
+ }
199
+ let newProp = cb(property);
200
+ if (newProp) {
201
+ this.members.splice(i, 1, newProp);
202
+ }
203
+ else {
204
+ this.members.splice(i, 1);
205
+ }
206
+ return this;
207
+ }
208
+ if (name) {
209
+ let newDec = cb(null);
210
+ if (newDec) {
211
+ this.members.push(newDec);
212
+ }
213
+ }
214
+ return this;
215
+ }
216
+ update() {
217
+ if (ts.isClassDeclaration(this.base)) {
218
+ return ts.factory.updateClassDeclaration(this.base, [...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
219
+ }
220
+ else {
221
+ return ts.factory.updateClassExpression(this.base, [...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
222
+ }
223
+ }
224
+ }
225
+ exports.Class = Class;
226
+ (function (Class) {
227
+ function getModifiers(node) {
228
+ var _a, _b;
229
+ return ([...((_b = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter((m) => m.kind != ts.SyntaxKind.Decorator)) !== null && _b !== void 0 ? _b : [])]);
230
+ }
231
+ Class.getModifiers = getModifiers;
232
+ function getDecorators(node) {
233
+ var _a, _b;
234
+ return ([...((_b = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter((m) => m.kind == ts.SyntaxKind.Decorator)) !== null && _b !== void 0 ? _b : [])]);
235
+ }
236
+ Class.getDecorators = getDecorators;
237
+ let foos = [];
238
+ function onClass(repl) {
239
+ foos.push(repl);
240
+ }
241
+ Class.onClass = onClass;
242
+ Crawler_1.Crawler.Register((node) => {
243
+ return ts.isClassExpression(node) || ts.isClassDeclaration(node);
244
+ }, (node) => {
245
+ let val = new Class(node);
246
+ for (let foo of foos) {
247
+ let result = foo(val);
248
+ if (!(result instanceof Class)) {
249
+ return result;
250
+ }
251
+ val = result;
252
+ }
253
+ return val.update();
254
+ });
255
+ })(Class || (exports.Class = Class = {}));
256
+ //# sourceMappingURL=Class.js.map
@@ -0,0 +1,8 @@
1
+ import * as ts from "typescript";
2
+ export declare module Crawler {
3
+ function Register(checker: (node: ts.Node) => boolean, replacer: (node: ts.Node) => (ts.Node | ts.Node[])): void;
4
+ function setContext(newContext: ts.TransformationContext): void;
5
+ function getContext(): ts.TransformationContext;
6
+ function Crawl(start: ts.Node, callback?: (node: ts.Node) => (ts.Node | ts.Node[])): ts.Node;
7
+ }
8
+ //# sourceMappingURL=Crawler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Crawler.d.ts","sourceRoot":"","sources":["Crawler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,sBAAc,OAAO,CAAC;IAGlB,SAAgB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,QAE3G;IAED,SAAgB,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,qBAAqB,QAG9D;IAED,SAAgB,UAAU,6BAEzB;IAED,SAAgB,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAI,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,WA4BvF;CAEJ"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Crawler = void 0;
4
+ const ts = require("typescript");
5
+ const ASTHelper_js_1 = require("../ASTHelper.js");
6
+ var Crawler;
7
+ (function (Crawler) {
8
+ let foos = new Map();
9
+ let context;
10
+ function Register(checker, replacer) {
11
+ foos.set(checker, replacer);
12
+ }
13
+ Crawler.Register = Register;
14
+ function setContext(newContext) {
15
+ context = newContext;
16
+ (0, ASTHelper_js_1.setContext)(context);
17
+ }
18
+ Crawler.setContext = setContext;
19
+ function getContext() {
20
+ return context;
21
+ }
22
+ Crawler.getContext = getContext;
23
+ function Crawl(start, callback) {
24
+ let crawlArray = (array) => {
25
+ for (let i = 0; i < array.length; i++) {
26
+ array[i] = ts.visitEachChild(array[i], crawl, context);
27
+ }
28
+ array = array.flat(1);
29
+ return array;
30
+ };
31
+ let crawl = (node) => {
32
+ for (let [check, value] of foos.entries()) {
33
+ let result = node;
34
+ if (check(node))
35
+ result = value(node);
36
+ //If we get given a bunch of nodes, we should visit each one individually and return.
37
+ if (Array.isArray(result)) {
38
+ return crawlArray(result);
39
+ }
40
+ node = result;
41
+ }
42
+ let result = node;
43
+ if (callback) {
44
+ result = callback(node);
45
+ }
46
+ if (Array.isArray(result)) {
47
+ return crawlArray(result);
48
+ }
49
+ return ts.visitEachChild(result, crawl, context);
50
+ };
51
+ return ts.visitEachChild(start, crawl, context);
52
+ }
53
+ Crawler.Crawl = Crawl;
54
+ })(Crawler || (exports.Crawler = Crawler = {}));
55
+ //# sourceMappingURL=Crawler.js.map
@@ -0,0 +1,78 @@
1
+ import * as ts from "typescript";
2
+ export declare const ArithmeticSymbols: {
3
+ "+": ts.SyntaxKind;
4
+ "\u2013": ts.SyntaxKind;
5
+ "*": ts.SyntaxKind;
6
+ "/": ts.SyntaxKind;
7
+ "%": ts.SyntaxKind;
8
+ "++": ts.SyntaxKind;
9
+ };
10
+ export declare const ComparisonOperators: {
11
+ "==": ts.SyntaxKind;
12
+ "===": ts.SyntaxKind;
13
+ "!=": ts.SyntaxKind;
14
+ "!==": ts.SyntaxKind;
15
+ ">": ts.SyntaxKind;
16
+ ">=": ts.SyntaxKind;
17
+ "<": ts.SyntaxKind;
18
+ "<=": ts.SyntaxKind;
19
+ };
20
+ export declare const BitwiseOperators: {
21
+ "&": ts.SyntaxKind;
22
+ "|": ts.SyntaxKind;
23
+ "^": ts.SyntaxKind;
24
+ "~": ts.SyntaxKind;
25
+ "<<": ts.SyntaxKind;
26
+ ">>": ts.SyntaxKind;
27
+ ">>>": ts.SyntaxKind;
28
+ };
29
+ export declare const LogicalOperators: {
30
+ "&&": ts.SyntaxKind;
31
+ "||": ts.SyntaxKind;
32
+ "!": ts.SyntaxKind;
33
+ };
34
+ export declare const AssignmentSymbols: {
35
+ "=": ts.SyntaxKind;
36
+ "+=": ts.SyntaxKind;
37
+ "-=": ts.SyntaxKind;
38
+ "*=": ts.SyntaxKind;
39
+ "/=": ts.SyntaxKind;
40
+ "%=": ts.SyntaxKind;
41
+ };
42
+ export declare const OtherSymbols: {
43
+ ",": ts.SyntaxKind;
44
+ };
45
+ export declare const AnyBinarySymbols: {
46
+ ",": ts.SyntaxKind;
47
+ "=": ts.SyntaxKind;
48
+ "+=": ts.SyntaxKind;
49
+ "-=": ts.SyntaxKind;
50
+ "*=": ts.SyntaxKind;
51
+ "/=": ts.SyntaxKind;
52
+ "%=": ts.SyntaxKind;
53
+ "&&": ts.SyntaxKind;
54
+ "||": ts.SyntaxKind;
55
+ "!": ts.SyntaxKind;
56
+ "&": ts.SyntaxKind;
57
+ "|": ts.SyntaxKind;
58
+ "^": ts.SyntaxKind;
59
+ "~": ts.SyntaxKind;
60
+ "<<": ts.SyntaxKind;
61
+ ">>": ts.SyntaxKind;
62
+ ">>>": ts.SyntaxKind;
63
+ "==": ts.SyntaxKind;
64
+ "===": ts.SyntaxKind;
65
+ "!=": ts.SyntaxKind;
66
+ "!==": ts.SyntaxKind;
67
+ ">": ts.SyntaxKind;
68
+ ">=": ts.SyntaxKind;
69
+ "<": ts.SyntaxKind;
70
+ "<=": ts.SyntaxKind;
71
+ "+": ts.SyntaxKind;
72
+ "\u2013": ts.SyntaxKind;
73
+ "*": ts.SyntaxKind;
74
+ "/": ts.SyntaxKind;
75
+ "%": ts.SyntaxKind;
76
+ "++": ts.SyntaxKind;
77
+ };
78
+ //# sourceMappingURL=Tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tokens.d.ts","sourceRoot":"","sources":["Tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,eAAO,MAAM,iBAAiB;;;;;;;CAO7B,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;;;;CAS/B,CAAC;AAGF,eAAO,MAAM,gBAAgB;;;;;;;;CAQ5B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;CAO7B,CAAC;AAEF,eAAO,MAAM,YAAY;;CAExB,CAAA;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkI,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnyBinarySymbols = exports.OtherSymbols = exports.AssignmentSymbols = exports.LogicalOperators = exports.BitwiseOperators = exports.ComparisonOperators = exports.ArithmeticSymbols = void 0;
4
+ const ts = require("typescript");
5
+ exports.ArithmeticSymbols = {
6
+ "+": ts.SyntaxKind.PlusToken,
7
+ "–": ts.SyntaxKind.MinusToken,
8
+ "*": ts.SyntaxKind.AsteriskToken,
9
+ "/": ts.SyntaxKind.SlashToken,
10
+ "%": ts.SyntaxKind.PercentToken,
11
+ "++": ts.SyntaxKind.PlusPlusToken,
12
+ };
13
+ exports.ComparisonOperators = {
14
+ "==": ts.SyntaxKind.EqualsEqualsToken,
15
+ "===": ts.SyntaxKind.EqualsEqualsToken,
16
+ "!=": ts.SyntaxKind.ExclamationEqualsToken,
17
+ "!==": ts.SyntaxKind.ExclamationEqualsEqualsToken,
18
+ ">": ts.SyntaxKind.GreaterThanToken,
19
+ ">=": ts.SyntaxKind.GreaterThanEqualsToken,
20
+ "<": ts.SyntaxKind.LessThanToken,
21
+ "<=": ts.SyntaxKind.LessThanEqualsToken,
22
+ };
23
+ exports.BitwiseOperators = {
24
+ "&": ts.SyntaxKind.AmpersandToken,
25
+ "|": ts.SyntaxKind.BarToken,
26
+ "^": ts.SyntaxKind.CaretToken,
27
+ "~": ts.SyntaxKind.TildeToken,
28
+ "<<": ts.SyntaxKind.LessThanLessThanToken,
29
+ ">>": ts.SyntaxKind.GreaterThanGreaterThanToken,
30
+ ">>>": ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken,
31
+ };
32
+ exports.LogicalOperators = {
33
+ "&&": ts.SyntaxKind.AmpersandAmpersandToken,
34
+ "||": ts.SyntaxKind.BarBarToken,
35
+ "!": ts.SyntaxKind.ExclamationToken
36
+ };
37
+ exports.AssignmentSymbols = {
38
+ "=": ts.SyntaxKind.EqualsToken,
39
+ "+=": ts.SyntaxKind.PlusEqualsToken,
40
+ "-=": ts.SyntaxKind.MinusEqualsToken,
41
+ "*=": ts.SyntaxKind.AsteriskEqualsToken,
42
+ "/=": ts.SyntaxKind.SlashEqualsToken,
43
+ "%=": ts.SyntaxKind.PercentEqualsToken
44
+ };
45
+ exports.OtherSymbols = {
46
+ ",": ts.SyntaxKind.CommaToken
47
+ };
48
+ exports.AnyBinarySymbols = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, exports.ArithmeticSymbols), exports.ComparisonOperators), exports.BitwiseOperators), exports.LogicalOperators), exports.AssignmentSymbols), exports.OtherSymbols);
49
+ //# sourceMappingURL=Tokens.js.map
@@ -0,0 +1,20 @@
1
+ import * as ts from "typescript";
2
+ declare class Searcher<NodeType extends ts.Node = ts.Expression> {
3
+ exp: Expression<NodeType>;
4
+ constructor(exp: Expression<NodeType>);
5
+ BINARY(lhs: ((node: ts.Node) => boolean) | undefined, op: string | undefined | ((node: ts.Node) => boolean), rhs: ((node: ts.Node) => boolean) | undefined): boolean;
6
+ }
7
+ declare class Expression<NodeType extends ts.Node = ts.Expression> {
8
+ ast: NodeType;
9
+ MATCH: Searcher<NodeType>;
10
+ constructor(ast: NodeType);
11
+ }
12
+ export declare function FROM<NodeType extends ts.Node>(node: NodeType): Expression<NodeType>;
13
+ export declare function HAS_IN_STATEMENT(node: ts.Node, cb: ((node: ts.Node) => boolean)): boolean;
14
+ export declare function HAS_IN_STATEMENT(cb: ((node: ts.Node) => boolean)): (arg: ts.Node) => boolean;
15
+ export declare function FIND_IN_STATEMENT<NodeType = ts.Node>(node: ts.Node, cb: ((node: ts.Node) => boolean)): NodeType | null;
16
+ export declare function FIND_IN_STATEMENT<NodeType = ts.Node>(cb: ((node: ts.Node) => boolean)): (arg: ts.Node) => NodeType | null;
17
+ export declare function HAS_ID_IN_STATEMENT(node: ts.Node, id: string | ts.Identifier): boolean;
18
+ export declare function HAS_ID_IN_STATEMENT(id: string | ts.Identifier): (node: ts.Node) => boolean;
19
+ export {};
20
+ //# sourceMappingURL=ASTSearcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTSearcher.d.ts","sourceRoot":"","sources":["ASTSearcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAMjC,cAAM,QAAQ,CAAC,QAAQ,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,UAAU;IACnD,GAAG,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAEd,GAAG,EAAE,UAAU,CAAC,QAAQ,CAAC;IAIrC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,GAAG,SAAS;CAoB7J;AAED,cAAM,UAAU,CAAC,QAAQ,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,UAAU;IACrD,GAAG,EAAG,QAAQ,CAAC;IAEf,KAAK,EAAE,QAA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IN_STATEMENT = exports.FIND_IN_STATEMENT = exports.HAS_IN_STATEMENT = exports.FROM = void 0;
4
+ const ts = require("typescript");
5
+ const Tokens_1 = require("./ASTInterface/Tokens");
6
+ const Crawler_1 = require("./ASTInterface/Crawler");
7
+ class Searcher {
8
+ constructor(exp) {
9
+ this.exp = exp;
10
+ }
11
+ BINARY(lhs, op, rhs) {
12
+ if (!ts.isBinaryExpression(this.exp.ast)) {
13
+ return false;
14
+ }
15
+ let bin = this.exp.ast;
16
+ if (lhs) {
17
+ if (!lhs(bin.left))
18
+ return false;
19
+ }
20
+ if (typeof op === "string") {
21
+ let kind = Tokens_1.AnyBinarySymbols[op];
22
+ if (!kind)
23
+ throw new Error(`Symbol ${op} doesn't exist in typescript`);
24
+ if (bin.operatorToken.kind != kind)
25
+ return false;
26
+ }
27
+ else if (op) {
28
+ if (!op(bin.operatorToken))
29
+ return false;
30
+ }
31
+ if (rhs) {
32
+ if (!rhs(bin.right))
33
+ return false;
34
+ }
35
+ return true;
36
+ }
37
+ }
38
+ class Expression {
39
+ constructor(ast) {
40
+ this.ast = ast;
41
+ this.MATCH = new Searcher(this);
42
+ }
43
+ }
44
+ function FROM(node) {
45
+ return new Expression(node);
46
+ }
47
+ exports.FROM = FROM;
48
+ function HAS_IN_STATEMENT(node, cb) {
49
+ if (typeof node === "function") {
50
+ cb = node;
51
+ node = undefined;
52
+ }
53
+ if (node) {
54
+ let result = false;
55
+ let context = Crawler_1.Crawler.getContext();
56
+ let search = (node) => {
57
+ if (cb(node)) {
58
+ result = true;
59
+ return node;
60
+ }
61
+ if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassExpression(node)
62
+ || ts.isFunctionExpression(node)) {
63
+ return node;
64
+ }
65
+ return ts.visitEachChild(node, search, context);
66
+ };
67
+ ts.visitEachChild(node, search, context);
68
+ return result;
69
+ }
70
+ else {
71
+ return (arg) => HAS_IN_STATEMENT(arg, cb);
72
+ }
73
+ }
74
+ exports.HAS_IN_STATEMENT = HAS_IN_STATEMENT;
75
+ function FIND_IN_STATEMENT(node, cb) {
76
+ if (typeof node === "function") {
77
+ cb = node;
78
+ node = undefined;
79
+ }
80
+ if (node) {
81
+ let result = null;
82
+ let context = Crawler_1.Crawler.getContext();
83
+ let search = (node) => {
84
+ if (cb(node)) {
85
+ result = node;
86
+ return node;
87
+ }
88
+ if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassExpression(node)
89
+ || ts.isFunctionExpression(node)) {
90
+ return node;
91
+ }
92
+ return ts.visitEachChild(node, search, context);
93
+ };
94
+ ts.visitEachChild(node, search, context);
95
+ return result;
96
+ }
97
+ else {
98
+ return (arg) => FIND_IN_STATEMENT(arg, cb);
99
+ }
100
+ }
101
+ exports.FIND_IN_STATEMENT = FIND_IN_STATEMENT;
102
+ function HAS_ID_IN_STATEMENT(node, id) {
103
+ if (typeof node === "string" || ts.isIdentifier(node)) {
104
+ id = typeof node === "string" ? node : node.text;
105
+ node = undefined;
106
+ }
107
+ let search = (node) => {
108
+ return ts.isIdentifier(node) && node.text == id;
109
+ };
110
+ if (node) {
111
+ return HAS_IN_STATEMENT(node, search);
112
+ }
113
+ return HAS_IN_STATEMENT(search);
114
+ }
115
+ exports.HAS_ID_IN_STATEMENT = HAS_ID_IN_STATEMENT;
116
+ //# sourceMappingURL=ASTSearcher.js.map
@@ -0,0 +1,10 @@
1
+ import * as ts from "typescript";
2
+ export declare function ENTER(node: ts.Node): () => Generator<undefined, void, unknown>;
3
+ export declare function EXIT(): void;
4
+ export declare function SKIP(): void;
5
+ export declare function ITER_PROPERTIES(): void;
6
+ export declare function ITER_BLOCKS(): void;
7
+ export declare function ITER_EXPRESSIONS(): void;
8
+ export declare function REPLACE(): void;
9
+ export declare function NEXT(): void;
10
+ //# sourceMappingURL=ASTTraverser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTTraverser.d.ts","sourceRoot":"","sources":["ASTTraverser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,wBAAgB,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,6CAKlC;AAED,wBAAgB,IAAI,SAEnB;AAED,wBAAgB,IAAI,SAEnB;AAED,wBAAgB,eAAe,SAE9B;AAED,wBAAgB,WAAW,SAE1B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBAAgB,OAAO,SAEtB;AAED,wBAAgB,IAAI,SAEnB"}