@bikky/compiler 0.0.45 → 0.0.47

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 (64) hide show
  1. package/.idea/Compiler.iml +12 -0
  2. package/.idea/encodings.xml +4 -0
  3. package/.idea/modules.xml +8 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/.idea/watcherTasks.xml +8 -0
  6. package/Execution/generate.mjs +2 -1
  7. package/Execution/generate.mjs.map +1 -1
  8. package/Execution/generate.mts +2 -1
  9. package/Libraries/BiscuitLibraries.d.mts +1 -0
  10. package/Libraries/BiscuitLibraries.d.mts.map +1 -1
  11. package/Libraries/BiscuitLibraries.mjs +3 -0
  12. package/Libraries/BiscuitLibraries.mjs.map +1 -1
  13. package/Libraries/BiscuitLibraries.mts +4 -1
  14. package/Libraries/DelayLib.d.mts +2 -0
  15. package/Libraries/DelayLib.d.mts.map +1 -0
  16. package/Libraries/DelayLib.mjs +32 -0
  17. package/Libraries/DelayLib.mjs.map +1 -0
  18. package/Libraries/DelayLib.mts +37 -0
  19. package/Libraries/MixinCode.mjs.map +1 -1
  20. package/Libraries/MixinCode.mts +1 -1
  21. package/Source/ASTBuilder.d.ts +21 -10
  22. package/Source/ASTBuilder.d.ts.map +1 -1
  23. package/Source/ASTBuilder.js +148 -43
  24. package/Source/ASTHelper.d.ts +1 -1
  25. package/Source/ASTHelper.d.ts.map +1 -1
  26. package/Source/ASTHelper.js +1 -2
  27. package/Source/ASTInterface/Class.d.ts +23 -13
  28. package/Source/ASTInterface/Class.d.ts.map +1 -1
  29. package/Source/ASTInterface/Class.js +84 -16
  30. package/Source/ASTInterface/Crawler.d.ts +14 -0
  31. package/Source/ASTInterface/Crawler.d.ts.map +1 -1
  32. package/Source/ASTInterface/Crawler.js +31 -4
  33. package/Source/ASTSearcher.js +5 -5
  34. package/Transformers/DelayTransformer.d.ts +2 -0
  35. package/Transformers/DelayTransformer.d.ts.map +1 -0
  36. package/Transformers/DelayTransformer.js +34 -0
  37. package/Transformers/MacroTransformer.js +3 -3
  38. package/Transformers/{SuperTransform.d.ts → Main.d.ts} +5 -3
  39. package/Transformers/Main.d.ts.map +1 -0
  40. package/Transformers/Main.js +17 -0
  41. package/Transformers/MixinTransformer.d.ts +1 -2
  42. package/Transformers/MixinTransformer.d.ts.map +1 -1
  43. package/Transformers/MixinTransformer.js +20 -28
  44. package/Transformers/SuperTransformer.js +4 -4
  45. package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
  46. package/package.json +3 -3
  47. package/tsconfig.build.libs.json +2 -1
  48. package/tsconfig.build.libs.tsbuildinfo +1 -1
  49. package/tsconfig.build.src.json +2 -1
  50. package/tsconfig.build.src.tsbuildinfo +1 -1
  51. package/tsconfig.json +2 -1
  52. package/tsconfig.tsbuildinfo +1 -1
  53. package/{vitest.config.d.ts → vitest.config.d.mts} +1 -1
  54. package/vitest.config.d.mts.map +1 -0
  55. package/{vitest.config.js → vitest.config.mjs} +3 -5
  56. package/vitest.config.mjs.map +1 -0
  57. package/vitest.config.mts +21 -0
  58. package/Transformers/CompilerInsertions.d.ts +0 -1
  59. package/Transformers/CompilerInsertions.d.ts.map +0 -1
  60. package/Transformers/CompilerInsertions.js +0 -24
  61. package/Transformers/Macros.d.ts +0 -3
  62. package/Transformers/Macros.d.ts.map +0 -1
  63. package/Transformers/SuperTransform.d.ts.map +0 -1
  64. package/vitest.config.d.ts.map +0 -1
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
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.PROP = exports.LET = exports.VAR = exports.EXP = exports.Expression = exports.asAST = void 0;
3
+ exports.STATEMENT = exports.COMMENT = exports.RETURN = exports.CONSTRUCTOR = exports.CLASS = exports.THROW = exports.NEW_ERROR = exports.NEW = exports.IF = exports.LITERAL = exports.PARAM_DECL = exports.ID = exports.TYPEOF = exports.LAMBDA_DECL = exports.FUNCTION_DECL = exports.DOT_BIND = exports.DOT_CALL = exports.FUNCTION_EXEC = exports.THIS = exports.SUPER = exports.NOT = exports.PROP = exports.LET = exports.VAR = exports.EXPR = exports.Expression = exports.asAST = void 0;
4
4
  const ts = require("typescript");
