greybel-interpreter 1.3.7 → 1.3.8
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.
- package/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -109
- package/dist/context.js +383 -382
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +213 -213
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +35 -35
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +52 -52
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +51 -51
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +16 -16
- package/dist/index.d.ts +45 -45
- package/dist/index.js +131 -131
- package/dist/interpreter.d.ts +41 -41
- package/dist/interpreter.js +312 -312
- package/dist/intrinsics-container.d.ts +7 -7
- package/dist/intrinsics-container.js +19 -19
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +111 -111
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +108 -108
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +41 -41
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +124 -124
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +85 -85
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +41 -41
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +39 -39
- package/dist/operations/evaluate.d.ts +41 -39
- package/dist/operations/evaluate.js +433 -367
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +152 -152
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +103 -103
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +200 -200
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +181 -181
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +119 -119
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +95 -95
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +111 -111
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +58 -58
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +171 -171
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +109 -109
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +100 -100
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +36 -36
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +11 -11
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +37 -37
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +330 -330
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -107
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +136 -136
- package/dist/types/boolean.d.ts +11 -11
- package/dist/types/boolean.js +46 -46
- package/dist/types/default.d.ts +11 -11
- package/dist/types/default.js +20 -20
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +174 -174
- package/dist/types/generics.d.ts +18 -18
- package/dist/types/generics.js +40 -40
- package/dist/types/interface.d.ts +23 -23
- package/dist/types/interface.js +103 -103
- package/dist/types/list.d.ts +31 -31
- package/dist/types/list.js +209 -209
- package/dist/types/map.d.ts +37 -37
- package/dist/types/map.js +366 -366
- package/dist/types/nil.d.ts +10 -10
- package/dist/types/nil.js +46 -46
- package/dist/types/number.d.ts +11 -11
- package/dist/types/number.js +46 -46
- package/dist/types/string.d.ts +33 -33
- package/dist/types/string.js +145 -145
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +62 -62
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +59 -59
- package/package.json +58 -58
package/dist/types/boolean.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
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
|
-
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;
|
|
25
|
-
}
|
|
26
|
-
CustomBoolean.prototype.getCustomType = function () {
|
|
27
|
-
return 'boolean';
|
|
28
|
-
};
|
|
29
|
-
CustomBoolean.prototype.toString = function () {
|
|
30
|
-
return this.value.toString();
|
|
31
|
-
};
|
|
32
|
-
CustomBoolean.prototype.fork = function () {
|
|
33
|
-
return new CustomBoolean(this.value);
|
|
34
|
-
};
|
|
35
|
-
CustomBoolean.prototype.toNumber = function () {
|
|
36
|
-
return this.value ? 1.0 : 0.0;
|
|
37
|
-
};
|
|
38
|
-
CustomBoolean.prototype.toInt = function () {
|
|
39
|
-
return this.value ? 1 : 0;
|
|
40
|
-
};
|
|
41
|
-
CustomBoolean.prototype.toTruthy = function () {
|
|
42
|
-
return this.value;
|
|
43
|
-
};
|
|
44
|
-
return CustomBoolean;
|
|
45
|
-
}(generics_1.CustomValue));
|
|
46
|
-
exports.default = CustomBoolean;
|
|
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
|
+
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;
|
|
25
|
+
}
|
|
26
|
+
CustomBoolean.prototype.getCustomType = function () {
|
|
27
|
+
return 'boolean';
|
|
28
|
+
};
|
|
29
|
+
CustomBoolean.prototype.toString = function () {
|
|
30
|
+
return this.value.toString();
|
|
31
|
+
};
|
|
32
|
+
CustomBoolean.prototype.fork = function () {
|
|
33
|
+
return new CustomBoolean(this.value);
|
|
34
|
+
};
|
|
35
|
+
CustomBoolean.prototype.toNumber = function () {
|
|
36
|
+
return this.value ? 1.0 : 0.0;
|
|
37
|
+
};
|
|
38
|
+
CustomBoolean.prototype.toInt = function () {
|
|
39
|
+
return this.value ? 1 : 0;
|
|
40
|
+
};
|
|
41
|
+
CustomBoolean.prototype.toTruthy = function () {
|
|
42
|
+
return this.value;
|
|
43
|
+
};
|
|
44
|
+
return CustomBoolean;
|
|
45
|
+
}(generics_1.CustomValue));
|
|
46
|
+
exports.default = CustomBoolean;
|
package/dist/types/default.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import CustomBoolean from './boolean';
|
|
2
|
-
import CustomNil from './nil';
|
|
3
|
-
import CustomNumber from './number';
|
|
4
|
-
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;
|
|
11
|
-
}
|
|
1
|
+
import CustomBoolean from './boolean';
|
|
2
|
+
import CustomNil from './nil';
|
|
3
|
+
import CustomNumber from './number';
|
|
4
|
+
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;
|
|
11
|
+
}
|
package/dist/types/default.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
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
|
-
}());
|
|
20
|
-
exports.default = Defaults;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
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
|
+
}());
|
|
20
|
+
exports.default = Defaults;
|
package/dist/types/function.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import OperationContext from '../context';
|
|
2
|
-
import Operation from '../operations/operation';
|
|
3
|
-
import { CustomValue } from './generics';
|
|
4
|
-
export interface Callback {
|
|
5
|
-
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
6
|
-
}
|
|
7
|
-
export declare class Argument {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
readonly defaultValue: Operation;
|
|
10
|
-
static createWithCustomValue(name: string, defaultValue: CustomValue): Argument;
|
|
11
|
-
constructor(name: string, defaultValue?: Operation | CustomValue);
|
|
12
|
-
}
|
|
13
|
-
export default class CustomFunction extends CustomValue {
|
|
14
|
-
readonly scope?: OperationContext;
|
|
15
|
-
readonly name: string;
|
|
16
|
-
readonly value: Callback;
|
|
17
|
-
private injectSelf;
|
|
18
|
-
readonly argumentDefs: Array<Argument>;
|
|
19
|
-
static createExternalAnonymous(callback: Callback): CustomFunction;
|
|
20
|
-
static createExternal(name: string, callback: Callback): CustomFunction;
|
|
21
|
-
static createExternalWithSelf(name: string, callback: Callback): CustomFunction;
|
|
22
|
-
constructor(scope: OperationContext, name: string, callback: Callback, injectSelf?: boolean);
|
|
23
|
-
setInjectSelf(injectSelf: boolean): CustomFunction;
|
|
24
|
-
addArgument(name: string, defaultValue?: Operation | CustomValue): CustomFunction;
|
|
25
|
-
fork(): CustomValue;
|
|
26
|
-
getCustomType(): string;
|
|
27
|
-
toNumber(): number;
|
|
28
|
-
toInt(): number;
|
|
29
|
-
toString(): string;
|
|
30
|
-
toTruthy(): boolean;
|
|
31
|
-
run(self: CustomValue, args: Array<CustomValue>, callContext: OperationContext): Promise<CustomValue>;
|
|
32
|
-
}
|
|
1
|
+
import OperationContext from '../context';
|
|
2
|
+
import Operation from '../operations/operation';
|
|
3
|
+
import { CustomValue } from './generics';
|
|
4
|
+
export interface Callback {
|
|
5
|
+
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Argument {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly defaultValue: Operation;
|
|
10
|
+
static createWithCustomValue(name: string, defaultValue: CustomValue): Argument;
|
|
11
|
+
constructor(name: string, defaultValue?: Operation | CustomValue);
|
|
12
|
+
}
|
|
13
|
+
export default class CustomFunction extends CustomValue {
|
|
14
|
+
readonly scope?: OperationContext;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly value: Callback;
|
|
17
|
+
private injectSelf;
|
|
18
|
+
readonly argumentDefs: Array<Argument>;
|
|
19
|
+
static createExternalAnonymous(callback: Callback): CustomFunction;
|
|
20
|
+
static createExternal(name: string, callback: Callback): CustomFunction;
|
|
21
|
+
static createExternalWithSelf(name: string, callback: Callback): CustomFunction;
|
|
22
|
+
constructor(scope: OperationContext, name: string, callback: Callback, injectSelf?: boolean);
|
|
23
|
+
setInjectSelf(injectSelf: boolean): CustomFunction;
|
|
24
|
+
addArgument(name: string, defaultValue?: Operation | CustomValue): CustomFunction;
|
|
25
|
+
fork(): CustomValue;
|
|
26
|
+
getCustomType(): string;
|
|
27
|
+
toNumber(): number;
|
|
28
|
+
toInt(): number;
|
|
29
|
+
toString(): string;
|
|
30
|
+
toTruthy(): boolean;
|
|
31
|
+
run(self: CustomValue, args: Array<CustomValue>, callContext: OperationContext): Promise<CustomValue>;
|
|
32
|
+
}
|
package/dist/types/function.js
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
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; }
|
|
67
|
-
this.name = name;
|
|
68
|
-
if (defaultValue instanceof generics_1.CustomValue) {
|
|
69
|
-
this.defaultValue = new reference_1.default(defaultValue);
|
|
70
|
-
}
|
|
71
|
-
else if (defaultValue instanceof operation_1.default) {
|
|
72
|
-
this.defaultValue = defaultValue;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw new Error('Invalid defaultValue in argument.');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
Argument.createWithCustomValue = function (name, defaultValue) {
|
|
79
|
-
return new Argument(name, new reference_1.default(defaultValue));
|
|
80
|
-
};
|
|
81
|
-
return Argument;
|
|
82
|
-
}());
|
|
83
|
-
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;
|
|
95
|
-
}
|
|
96
|
-
CustomFunction.createExternalAnonymous = function (callback) {
|
|
97
|
-
return new CustomFunction(null, 'anonymous', callback);
|
|
98
|
-
};
|
|
99
|
-
CustomFunction.createExternal = function (name, callback) {
|
|
100
|
-
return new CustomFunction(null, name, callback);
|
|
101
|
-
};
|
|
102
|
-
CustomFunction.createExternalWithSelf = function (name, callback) {
|
|
103
|
-
return new CustomFunction(null, name, callback, true).addArgument('self');
|
|
104
|
-
};
|
|
105
|
-
CustomFunction.prototype.setInjectSelf = function (injectSelf) {
|
|
106
|
-
this.injectSelf = injectSelf;
|
|
107
|
-
return this;
|
|
108
|
-
};
|
|
109
|
-
CustomFunction.prototype.addArgument = function (name, defaultValue) {
|
|
110
|
-
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
111
|
-
this.argumentDefs.push(new Argument(name, defaultValue));
|
|
112
|
-
return this;
|
|
113
|
-
};
|
|
114
|
-
CustomFunction.prototype.fork = function () {
|
|
115
|
-
return new CustomFunction(this.scope, this.name, this.value);
|
|
116
|
-
};
|
|
117
|
-
CustomFunction.prototype.getCustomType = function () {
|
|
118
|
-
return 'function';
|
|
119
|
-
};
|
|
120
|
-
CustomFunction.prototype.toNumber = function () {
|
|
121
|
-
return Number.NaN;
|
|
122
|
-
};
|
|
123
|
-
CustomFunction.prototype.toInt = function () {
|
|
124
|
-
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 () {
|
|
131
|
-
return true;
|
|
132
|
-
};
|
|
133
|
-
CustomFunction.prototype.run = function (self, args, callContext) {
|
|
134
|
-
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
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
return CustomFunction;
|
|
173
|
-
}(generics_1.CustomValue));
|
|
174
|
-
exports.default = CustomFunction;
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
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; }
|
|
67
|
+
this.name = name;
|
|
68
|
+
if (defaultValue instanceof generics_1.CustomValue) {
|
|
69
|
+
this.defaultValue = new reference_1.default(defaultValue);
|
|
70
|
+
}
|
|
71
|
+
else if (defaultValue instanceof operation_1.default) {
|
|
72
|
+
this.defaultValue = defaultValue;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error('Invalid defaultValue in argument.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
Argument.createWithCustomValue = function (name, defaultValue) {
|
|
79
|
+
return new Argument(name, new reference_1.default(defaultValue));
|
|
80
|
+
};
|
|
81
|
+
return Argument;
|
|
82
|
+
}());
|
|
83
|
+
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;
|
|
95
|
+
}
|
|
96
|
+
CustomFunction.createExternalAnonymous = function (callback) {
|
|
97
|
+
return new CustomFunction(null, 'anonymous', callback);
|
|
98
|
+
};
|
|
99
|
+
CustomFunction.createExternal = function (name, callback) {
|
|
100
|
+
return new CustomFunction(null, name, callback);
|
|
101
|
+
};
|
|
102
|
+
CustomFunction.createExternalWithSelf = function (name, callback) {
|
|
103
|
+
return new CustomFunction(null, name, callback, true).addArgument('self');
|
|
104
|
+
};
|
|
105
|
+
CustomFunction.prototype.setInjectSelf = function (injectSelf) {
|
|
106
|
+
this.injectSelf = injectSelf;
|
|
107
|
+
return this;
|
|
108
|
+
};
|
|
109
|
+
CustomFunction.prototype.addArgument = function (name, defaultValue) {
|
|
110
|
+
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
111
|
+
this.argumentDefs.push(new Argument(name, defaultValue));
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
CustomFunction.prototype.fork = function () {
|
|
115
|
+
return new CustomFunction(this.scope, this.name, this.value);
|
|
116
|
+
};
|
|
117
|
+
CustomFunction.prototype.getCustomType = function () {
|
|
118
|
+
return 'function';
|
|
119
|
+
};
|
|
120
|
+
CustomFunction.prototype.toNumber = function () {
|
|
121
|
+
return Number.NaN;
|
|
122
|
+
};
|
|
123
|
+
CustomFunction.prototype.toInt = function () {
|
|
124
|
+
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 () {
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
CustomFunction.prototype.run = function (self, args, callContext) {
|
|
134
|
+
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
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
return CustomFunction;
|
|
173
|
+
}(generics_1.CustomValue));
|
|
174
|
+
exports.default = CustomFunction;
|
package/dist/types/generics.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import Path from '../utils/path';
|
|
2
|
-
export declare abstract class CustomValue {
|
|
3
|
-
abstract value: any;
|
|
4
|
-
abstract getCustomType(): string;
|
|
5
|
-
abstract toNumber(): number;
|
|
6
|
-
abstract toInt(): number;
|
|
7
|
-
abstract toString(): string;
|
|
8
|
-
abstract toTruthy(): boolean;
|
|
9
|
-
abstract fork(): CustomValue;
|
|
10
|
-
}
|
|
11
|
-
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
12
|
-
abstract has(path: Path<CustomValue> | CustomValue): boolean;
|
|
13
|
-
abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
14
|
-
abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
15
|
-
abstract [Symbol.iterator](): Iterator<CustomValue>;
|
|
16
|
-
}
|
|
17
|
-
export declare abstract class CustomObject extends CustomValueWithIntrinsics {
|
|
18
|
-
}
|
|
1
|
+
import Path from '../utils/path';
|
|
2
|
+
export declare abstract class CustomValue {
|
|
3
|
+
abstract value: any;
|
|
4
|
+
abstract getCustomType(): string;
|
|
5
|
+
abstract toNumber(): number;
|
|
6
|
+
abstract toInt(): number;
|
|
7
|
+
abstract toString(): string;
|
|
8
|
+
abstract toTruthy(): boolean;
|
|
9
|
+
abstract fork(): CustomValue;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
12
|
+
abstract has(path: Path<CustomValue> | CustomValue): boolean;
|
|
13
|
+
abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
14
|
+
abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
15
|
+
abstract [Symbol.iterator](): Iterator<CustomValue>;
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class CustomObject extends CustomValueWithIntrinsics {
|
|
18
|
+
}
|