greybel-interpreter 1.4.4 → 1.4.6

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 (93) hide show
  1. package/dist/context.d.ts +3 -2
  2. package/dist/context.js +113 -190
  3. package/dist/cps.js +135 -188
  4. package/dist/handler/error.js +6 -29
  5. package/dist/handler/output.js +15 -38
  6. package/dist/handler/resource.js +16 -39
  7. package/dist/handler-container.js +6 -8
  8. package/dist/index.d.ts +4 -3
  9. package/dist/index.js +10 -9
  10. package/dist/interpreter.d.ts +5 -4
  11. package/dist/interpreter.js +109 -203
  12. package/dist/operations/assign.d.ts +1 -1
  13. package/dist/operations/assign.js +28 -93
  14. package/dist/operations/block.d.ts +1 -1
  15. package/dist/operations/block.js +33 -89
  16. package/dist/operations/break.d.ts +1 -1
  17. package/dist/operations/break.js +11 -29
  18. package/dist/operations/call.d.ts +1 -1
  19. package/dist/operations/call.js +31 -106
  20. package/dist/operations/chunk.d.ts +1 -1
  21. package/dist/operations/chunk.js +15 -67
  22. package/dist/operations/continue.d.ts +1 -1
  23. package/dist/operations/continue.js +11 -29
  24. package/dist/operations/debugger-statement.d.ts +1 -1
  25. package/dist/operations/debugger-statement.js +11 -29
  26. package/dist/operations/evaluate.d.ts +1 -1
  27. package/dist/operations/evaluate.js +143 -247
  28. package/dist/operations/for.d.ts +1 -1
  29. package/dist/operations/for.js +62 -133
  30. package/dist/operations/function-reference.d.ts +1 -1
  31. package/dist/operations/function-reference.js +25 -84
  32. package/dist/operations/function.d.ts +1 -1
  33. package/dist/operations/function.js +49 -177
  34. package/dist/operations/if-statement.d.ts +1 -1
  35. package/dist/operations/if-statement.js +58 -154
  36. package/dist/operations/import.d.ts +1 -1
  37. package/dist/operations/import.js +35 -97
  38. package/dist/operations/include.d.ts +1 -1
  39. package/dist/operations/include.js +19 -73
  40. package/dist/operations/list.d.ts +1 -1
  41. package/dist/operations/list.js +24 -93
  42. package/dist/operations/literal.d.ts +1 -1
  43. package/dist/operations/literal.js +15 -33
  44. package/dist/operations/map.d.ts +1 -1
  45. package/dist/operations/map.js +26 -153
  46. package/dist/operations/negated-binary.d.ts +1 -1
  47. package/dist/operations/negated-binary.js +24 -91
  48. package/dist/operations/new-instance.d.ts +1 -1
  49. package/dist/operations/new-instance.js +21 -82
  50. package/dist/operations/noop.d.ts +1 -1
  51. package/dist/operations/noop.js +10 -27
  52. package/dist/operations/not.d.ts +1 -1
  53. package/dist/operations/not.js +17 -78
  54. package/dist/operations/operation.d.ts +2 -2
  55. package/dist/operations/operation.js +3 -5
  56. package/dist/operations/reference.d.ts +1 -1
  57. package/dist/operations/reference.js +10 -28
  58. package/dist/operations/resolve.d.ts +1 -1
  59. package/dist/operations/resolve.js +161 -281
  60. package/dist/operations/return.d.ts +1 -1
  61. package/dist/operations/return.js +27 -89
  62. package/dist/operations/while.d.ts +1 -1
  63. package/dist/operations/while.js +45 -116
  64. package/dist/types/base.d.ts +9 -0
  65. package/dist/types/base.js +5 -0
  66. package/dist/types/boolean.d.ts +3 -1
  67. package/dist/types/boolean.js +24 -36
  68. package/dist/types/default.d.ts +6 -9
  69. package/dist/types/default.js +11 -17
  70. package/dist/types/function.d.ts +1 -1
  71. package/dist/types/function.js +60 -130
  72. package/dist/types/interface.d.ts +2 -1
  73. package/dist/types/interface.js +44 -64
  74. package/dist/types/list.d.ts +4 -6
  75. package/dist/types/list.js +77 -128
  76. package/dist/types/map.d.ts +11 -15
  77. package/dist/types/map.js +101 -267
  78. package/dist/types/nil.d.ts +2 -1
  79. package/dist/types/nil.js +23 -36
  80. package/dist/types/number.d.ts +16 -2
  81. package/dist/types/number.js +60 -37
  82. package/dist/types/string.d.ts +4 -6
  83. package/dist/types/string.js +66 -90
  84. package/dist/types/{generics.d.ts → with-intrinsics.d.ts} +6 -9
  85. package/dist/types/with-intrinsics.js +19 -0
  86. package/dist/utils/deep-equal.js +9 -34
  87. package/dist/utils/object-value.d.ts +7 -0
  88. package/dist/utils/object-value.js +42 -0
  89. package/dist/utils/path.js +16 -43
  90. package/package.json +3 -3
  91. package/dist/intrinsics-container.d.ts +0 -7
  92. package/dist/intrinsics-container.js +0 -19
  93. package/dist/types/generics.js +0 -40
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,114 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
54
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
13
  };