5
5
  const Tokens_1 = require("./ASTInterface/Tokens");
6
- const Crawler_1 = require("./ASTInterface/Crawler");
6
+ const Crawler_js_1 = require("./ASTInterface/Crawler.js");
7
+ const Class_js_1 = require("./ASTInterface/Class.js");
7
8
  `EXP(SUPER().ACCESS(Name)).OP(!==, "undefined")`;
8
9
  function asAST(item) {
9
10
  if (typeof item === "string")
10
11
  return ID(item).toAST();
11
- if (item instanceof Expression || item instanceof Statement)
12
+ if (item instanceof Expression)
12
13
  return item.toAST();
13
14
  return item;
14
15
  }
@@ -28,12 +29,12 @@ class Expression {
28
29
  DOT(other) {
29
30
  if (!this.ast)
30
31
  throw new Error("Can't dot access undefined.");
31
- return new Expression(Crawler_1.Crawler.getContext().factory.createPropertyAccessExpression(this.getExpression(), asAST(other)));
32
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createPropertyAccessExpression(this.getExpression(), asAST(other)));
32
33
  }
33
34
  LOOKUP(other) {
34
35
  if (!this.ast)
35
36
  throw new Error("Can't [] access undefined.");
36
- return new Expression(Crawler_1.Crawler.getContext().factory.createElementAccessExpression(this.getExpression(), typeof other === "number" ? other : asAST(other)));
37
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createElementAccessExpression(this.getExpression(), typeof other === "number" ? other : asAST(other)));
37
38
  }
38
39
  OP(op, other) {
39
40
  other = asAST(other);
@@ -41,18 +42,18 @@ class Expression {
41
42
  throw new Error("Can't use nothing as lhs of operator expression..");
42
43
  if (op in Tokens_1.ComparisonOperators) {
43
44
  let opType = Tokens_1.ComparisonOperators[op];
44
- return new Expression(Crawler_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), opType, other));
45
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), opType, other));
45
46
  }
46
47
  if (op in Tokens_1.LogicalOperators) {
47
48
  switch (op) {
48
49
  case "??":
49
- return new Expression(Crawler_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), ts.SyntaxKind.QuestionQuestionToken, other));
50
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), ts.SyntaxKind.QuestionQuestionToken, other));
50
51
  case "||":
51
- return new Expression(Crawler_1.Crawler.getContext().factory.createLogicalOr(this.getExpression(), other));
52
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createLogicalOr(this.getExpression(), other));
52
53
  case "&&":
53
- return new Expression(Crawler_1.Crawler.getContext().factory.createLogicalAnd(this.getExpression(), other));
54
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createLogicalAnd(this.getExpression(), other));
54
55
  case "!":
55
- return new Expression(Crawler_1.Crawler.getContext().factory.createLogicalNot(this.getExpression()));
56
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createLogicalNot(this.getExpression()));
56
57
  }
57
58
  }
58
59
  return this;
@@ -61,13 +62,23 @@ class Expression {
61
62
  * If (not inline).
62
63
  */
63
64
  IF(then, otherwise) {
64
- return new Expression(Crawler_1.Crawler.getContext().factory.createIfStatement(this.getExpression(), asAST(then), otherwise && asAST(otherwise)));
65
+ if (then instanceof Statement)
66
+ then = then.toAST();
67
+ if (Array.isArray(then)) {
68
+ then = Crawler_js_1.Crawler.getContext().factory.createBlock(then);
69
+ }
70
+ if (otherwise instanceof Statement)
71
+ otherwise = otherwise.toAST();
72
+ if (Array.isArray(otherwise)) {
73
+ otherwise = Crawler_js_1.Crawler.getContext().factory.createBlock(otherwise);
74
+ }
75
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createIfStatement(this.getExpression(), asAST(then), otherwise && asAST(otherwise)));
65
76
  }
66
77
  /**
67
78
  * If inline.
68
79
  */
69
80
  IFI(then, otherwise) {
70
- return new Expression(Crawler_1.Crawler.getContext().factory.createConditionalExpression(this.getExpression(), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createParenthesizedExpression(asAST(then)), ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createParenthesizedExpression(asAST(otherwise))));
81
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createConditionalExpression(this.getExpression(), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createParenthesizedExpression(asAST(then)), ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createParenthesizedExpression(asAST(otherwise))));
71
82
  }
72
83
  ASGN(op, other) {
73
84
  other = asAST(other);
@@ -80,16 +91,16 @@ class Expression {
80
91
  }
81
92
  switch (op) {
82
93
  case "=":
83
- return new Expression(Crawler_1.Crawler.getContext().factory.createAssignment(this.getExpression(), other));
94
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createAssignment(this.getExpression(), other));
84
95
  break;
85
96
  default:
86
- return new Expression(Crawler_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), Tokens_1.AssignmentSymbols[op], other));
97
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createBinaryExpression(this.getExpression(), Tokens_1.AssignmentSymbols[op], other));
87
98
  break;
88
99
  }
89
100
  return this;
90
101
  }
91
102
  CALL(...args) {
92
- return new Expression(Crawler_1.Crawler.getContext().factory.createCallExpression(this.getExpression(), undefined, args.map((e) => asAST(e))));
103
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createCallExpression(this.getExpression(), undefined, args.map((e) => asAST(e))));
93
104
  }
94
105
  toAST() {
95
106
  return this.ast;
@@ -97,12 +108,12 @@ class Expression {
97
108
  ;
98
109
  }
99
110
  exports.Expression = Expression;
100
- function EXP(exp) {
111
+ function EXPR(exp) {
101
112
  if (exp instanceof Expression)
102
113
  return exp;
103
114
  return new Expression(exp);
104
115
  }
105
- exports.EXP = EXP;
116
+ exports.EXPR = EXPR;
106
117
  function isValidVarInitialiser(val) {
107
118
  if (!val)
108
119
  return true;
@@ -141,68 +152,162 @@ function NOT(exp) {
141
152
  exp = new Expression(exp);
142
153
  if (ts.isVariableStatement(exp.ast))
143
154
  throw new Error("Cannot NOT a variable declaration.");
144
- exp.ast = Crawler_1.Crawler.getContext().factory.createLogicalNot(exp.ast);
155
+ exp.ast = Crawler_js_1.Crawler.getContext().factory.createLogicalNot(exp.ast);
145
156
  return exp;
146
157
  }
147
158
  exports.NOT = NOT;
148
159
  function SUPER() {
149
- return new Expression(Crawler_1.Crawler.getContext().factory.createSuper());
160
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createSuper());
150
161
  }
151
162
  exports.SUPER = SUPER;
152
163
  function THIS() {
153
- return new Expression(Crawler_1.Crawler.getContext().factory.createThis());
164
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createThis());
154
165
  }
155
166
  exports.THIS = THIS;
156
167
  ///Call a function.
157
- function CALL(name, ...args) {
158
- return new Expression(Crawler_1.Crawler.getContext().factory.createCallExpression(asAST(name), undefined, args.map((e) => asAST(e))));
159
- }
160
- exports.CALL = CALL;
161
- ///Call parent.method.call
162
- function METHOD_CALL(parent, name, ...args) {
163
- if (!(parent instanceof Expression))
164
- parent = new Expression(parent);
165
- return CALL(parent.DOT(name).DOT(ID("call")), ...args);
166
- }
167
- exports.METHOD_CALL = METHOD_CALL;
168
- function FUNC_CALL(name, ...args) {
168
+ function FUNCTION_EXEC(name, ...args) {
169
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createCallExpression(asAST(name), undefined, args.map((e) => asAST(e))));
170
+ }
171
+ exports.FUNCTION_EXEC = FUNCTION_EXEC;
172
+ // export function FUNCTION_CALL(name: AnyExpr, ...args: AnyExpr[]): Expression {
173
+ // if (!(name instanceof Expression)) name = new Expression(name);
174
+ // return CALL(name.DOT(ID("call")), ...args)
175
+ // }
176
+ function DOT_CALL(name, ...args) {
169
177
  if (!(name instanceof Expression))
170
178
  name = new Expression(name);
171
- return CALL(name.DOT(ID("call")), ...args);
179
+ return FUNCTION_EXEC(name.DOT(ID("call")), ...args);
172
180
  }
173
- exports.FUNC_CALL = FUNC_CALL;
174
- function FUNC_BIND(name, newThis) {
181
+ exports.DOT_CALL = DOT_CALL;
182
+ function DOT_BIND(name, newThis, ...args) {
175
183
  if (!(name instanceof Expression))
176
184
  name = new Expression(name);
177
- return FUNC_CALL(name, ID("bind"), newThis);
185
+ return FUNCTION_EXEC(name, ID("bind"), newThis, ...args);
186
+ }
187
+ exports.DOT_BIND = DOT_BIND;
188
+ function FUNCTION_DECL(name, parameters, contents) {
189
+ let factory = Crawler_js_1.Crawler.getContext().factory;
190
+ return new Expression(factory.createFunctionExpression(undefined, undefined, name, undefined, parameters, undefined, factory.createBlock(contents)));
178
191
  }
179
- exports.FUNC_BIND = FUNC_BIND;
192
+ exports.FUNCTION_DECL = FUNCTION_DECL;
193
+ function LAMBDA_DECL(parameters, contents, inline = false) {
194
+ let factory = Crawler_js_1.Crawler.getContext().factory;
195
+ if (contents instanceof Statement)
196
+ contents = contents.toAST();
197
+ if (!Array.isArray(contents)) {
198
+ contents = [contents];
199
+ }
200
+ return new Expression(factory.createArrowFunction(undefined, undefined, parameters, undefined, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createBlock(contents, !inline)));
201
+ }
202
+ exports.LAMBDA_DECL = LAMBDA_DECL;
180
203
  function TYPEOF(other) {
181
- return new Expression(Crawler_1.Crawler.getContext().factory.createTypeOfExpression(other));
204
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createTypeOfExpression(other));
182
205
  }
183
206
  exports.TYPEOF = TYPEOF;
184
207
  function ID(name) {
185
- return new Expression(Crawler_1.Crawler.getContext().factory.createIdentifier(name));
208
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createIdentifier(name));
186
209
  }