56
14
  Object.defineProperty(exports, "__esModule", { value: true });
57
- var context_1 = require("../context");
58
- var default_1 = __importDefault(require("../types/default"));
59
- var block_1 = __importDefault(require("./block"));
60
- var operation_1 = __importDefault(require("./operation"));
61
- var While = /** @class */ (function (_super) {
62
- __extends(While, _super);
63
- function While(item, target) {
64
- var _this = _super.call(this, null, target) || this;
65
- _this.item = item;
66
- return _this;
15
+ const context_1 = require("../context");
16
+ const default_1 = __importDefault(require("../types/default"));
17
+ const block_1 = __importDefault(require("./block"));
18
+ const operation_1 = __importDefault(require("./operation"));
19
+ class While extends operation_1.default {
20
+ constructor(item, target) {
21
+ super(null, target);
22
+ this.item = item;
67
23
  }
68
- While.prototype.build = function (visit) {
69
- return __awaiter(this, void 0, void 0, function () {
70
- var stack, _a;
71
- return __generator(this, function (_b) {
72
- switch (_b.label) {
73
- case 0: return [4 /*yield*/, Promise.all(this.item.body.map(function (child) { return visit(child); }))];
74
- case 1:
75
- stack = _b.sent();
76
- this.block = new block_1.default(stack);
77
- _a = this;
78
- return [4 /*yield*/, visit(this.item.condition)];
79
- case 2:
80
- _a.condition = _b.sent();
81
- return [2 /*return*/, this];
82
- }
83
- });
24
+ build(visit) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
27
+ this.block = new block_1.default(stack);
28
+ this.condition = yield visit(this.item.condition);
29
+ return this;
84
30
  });
85
- };
86
- While.prototype.handle = function (ctx) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var whileCtx, loopState;
89
- var _this = this;
90
- return __generator(this, function (_a) {
91
- whileCtx = ctx.fork({
92
- type: context_1.ContextType.Loop,
93
- state: context_1.ContextState.Temporary
31
+ }
32
+ handle(ctx) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const whileCtx = ctx.fork({
35
+ type: context_1.ContextType.Loop,
36
+ state: context_1.ContextState.Temporary
37
+ });
38
+ const loopState = new context_1.LoopState();
39
+ whileCtx.loopState = loopState;
40
+ return new Promise((resolve, reject) => {
41
+ const iteration = () => __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ const conditionResult = yield this.condition.handle(whileCtx);
44
+ if (!conditionResult.toTruthy()) {
45
+ resolve(default_1.default.Void);
46
+ return;
47
+ }
48
+ loopState.isContinue = false;
49
+ yield this.block.handle(whileCtx);
50
+ if (loopState.isBreak || ctx.isExit()) {
51
+ resolve(default_1.default.Void);
52
+ return;
53
+ }
54
+ process.nextTick(iteration);
55
+ }
56
+ catch (err) {
57
+ reject(err);
58
+ }
94
59
  });
95
- loopState = new context_1.LoopState();
96
- whileCtx.loopState = loopState;
97
- return [2 /*return*/, new Promise(function (resolve, reject) {
98
- var iteration = function () { return __awaiter(_this, void 0, void 0, function () {
99
- var conditionResult, err_1;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- _a.trys.push([0, 3, , 4]);
104
- return [4 /*yield*/, this.condition.handle(whileCtx)];
105
- case 1:
106
- conditionResult = _a.sent();
107
- if (!conditionResult.toTruthy()) {
108
- resolve(default_1.default.Void);
109
- return [2 /*return*/];
110
- }
111
- loopState.isContinue = false;
112
- return [4 /*yield*/, this.block.handle(whileCtx)];
113
- case 2:
114
- _a.sent();
115
- if (loopState.isBreak || ctx.isExit()) {
116
- resolve(default_1.default.Void);
117
- return [2 /*return*/];
118
- }
119
- process.nextTick(iteration);
120
- return [3 /*break*/, 4];
121
- case 3:
122
- err_1 = _a.sent();
123
- reject(err_1);
124
- return [3 /*break*/, 4];
125
- case 4: return [2 /*return*/];
126
- }
127
- });
128
- }); };
129
- iteration();
130
- })];
60
+ iteration();
131
61
  });
132
62
  });
133
- };
134
- return While;
135
- }(operation_1.default));
63
+ }
64
+ }
136
65
  exports.default = While;
@@ -0,0 +1,9 @@
1
+ export default abstract class CustomValue {
2
+ abstract value: any;
3
+ abstract getCustomType(): string;
4
+ abstract toNumber(): number;
5
+ abstract toInt(): number;
6
+ abstract toString(): string;
7
+ abstract toTruthy(): boolean;
8
+ abstract fork(): CustomValue;
9
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CustomValue {
4
+ }
5
+ exports.default = CustomValue;
@@ -1,4 +1,4 @@
1
- import { CustomValue } from './generics';
1
+ import CustomValue from './base';
2
2
  export default class CustomBoolean extends CustomValue {
3
3
  readonly value: boolean;
4
4
  constructor(value: boolean);
@@ -9,3 +9,5 @@ export default class CustomBoolean extends CustomValue {
9
9
  toInt(): number;
10
10
  toTruthy(): boolean;
11
11
  }
12
+ export declare const DefaultTrue: CustomBoolean;
13
+ export declare const DefaultFalse: CustomBoolean;
@@ -1,46 +1,34 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
17
5
  Object.defineProperty(exports, "__esModule", { value: true });
18
- var generics_1 = require("./generics");
19
- var CustomBoolean = /** @class */ (function (_super) {
20
- __extends(CustomBoolean, _super);
21
- function CustomBoolean(value) {
22
- var _this = _super.call(this) || this;
23
- _this.value = value;
24
- return _this;
6
+ exports.DefaultFalse = exports.DefaultTrue = void 0;
7
+ const base_1 = __importDefault(require("./base"));
8
+ class CustomBoolean extends base_1.default {
9
+ constructor(value) {
10
+ super();
11
+ this.value = value;
25
12
  }
26
- CustomBoolean.prototype.getCustomType = function () {
13
+ getCustomType() {
27
14
  return 'boolean';
28
- };
29
- CustomBoolean.prototype.toString = function () {
15
+ }
16
+ toString() {
30
17
  return this.value.toString();
31
- };
32
- CustomBoolean.prototype.fork = function () {
18
+ }
19
+ fork() {
33
20
  return new CustomBoolean(this.value);
34
- };
35
- CustomBoolean.prototype.toNumber = function () {
21
+ }
22
+ toNumber() {
36
23
  return this.value ? 1.0 : 0.0;
37
- };
38
- CustomBoolean.prototype.toInt = function () {
24
+ }
25
+ toInt() {
39
26
  return this.value ? 1 : 0;
40
- };
41
- CustomBoolean.prototype.toTruthy = function () {
27
+ }
28
+ toTruthy() {
42
29
  return this.value;
43
- };
44
- return CustomBoolean;
45
- }(generics_1.CustomValue));
30
+ }
31
+ }
46
32
  exports.default = CustomBoolean;
33
+ exports.DefaultTrue = new CustomBoolean(true);
34
+ exports.DefaultFalse = new CustomBoolean(false);
@@ -1,11 +1,8 @@
1
- import CustomBoolean from './boolean';
2
- import CustomNil from './nil';
3
- import CustomNumber from './number';
4
1
  export default class Defaults {
5
- static readonly Void: CustomNil;
6
- static readonly True: CustomBoolean;
7
- static readonly False: CustomBoolean;
8
- static readonly NegativeOne: CustomNumber;
9
- static readonly PositiveOne: CustomNumber;
10
- static readonly Zero: CustomNumber;
2
+ static readonly Void: import("./nil").default;
3
+ static readonly True: import("./boolean").default;
4
+ static readonly False: import("./boolean").default;
5
+ static readonly NegativeOne: import("./number").default;
6
+ static readonly PositiveOne: import("./number").default;
7
+ static readonly Zero: import("./number").default;
11
8
  }
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var boolean_1 = __importDefault(require("./boolean"));
7
- var nil_1 = __importDefault(require("./nil"));
8
- var number_1 = __importDefault(require("./number"));
9
- var Defaults = /** @class */ (function () {
10
- function Defaults() {
11
- }
12
- Defaults.Void = new nil_1.default();
13
- Defaults.True = new boolean_1.default(true);
14
- Defaults.False = new boolean_1.default(false);
15
- Defaults.NegativeOne = new number_1.default(-1);
16
- Defaults.PositiveOne = new number_1.default(1);
17
- Defaults.Zero = new number_1.default(0);
18
- return Defaults;
19
- }());
3
+ const boolean_1 = require("./boolean");
4
+ const nil_1 = require("./nil");
5
+ const number_1 = require("./number");
6
+ class Defaults {
7
+ }
20
8
  exports.default = Defaults;
9
+ Defaults.Void = nil_1.Void;
10
+ Defaults.True = boolean_1.DefaultTrue;
11
+ Defaults.False = boolean_1.DefaultFalse;
12
+ Defaults.NegativeOne = number_1.NegativeOne;
13
+ Defaults.PositiveOne = number_1.PositiveOne;
14
+ Defaults.Zero = number_1.Zero;
@@ -1,6 +1,6 @@
1
1
  import OperationContext from '../context';
2
2
  import Operation from '../operations/operation';
3
- import { CustomValue } from './generics';
3
+ import CustomValue from './base';
4
4
  export interface Callback {
5
5
  (ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
6
6
  }
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -23,49 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
9
  });
25
10
  };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
54
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
13
  };