187
210
  exports.ID = ID;
211
+ function PARAM_DECL(name, type) {
212
+ return Crawler_js_1.Crawler.getContext().factory.createParameterDeclaration(undefined, undefined, name, undefined, type ? asAST(type) : undefined);
213
+ }
214
+ exports.PARAM_DECL = PARAM_DECL;
188
215
  function LITERAL(name) {
189
- return new Expression(Crawler_1.Crawler.getContext().factory.createStringLiteral(name));
216
+ return new Expression(Crawler_js_1.Crawler.getContext().factory.createStringLiteral(name));
190
217
  }
191
218
  exports.LITERAL = LITERAL;
192
219
  function IF(ifs, then, elses) {
193
- return Crawler_1.Crawler.getContext().factory.createIfStatement(asAST(ifs), asAST(then), elses ? asAST(elses) : elses);
220
+ if (then instanceof Statement)
221
+ then = then.toAST();
222
+ if (Array.isArray(then)) {
223
+ then = Crawler_js_1.Crawler.getContext().factory.createBlock(then);
224
+ }
225
+ if (elses instanceof Statement)
226
+ elses = elses.toAST();
227
+ if (Array.isArray(elses)) {
228
+ elses = Crawler_js_1.Crawler.getContext().factory.createBlock(elses);
229
+ }
230
+ return Crawler_js_1.Crawler.getContext().factory.createIfStatement(asAST(ifs), asAST(then), elses ? asAST(elses) : elses);
194
231
  }
195
232
  exports.IF = IF;