56
14
  Object.defineProperty(exports, "__esModule", { value: true });
57
15
  exports.Argument = void 0;
58
- var context_1 = require("../context");
59
- var operation_1 = __importDefault(require("../operations/operation"));
60
- var reference_1 = __importDefault(require("../operations/reference"));
61
- var default_1 = __importDefault(require("./default"));
62
- var generics_1 = require("./generics");
63
- var nil_1 = __importDefault(require("./nil"));
64
- var Argument = /** @class */ (function () {
65
- function Argument(name, defaultValue) {
66
- if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
16
+ const context_1 = require("../context");
17
+ const operation_1 = __importDefault(require("../operations/operation"));
18
+ const reference_1 = __importDefault(require("../operations/reference"));
19
+ const base_1 = __importDefault(require("./base"));
20
+ const default_1 = __importDefault(require("./default"));
21
+ const nil_1 = __importDefault(require("./nil"));
22
+ class Argument {
23
+ constructor(name, defaultValue = default_1.default.Void) {
67
24
  this.name = name;
68
- if (defaultValue instanceof generics_1.CustomValue) {
25
+ if (defaultValue instanceof base_1.default) {
69
26
  this.defaultValue = new reference_1.default(defaultValue);
70
27
  }
71
28
  else if (defaultValue instanceof operation_1.default) {
@@ -75,100 +32,73 @@ var Argument = /** @class */ (function () {
75
32
  throw new Error('Invalid defaultValue in argument.');
76
33
  }
77
34
  }
78
- Argument.createWithCustomValue = function (name, defaultValue) {
35
+ static createWithCustomValue(name, defaultValue) {
79
36
  return new Argument(name, new reference_1.default(defaultValue));
80
- };
81
- return Argument;
82
- }());
37
+ }
38
+ }
83
39
  exports.Argument = Argument;
84
- var CustomFunction = /** @class */ (function (_super) {
85
- __extends(CustomFunction, _super);
86
- function CustomFunction(scope, name, callback, injectSelf) {
87
- if (injectSelf === void 0) { injectSelf = false; }
88
- var _this = _super.call(this) || this;
89
- _this.scope = scope;
90
- _this.name = name;
91
- _this.value = callback;
92
- _this.injectSelf = injectSelf;
93
- _this.argumentDefs = [];
94
- return _this;
40
+ class CustomFunction extends base_1.default {
41
+ constructor(scope, name, callback, injectSelf = false) {
42
+ super();
43
+ this.scope = scope;
44
+ this.name = name;
45
+ this.value = callback;
46
+ this.injectSelf = injectSelf;
47
+ this.argumentDefs = [];
95
48
  }
96
- CustomFunction.createExternalAnonymous = function (callback) {
49
+ static createExternalAnonymous(callback) {
97
50
  return new CustomFunction(null, 'anonymous', callback);
98
- };
99
- CustomFunction.createExternal = function (name, callback) {
51
+ }
52
+ static createExternal(name, callback) {
100
53
  return new CustomFunction(null, name, callback);
101
- };
102
- CustomFunction.createExternalWithSelf = function (name, callback) {
54
+ }
55
+ static createExternalWithSelf(name, callback) {
103
56
  return new CustomFunction(null, name, callback, true).addArgument('self');
104
- };
105
- CustomFunction.prototype.setInjectSelf = function (injectSelf) {
57
+ }
58
+ setInjectSelf(injectSelf) {
106
59
  this.injectSelf = injectSelf;
107
60
  return this;
108
- };
109
- CustomFunction.prototype.addArgument = function (name, defaultValue) {
110
- if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
61
+ }
62
+ addArgument(name, defaultValue = default_1.default.Void) {
111
63
  this.argumentDefs.push(new Argument(name, defaultValue));
112
64
  return this;
113
- };
114
- CustomFunction.prototype.fork = function () {
65
+ }
66
+ fork() {
115
67
  return new CustomFunction(this.scope, this.name, this.value);
116
- };
117
- CustomFunction.prototype.getCustomType = function () {
68
+ }
69
+ getCustomType() {
118
70
  return 'function';
119
- };
120
- CustomFunction.prototype.toNumber = function () {
71
+ }
72
+ toNumber() {
121
73
  return Number.NaN;
122
- };
123
- CustomFunction.prototype.toInt = function () {
74
+ }
75
+ toInt() {
124
76
  return 0;
125
- };
126
- CustomFunction.prototype.toString = function () {
127
- var args = this.argumentDefs.map(function (item) { return item.name; });
128
- return "function ".concat(this.name, "(").concat(args.join(', '), ")");
129
- };
130
- CustomFunction.prototype.toTruthy = function () {
77
+ }
78
+ toString() {
79
+ const args = this.argumentDefs.map((item) => item.name);
80
+ return `function ${this.name}(${args.join(', ')})`;
81
+ }
82
+ toTruthy() {
131
83
  return true;
132
- };
133
- CustomFunction.prototype.run = function (self, args, callContext) {
84
+ }
85
+ run(self, args, callContext) {
134
86
  var _a;
135
- return __awaiter(this, void 0, void 0, function () {
136
- var fnCtx, argMap, index, item, _b, _c, _d, _e;
137
- return __generator(this, function (_f) {
138
- switch (_f.label) {
139
- case 0:
140
- fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
141
- type: context_1.ContextType.Function,
142
- state: context_1.ContextState.Default
143
- });
144
- argMap = new Map();
145
- if (this.injectSelf && !(self instanceof nil_1.default)) {
146
- args.unshift(self);
147
- }
148
- index = 0;
149
- _f.label = 1;
150
- case 1:
151
- if (!(index < this.argumentDefs.length)) return [3 /*break*/, 5];
152
- item = this.argumentDefs[index];
153
- _c = (_b = argMap).set;
154
- _d = [item.name];
155
- _e = args[index];
156
- if (_e) return [3 /*break*/, 3];
157
- return [4 /*yield*/, item.defaultValue.handle(fnCtx)];
158
- case 2:
159
- _e = (_f.sent());
160
- _f.label = 3;
161
- case 3:
162
- _c.apply(_b, _d.concat([_e]));
163
- _f.label = 4;
164
- case 4:
165
- index++;
166
- return [3 /*break*/, 1];
167
- case 5: return [2 /*return*/, this.value(fnCtx || callContext, self, argMap)];
168
- }
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
89
+ type: context_1.ContextType.Function,
90
+ state: context_1.ContextState.Default
169
91
  });
92
+ const argMap = new Map();
93
+ if (this.injectSelf && !(self instanceof nil_1.default)) {
94
+ args.unshift(self);
95
+ }
96
+ for (let index = 0; index < this.argumentDefs.length; index++) {
97
+ const item = this.argumentDefs[index];
98
+ argMap.set(item.name, args[index] || (yield item.defaultValue.handle(fnCtx)));
99
+ }
100
+ return this.value(fnCtx || callContext, self, argMap);
170
101
  });
171
- };
172
- return CustomFunction;
173
- }(generics_1.CustomValue));
102
+ }
103
+ }
174
104
  exports.default = CustomFunction;
@@ -1,6 +1,7 @@
1
1
  import Path from '../utils/path';
2
+ import CustomValue from './base';
2
3
  import CustomFunction from './function';
3
- import { CustomObject, CustomValue } from './generics';
4
+ import { CustomObject } from './with-intrinsics';
4
5
  export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
5
6
  next(): IteratorResult<CustomValue>;
6
7
  }