233
+ function NEW(id, args, types) {
234
+ return Crawler_js_1.Crawler.getContext().factory.createNewExpression(asAST(id), undefined, args.map((e) => asAST(e)));
235
+ }
236
+ exports.NEW = NEW;
237
+ function NEW_ERROR(arg) {
238
+ if (typeof arg === "string") {
239
+ arg = LITERAL(arg);
240
+ }
241
+ return NEW(ID("Error"), [arg]);
242
+ }
243
+ exports.NEW_ERROR = NEW_ERROR;
244
+ function THROW(expr) {
245
+ return Crawler_js_1.Crawler.getContext().factory.createThrowStatement(asAST(expr));
246
+ }
247
+ exports.THROW = THROW;
248
+ function CLASS(name) {
249
+ return new Class_js_1.Class(asAST(name));
250
+ }
251
+ exports.CLASS = CLASS;
252
+ function CONSTRUCTOR(args, block) {
253
+ let exprBlock;
254
+ if (block) {
255
+ exprBlock = Crawler_js_1.Crawler.getContext().factory.createBlock(block.map((e) => asAST(e)));
256
+ }
257
+ return Crawler_js_1.Crawler.getContext().factory.createConstructorDeclaration(undefined, args, exprBlock);
258
+ }
259
+ exports.CONSTRUCTOR = CONSTRUCTOR;
260
+ function RETURN(expr) {
261
+ return Crawler_js_1.Crawler.getContext().factory.createReturnStatement(expr ? asAST(expr) : undefined);
262
+ }
263
+ exports.RETURN = RETURN;
264
+ function COMMENT(node, comment, beforeNode = true, newlineAfter = true) {
265
+ if (beforeNode) {
266
+ return ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, comment, newlineAfter);
267
+ }
268
+ else {
269
+ return ts.addSyntheticTrailingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, comment, newlineAfter);
270
+ }
271
+ }
272
+ exports.COMMENT = COMMENT;
196
273
  class Statement {
197
274
  constructor() {
198
275
  this.statements = [];
276
+ this.comments = [];
199
277
  }
200
278
  LINE(exp) {
201
279
  this.statements.push(exp);
280
+ return this;
281
+ }
282
+ COMMENT(comment, trailingNewLine = true) {
283
+ let type = "post";
284
+ if (this.statements.length == 0) {
285
+ type = "pre";
286
+ }
287
+ if (!this.comments[this.statements.length]) {
288
+ this.comments[this.statements.length] = [];
289
+ }
290
+ this.comments[this.statements.length].push((node) => {
291
+ if (type == "pre") {
292
+ return ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, comment, trailingNewLine);
293
+ }
294
+ else {
295
+ return ts.addSyntheticTrailingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, comment, trailingNewLine);
296
+ }
297
+ });
298
+ return this;
202
299
  }
203
300
  toAST() {
204
- let statements = this.statements.map((e) => Crawler_1.Crawler.getContext().factory.createExpressionStatement(asAST(e)));
205
- return Crawler_1.Crawler.getContext().factory.createBlock(statements);
301
+ let factory = Crawler_js_1.Crawler.getContext().factory;
302
+ return this.statements.map((e, i) => {
303
+ let node = asAST(e);
304
+ if (this.comments[i]) {
305
+ for (let comment of this.comments[i]) {
306
+ node = comment(node);
307
+ }
308
+ }
309
+ return factory.createExpressionStatement(node);
310
+ });
206
311
  }
207
312
  }
208
313
  function STATEMENT() {
@@ -1,5 +1,5 @@
1
1
  import * as ts from "typescript";
2
- import { Expression } from "./ASTBuilder.js";
2
+ import type { Expression } from "./ASTBuilder.js";
3
3
  export interface fromable {
4
4
  from: (param: any) => any;
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ASTHelper.d.ts","sourceRoot":"","sources":["ASTHelper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAS,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAC7B;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,UAK/D;AAED,qBAAa,eAAe;IACxB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC;gBAER,IAAI,EAAE,EAAE,CAAC,UAAU;IAI/B,OAAO;IAIP,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU;CAI7B;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACpD,SAAS,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAM;IAC/B,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;IAGtB,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU;IAK7B,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ;IAQjC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB,GAAG,EAAE,CAAC,IAAI;CAKnD;AAED,yBAAc,mBAAmB,CAAC;IAC9B,SAAgB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,mBAAmB,CAK1E;CACJ;AAED,qBAAa,mBAAoB,SAAQ,mBAAmB;gBAG5C,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CA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,UAAU,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAa/C,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAelD,UAAU;IAIV,UAAU;IAIV,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS;IAK7C,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,qBAAqB;IAmCxG,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB;CAgB3C;AAED,qBAAa,UAAU;IACnB,QAAQ,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;IACzB,UAAU,EAAE,EAAE,CAAC,SAAS,EAAE,CAAM;IAEhC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU;IAOlC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,SAAS;IASxD,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS;IAUrC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB;CAM3C;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAahE;AAED,yBAAc,OAAO,CAAC;IAGlB,SAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,UAEjE;IAED,SAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,UAM1E;CACJ"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Printer = exports.logError = exports.SourceFile = exports.ClassDeclaration = exports.AccessExpression = exports.PropertyDeclaration = exports.VariableDeclaration = exports.NamedExpression = exports.getNodeText = void 0;
4
4
  const ts = require("typescript");
5
- const ASTBuilder_js_1 = require("./ASTBuilder.js");
6
5
  const Crawler_js_1 = require("./ASTInterface/Crawler.js");
7
6
  function getNodeText(node, source) {
8
7
  if (node.pos > 0 && node.end < source.end) {
@@ -136,7 +135,7 @@ class ClassDeclaration {
136
135
  return getNodeText(id, this.sourceFile);
137
136
  }
138
137
  addMemberAtStart(member) {
139
- this.members.unshift((0, ASTBuilder_js_1.asAST)(member));
138
+ this.members.unshift("toAST" in member ? member.toAST() : member);
140
139
  return this;
141
140
  }
142
141
  addMember(member) {
@@ -1,33 +1,43 @@
1
1
  import * as ts from "typescript";
2
- import { NamedExpression } from "../ASTHelper";
2
+ import { NamedExpression } from "../ASTHelper.js";
3
3
  type APICallback<T, R = T> = (obj: T | null) => R | null;
4
4
  export declare class Decorator extends NamedExpression {
5
- base: ts.Decorator;
5
+ private base;
6
6
  constructor(base: ts.Decorator | ts.Identifier | string);
7
+ isCallExpression(): boolean;
8
+ numArguments(): number;
9
+ getArgument(index: number): ts.Expression | undefined;
7
10
  update(): ts.Decorator;
8
11
  }
9
- export declare class Class extends NamedExpression {
10
- base: ts.ClassDeclaration | ts.ClassExpression;
12
+ export declare class Class<T extends ts.ClassDeclaration | ts.ClassExpression = ts.ClassDeclaration | ts.ClassExpression> extends NamedExpression {
13
+ private base;
11
14
  modifiers: ts.Modifier[];
12
15
  decorators: Decorator[];
13
16
  extends: ts.HeritageClause | undefined;
14
17
  implements: ts.HeritageClause[];
15
18
  members: (ts.ClassElement)[];
16
19
  typeParams: ts.TypeParameterDeclaration[];
17
- constructor(base: ts.ClassDeclaration | ts.ClassExpression | string | ts.Identifier);
20
+ constructor(base: T | string | ts.Identifier);
21
+ isClassExpression(): this is Class<ts.ClassExpression>;
22
+ isClassDeclaration(): this is Class<ts.ClassDeclaration>;
18
23
  hasExtends(): boolean;
19
- setExtends(extend: ts.ExpressionWithTypeArguments): void;
24
+ EXTENDS(extend: ts.ExpressionWithTypeArguments): void;
20
25
  unshiftDecorator(...dec: Decorator[]): this;
21
26
  pushDecorator(...dec: Decorator[]): this;
22
- decorator(identifier: string | ts.Identifier, cb: APICallback<Decorator>): this;
23
- decorator(cb: APICallback<Decorator>): this;
27
+ DECORATOR(identifier: string | ts.Identifier, cb: APICallback<Decorator>): this;
28
+ DECORATOR(cb: APICallback<Decorator>): this;
24
29
  unshift(...members: ts.ClassElement[]): this;
25
30
  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
+ PROPERTY(identifier: string | ts.Identifier | ts.PropertyDeclaration, cb: APICallback<ts.PropertyDeclaration, ts.ClassElement>): this;
32
+ PROPERTY(cb: APICallback<ts.PropertyDeclaration, ts.ClassElement>): this;
33
+ METHOD(identifier: string | ts.Identifier | ts.MethodDeclaration, cb: APICallback<ts.MethodDeclaration, ts.ClassElement>): this;
34
+ METHOD(cb: APICallback<ts.MethodDeclaration, ts.ClassElement>): this;
35
+ CONSTRUCTOR(): this;
36
+ CONSTRUCTOR(cb: APICallback<ts.ConstructorDeclaration, ts.ClassElement>): this;
37
+ copyFrom(other: Class): this;
38
+ update(): T;
39
+ toClassExpression(): ts.ClassExpression;
40
+ toClassDeclaration(): ts.ClassDeclaration;
31
41
  }
32
42
  export declare namespace Class {
33
43
  function getModifiers(node: ts.ClassDeclaration | ts.ClassExpression): ts.Modifier[];
@@ -1 +1 @@
1
- {"version":3,"file":"Class.d.ts","sourceRoot":"","sources":["Class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAA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AC,gBAAgB,GAAG,EAAE,CAAC,eAAe,kBAE3E;IAID,SAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,QAE1E;CAqBJ"}
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Class = exports.Decorator = void 0;
4
4
  const ts = require("typescript");
5
- const ASTHelper_1 = require("../ASTHelper");
6
- const Crawler_1 = require("./Crawler");
7
- class Decorator extends ASTHelper_1.NamedExpression {
5
+ const ASTHelper_js_1 = require("../ASTHelper.js");
6
+ const Crawler_js_1 = require("./Crawler.js");
7
+ class Decorator extends ASTHelper_js_1.NamedExpression {
8
8
  constructor(base) {
9
9
  if (typeof base === "string")
10
10
  base = ts.factory.createIdentifier(base);
@@ -26,6 +26,15 @@ class Decorator extends ASTHelper_1.NamedExpression {
26
26
  super(name);
27
27
  this.base = base;
28
28
  }
29
+ isCallExpression() {
30
+ return ts.isCallExpression(this.base.expression);
31
+ }
32
+ numArguments() {
33
+ return this.isCallExpression() ? this.base.expression.arguments.length : 0;
34
+ }
35
+ getArgument(index) {
36
+ return this.isCallExpression() ? this.base.expression.arguments[index] : undefined;
37
+ }
29
38
  update() {
30
39
  if (ts.isCallExpression(this.base.expression)) {
31
40
  ts.factory.updateCallExpression(this.base.expression, this.name, this.base.expression.typeArguments, this.base.expression.arguments);
@@ -38,7 +47,7 @@ class Decorator extends ASTHelper_1.NamedExpression {
38
47
  }
39
48
  }
40
49
  exports.Decorator = Decorator;
41
- class Class extends ASTHelper_1.NamedExpression {
50
+ class Class extends ASTHelper_js_1.NamedExpression {
42
51
  constructor(base) {
43
52
  if (typeof base === "string")
44
53
  base = ts.factory.createIdentifier(base);
@@ -68,10 +77,16 @@ class Class extends ASTHelper_1.NamedExpression {
68
77
  this.base = ts.factory.createClassDeclaration(undefined, undefined, undefined, undefined, []);
69
78
  }
70
79
  }
80
+ isClassExpression() {
81
+ return ts.isClassExpression(this.base);
82
+ }
83
+ isClassDeclaration() {
84
+ return ts.isClassDeclaration(this.base);
85
+ }
71
86
  hasExtends() {
72
87
  return !!this.extends;
73
88
  }
74
- setExtends(extend) {
89
+ EXTENDS(extend) {
75
90
  this.extends = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [extend]);
76
91
  }
77
92
  unshiftDecorator(...dec) {
@@ -82,7 +97,7 @@ class Class extends ASTHelper_1.NamedExpression {
82
97
  this.decorators.push(...dec);
83
98
  return this;
84
99
  }
85
- decorator(identifier, cb) {
100
+ DECORATOR(identifier, cb) {
86
101
  let name;
87
102
  if (typeof identifier === "function") {
88
103
  cb = identifier;
@@ -124,7 +139,7 @@ class Class extends ASTHelper_1.NamedExpression {
124
139
  this.members.push(...members);
125
140
  return this;
126
141
  }
127
- property(identifier, cb) {
142
+ PROPERTY(identifier, cb) {
128
143
  let name;
129
144
  if (typeof identifier === "function") {
130
145
  cb = identifier;
@@ -176,7 +191,7 @@ class Class extends ASTHelper_1.NamedExpression {
176
191
  }
177
192
  return this;
178
193
  }
179
- method(identifier, cb) {
194
+ METHOD(identifier, cb) {
180
195
  let name;
181
196
  if (typeof identifier === "function") {
182
197
  cb = identifier;
@@ -215,14 +230,61 @@ class Class extends ASTHelper_1.NamedExpression {
215
230
  }
216
231
  return this;
217
232
  }
233
+ CONSTRUCTOR(cb) {
234
+ let didWork = false;
235
+ for (let i = 0; i < this.members.length; i++) {
236
+ let property = this.members[i];
237
+ if (!ts.isConstructorDeclaration(property)) {
238
+ continue;
239
+ }
240
+ let newProp = cb(property);
241
+ didWork = true;
242
+ if (newProp) {
243
+ this.members.splice(i, 1, newProp);
244
+ }
245
+ else {
246
+ this.members.splice(i, 1);
247
+ i--;
248
+ }
249
+ }
250
+ if (!didWork) {
251
+ let newDec = cb(null);
252
+ if (newDec) {
253
+ this.members.push(newDec);
254
+ }
255
+ }
256
+ return this;
257
+ }
258
+ copyFrom(other) {
259
+ this.modifiers = [...other.modifiers];
260
+ this.decorators = [...other.decorators];
261
+ this.extends = other.extends;
262
+ this.implements = [...other.implements];
263
+ this.members = [...other.members];
264
+ this.typeParams = [...other.typeParams];
265
+ return this;
266
+ }
218
267
  update() {
268
+ let factory = Crawler_js_1.Crawler.getContext().factory;
219
269
  if (ts.isClassDeclaration(this.base)) {
220
- 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);
270
+ return factory.updateClassDeclaration(this.base, [...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
221
271
  }
222
272
  else {
223
- 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);
273
+ return factory.updateClassExpression(this.base, [...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
224
274
  }
225
275
  }
276
+ toClassExpression() {
277
+ if (ts.isClassExpression(this.base)) {
278
+ return this.base;
279
+ }
280
+ return Crawler_js_1.Crawler.getContext().factory.createClassExpression([...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
281
+ }
282
+ toClassDeclaration() {
283
+ if (ts.isClassDeclaration(this.base)) {
284
+ return this.base;
285
+ }
286
+ return Crawler_js_1.Crawler.getContext().factory.createClassDeclaration([...this.modifiers, ...this.decorators.map((e) => e.update())], this.name, this.typeParams, [...(this.extends ? [this.extends] : []), ...this.implements], this.members);
287
+ }
226
288
  }
227
289
  exports.Class = Class;
228
290
  (function (Class) {
@@ -241,18 +303,24 @@ exports.Class = Class;
241
303
  foos.push(repl);
242
304
  }
243
305
  Class.onClass = onClass;
244
- Crawler_1.Crawler.Register((node) => {
306
+ Crawler_js_1.Crawler.Register((node) => {
245
307
  return ts.isClassExpression(node) || ts.isClassDeclaration(node);
246
308
  }, (node) => {
247
- let val = new Class(node);
309
+ let val = node;
248
310
  for (let foo of foos) {
249
- let result = foo(val);
250
- if (!(result instanceof Class)) {
311
+ let _class = new Class(node);
312
+ let result = foo(_class);
313
+ if (Array.isArray(result)) {
251
314
  return result;
252
315
  }
253
- val = result;
316
+ if (result instanceof Class) {
317
+ val = result.update();
318
+ }
319
+ else {
320
+ val = result;
321
+ }
254
322
  }
255
- return val.update();
323
+ return val;
256
324
  });
257
325
  })(Class || (exports.Class = Class = {}));
258
326
  //# sourceMappingURL=Class.js.map
@@ -1,5 +1,19 @@
1
1
  import * as ts from "typescript";
2
2
  export declare namespace Crawler {
3
+ function SetProgram(tsProgram: ts.Program): void;
4
+ function SetFile(tsFile: ts.SourceFile): void;
5
+ function OnFile(callback: (file: {
6
+ ts: ts.SourceFile;
7
+ data: any;
8
+ }) => void): void;
9
+ function GetProgram(): {
10
+ ts: ts.Program;
11
+ data: any;
12
+ };
13
+ function GetFile(): {
14
+ ts: ts.SourceFile;
15
+ data: any;
16
+ };
3
17
  function Register(checker: (node: ts.Node) => boolean, replacer: (node: ts.Node) => (ts.Node | ts.Node[])): void;
4
18
  function setContext(newContext: ts.TransformationContext): void;
5
19
  function getContext(): ts.TransformationContext;
@@ -1 +1 @@
1
- {"version":3,"file":"Crawler.d.ts","sourceRoot":"","sources":["Crawler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,yBAAc,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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