@dronedeploy/rocos-js-sdk 3.0.10 → 3.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/api/StreamRegister.d.ts +3 -3
- package/cjs/api/StreamRegister.js +6 -6
- package/cjs/api/streams/telemetry/TelemetryStreamAbstract.js +8 -7
- package/cjs/helpers/kscript/Context.d.ts +14 -8
- package/cjs/helpers/kscript/Context.js +59 -22
- package/cjs/helpers/kscript/kscript.d.ts +7 -2
- package/cjs/helpers/kscript/kscript.js +24 -14
- package/cjs/helpers/kscript/nodes/Identifier.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/Identifier.js +2 -1
- package/cjs/helpers/kscript/nodes/Literal.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/Literal.js +4 -1
- package/cjs/helpers/kscript/nodes/Node.d.ts +6 -1
- package/cjs/helpers/kscript/nodes/Node.js +0 -1
- package/cjs/helpers/kscript/nodes/Program.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/Program.js +13 -4
- package/cjs/helpers/kscript/nodes/TemplateLiteral.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/TemplateLiteral.js +8 -0
- package/cjs/helpers/kscript/nodes/VariableDeclaration.d.ts +8 -0
- package/cjs/helpers/kscript/nodes/VariableDeclaration.js +43 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.js +11 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +19 -5
- package/cjs/helpers/kscript/nodes/expressions/AssignmentExpression.d.ts +8 -0
- package/cjs/helpers/kscript/nodes/expressions/AssignmentExpression.js +33 -0
- package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +8 -0
- package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.js +55 -22
- package/cjs/helpers/kscript/nodes/expressions/CallExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/CallExpression.js +11 -1
- package/cjs/helpers/kscript/nodes/expressions/ChainExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ChainExpression.js +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.js +10 -0
- package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +2 -0
- package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.js +11 -0
- package/cjs/helpers/kscript/nodes/expressions/MemberExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/MemberExpression.js +7 -0
- package/cjs/helpers/kscript/nodes/expressions/NewExpression.d.ts +9 -0
- package/cjs/helpers/kscript/nodes/expressions/NewExpression.js +44 -0
- package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.js +29 -0
- package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +2 -0
- package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.js +9 -0
- package/cjs/helpers/kscript/nodes/expressions/index.d.ts +2 -1
- package/cjs/helpers/kscript/nodes/expressions/index.js +5 -3
- package/cjs/helpers/kscript/nodes/nodeTypes.d.ts +9 -1
- package/cjs/helpers/kscript/nodes/nodeTypes.js +9 -1
- package/cjs/helpers/kscript/nodes/statements/BlockStatement.d.ts +8 -0
- package/cjs/helpers/kscript/nodes/statements/BlockStatement.js +29 -0
- package/cjs/helpers/kscript/nodes/{expressions → statements}/ExpressionStatement.d.ts +1 -0
- package/cjs/helpers/kscript/nodes/{expressions → statements}/ExpressionStatement.js +8 -1
- package/cjs/helpers/kscript/nodes/statements/ReturnStatement.d.ts +12 -0
- package/cjs/helpers/kscript/nodes/statements/ReturnStatement.js +33 -0
- package/cjs/helpers/kscript/nodes/statements/SwitchStatement.d.ts +9 -0
- package/cjs/helpers/kscript/nodes/statements/SwitchStatement.js +52 -0
- package/cjs/helpers/kscript/nodes/statements/index.d.ts +4 -0
- package/cjs/helpers/kscript/nodes/statements/index.js +14 -0
- package/cjs/models/asset-storage/SyncIntegrations.d.ts +3 -3
- package/cjs/services/AssetStorageService.d.ts +3 -3
- package/cjs/services/BaseStreamService.js +1 -1
- package/cjs/services/WebRTCSignallingService.js +1 -2
- package/esm/api/StreamRegister.d.ts +3 -3
- package/esm/api/StreamRegister.js +6 -6
- package/esm/api/streams/telemetry/TelemetryStreamAbstract.js +8 -7
- package/esm/helpers/kscript/Context.d.ts +14 -8
- package/esm/helpers/kscript/Context.js +59 -22
- package/esm/helpers/kscript/kscript.d.ts +7 -2
- package/esm/helpers/kscript/kscript.js +22 -13
- package/esm/helpers/kscript/nodes/Identifier.d.ts +1 -0
- package/esm/helpers/kscript/nodes/Identifier.js +2 -1
- package/esm/helpers/kscript/nodes/Literal.d.ts +1 -0
- package/esm/helpers/kscript/nodes/Literal.js +4 -1
- package/esm/helpers/kscript/nodes/Node.d.ts +6 -1
- package/esm/helpers/kscript/nodes/Node.js +0 -1
- package/esm/helpers/kscript/nodes/Program.d.ts +1 -0
- package/esm/helpers/kscript/nodes/Program.js +13 -4
- package/esm/helpers/kscript/nodes/TemplateLiteral.d.ts +1 -0
- package/esm/helpers/kscript/nodes/TemplateLiteral.js +8 -0
- package/esm/helpers/kscript/nodes/VariableDeclaration.d.ts +8 -0
- package/esm/helpers/kscript/nodes/VariableDeclaration.js +37 -0
- package/esm/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/ArrayExpression.js +11 -0
- package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +19 -5
- package/esm/helpers/kscript/nodes/expressions/AssignmentExpression.d.ts +8 -0
- package/esm/helpers/kscript/nodes/expressions/AssignmentExpression.js +27 -0
- package/esm/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +8 -0
- package/esm/helpers/kscript/nodes/expressions/BinaryExpression.js +57 -23
- package/esm/helpers/kscript/nodes/expressions/CallExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/CallExpression.js +11 -1
- package/esm/helpers/kscript/nodes/expressions/ChainExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/ChainExpression.js +1 -0
- package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.js +10 -0
- package/esm/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +2 -0
- package/esm/helpers/kscript/nodes/expressions/LogicalExpression.js +13 -1
- package/esm/helpers/kscript/nodes/expressions/MemberExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/MemberExpression.js +7 -0
- package/esm/helpers/kscript/nodes/expressions/NewExpression.d.ts +9 -0
- package/esm/helpers/kscript/nodes/expressions/NewExpression.js +38 -0
- package/esm/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +1 -0
- package/esm/helpers/kscript/nodes/expressions/ObjectExpression.js +29 -0
- package/esm/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +2 -0
- package/esm/helpers/kscript/nodes/expressions/UnaryExpression.js +11 -1
- package/esm/helpers/kscript/nodes/expressions/index.d.ts +2 -1
- package/esm/helpers/kscript/nodes/expressions/index.js +2 -1
- package/esm/helpers/kscript/nodes/nodeTypes.d.ts +9 -1
- package/esm/helpers/kscript/nodes/nodeTypes.js +9 -1
- package/esm/helpers/kscript/nodes/statements/BlockStatement.d.ts +8 -0
- package/esm/helpers/kscript/nodes/statements/BlockStatement.js +23 -0
- package/esm/helpers/kscript/nodes/{expressions → statements}/ExpressionStatement.d.ts +1 -0
- package/esm/helpers/kscript/nodes/{expressions → statements}/ExpressionStatement.js +8 -1
- package/esm/helpers/kscript/nodes/statements/ReturnStatement.d.ts +12 -0
- package/esm/helpers/kscript/nodes/statements/ReturnStatement.js +25 -0
- package/esm/helpers/kscript/nodes/statements/SwitchStatement.d.ts +9 -0
- package/esm/helpers/kscript/nodes/statements/SwitchStatement.js +46 -0
- package/esm/helpers/kscript/nodes/statements/index.d.ts +4 -0
- package/esm/helpers/kscript/nodes/statements/index.js +4 -0
- package/esm/models/asset-storage/SyncIntegrations.d.ts +3 -3
- package/esm/services/AssetStorageService.d.ts +3 -3
- package/esm/services/BaseStreamService.js +1 -1
- package/esm/services/WebRTCSignallingService.js +1 -2
- package/package.json +1 -1
@@ -13,34 +13,48 @@ class BinaryExpressionNode extends Node_1.default {
|
|
13
13
|
constructor(node, context) {
|
14
14
|
super(node, context, 'BinaryExpression');
|
15
15
|
}
|
16
|
+
validate(validateChildren = false) {
|
17
|
+
if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
|
18
|
+
throw new Error(`Unsupported operator: ${this.node.operator}`);
|
19
|
+
}
|
20
|
+
if (!validateChildren) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
(0, utils_1.construct)(this.node.left, this.context).validate(true);
|
24
|
+
(0, utils_1.construct)(this.node.right, this.context).validate(true);
|
25
|
+
}
|
16
26
|
run() {
|
17
27
|
const left = (0, utils_1.construct)(this.node.left, this.context).run();
|
18
28
|
const right = (0, utils_1.construct)(this.node.right, this.context).run();
|
19
29
|
return this.operate(left, right);
|
20
30
|
}
|
21
31
|
operate(left, right) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
if (BinaryExpressionNode.EQUALITY_OPERATORS.has(this.node.operator)) {
|
33
|
+
return this.equality(this.node.operator, left, right);
|
34
|
+
}
|
35
|
+
if (BinaryExpressionNode.COMPARISON_OPERATORS.has(this.node.operator)) {
|
36
|
+
return this.comparison(this.node.operator, left, right);
|
37
|
+
}
|
38
|
+
if (BinaryExpressionNode.ARITHMETIC_OPERATORS.has(this.node.operator)) {
|
39
|
+
return this.arithmetic(this.node.operator, left, right);
|
40
|
+
}
|
41
|
+
if (BinaryExpressionNode.BITWISE_OPERATORS.has(this.node.operator)) {
|
42
|
+
return this.bitwise(this.node.operator, left, right);
|
43
|
+
}
|
44
|
+
if (this.node.operator === BinaryExpressionNode.IN_OPERATOR) {
|
45
|
+
return this.checkIn(left, right);
|
46
|
+
}
|
47
|
+
throw new Error(`Unsupported operator: ${this.node.operator}`);
|
48
|
+
}
|
49
|
+
bitwise(operator, left, right) {
|
50
|
+
if (typeof left !== 'number' || typeof right !== 'number') {
|
51
|
+
throw new Error('Bitwise operators are only supported for numbers');
|
52
|
+
}
|
53
|
+
switch (operator) {
|
54
|
+
case '<<':
|
55
|
+
return left << right;
|
56
|
+
case '>>':
|
57
|
+
return left >> right;
|
44
58
|
}
|
45
59
|
}
|
46
60
|
arithmetic(operator, left, right) {
|
@@ -101,4 +115,23 @@ class BinaryExpressionNode extends Node_1.default {
|
|
101
115
|
return right.includes(left);
|
102
116
|
}
|
103
117
|
}
|
118
|
+
BinaryExpressionNode.EQUALITY_OPERATORS = new Set(['==', '!=', '===', '!==']);
|
119
|
+
BinaryExpressionNode.COMPARISON_OPERATORS = new Set(['<', '<=', '>', '>=']);
|
120
|
+
BinaryExpressionNode.ARITHMETIC_OPERATORS = new Set([
|
121
|
+
'+',
|
122
|
+
'-',
|
123
|
+
'*',
|
124
|
+
'/',
|
125
|
+
'%',
|
126
|
+
'**',
|
127
|
+
]);
|
128
|
+
BinaryExpressionNode.BITWISE_OPERATORS = new Set(['<<', '>>']);
|
129
|
+
BinaryExpressionNode.IN_OPERATOR = 'in';
|
130
|
+
BinaryExpressionNode.SUPPORTED_OPERATORS = new Set([
|
131
|
+
...BinaryExpressionNode.EQUALITY_OPERATORS,
|
132
|
+
...BinaryExpressionNode.COMPARISON_OPERATORS,
|
133
|
+
...BinaryExpressionNode.ARITHMETIC_OPERATORS,
|
134
|
+
...BinaryExpressionNode.BITWISE_OPERATORS,
|
135
|
+
BinaryExpressionNode.IN_OPERATOR,
|
136
|
+
]);
|
104
137
|
exports.default = BinaryExpressionNode;
|
@@ -3,6 +3,7 @@ import Context from '../../Context';
|
|
3
3
|
import Node from '../Node';
|
4
4
|
export default class CallExpressionNode extends Node<CallExpression> {
|
5
5
|
constructor(node: AnyNode, context: Context);
|
6
|
+
validate(validateChildren?: boolean): void;
|
6
7
|
run(): unknown;
|
7
8
|
private spreadArgs;
|
8
9
|
}
|
@@ -9,9 +9,19 @@ class CallExpressionNode extends Node_1.default {
|
|
9
9
|
constructor(node, context) {
|
10
10
|
super(node, context, 'CallExpression');
|
11
11
|
}
|
12
|
-
|
12
|
+
validate(validateChildren = false) {
|
13
13
|
if (!this.context.isFunctionCallAllowed)
|
14
14
|
throw new Error('Function calls are not allowed');
|
15
|
+
if (!validateChildren) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
(0, utils_1.construct)(this.node.callee, this.context).validate(true);
|
19
|
+
for (const arg of this.node.arguments) {
|
20
|
+
(0, utils_1.construct)(arg, this.context).validate(true);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
run() {
|
24
|
+
this.validate();
|
15
25
|
const callee = (0, utils_1.construct)(this.node.callee, this.context).run();
|
16
26
|
let thisArg = {};
|
17
27
|
if (this.node.callee.type === 'MemberExpression') {
|
@@ -16,6 +16,16 @@ class ConditionalExpressionNode extends Node_1.default {
|
|
16
16
|
constructor(node, context) {
|
17
17
|
super(node, context, ['ConditionalExpression', 'IfStatement']);
|
18
18
|
}
|
19
|
+
validate(validateChildren) {
|
20
|
+
if (!validateChildren) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
(0, utils_1.construct)(this.node.test, this.context).validate(true);
|
24
|
+
(0, utils_1.construct)(this.node.consequent, this.context).validate(true);
|
25
|
+
if (this.node.alternate !== null && this.node.alternate !== undefined) {
|
26
|
+
(0, utils_1.construct)(this.node.alternate, this.context).validate(true);
|
27
|
+
}
|
28
|
+
}
|
19
29
|
run() {
|
20
30
|
const test = (0, utils_1.construct)(this.node.test, this.context).run();
|
21
31
|
if (test) {
|
@@ -2,7 +2,9 @@ import { AnyNode, LogicalExpression } from 'acorn';
|
|
2
2
|
import Context from '../../Context';
|
3
3
|
import Node from '../Node';
|
4
4
|
export default class BinaryExpressionNode extends Node<LogicalExpression> {
|
5
|
+
private static readonly SUPPORTED_OPERATORS;
|
5
6
|
constructor(node: AnyNode, context: Context);
|
7
|
+
validate(validateChildren: boolean): void;
|
6
8
|
run(): unknown;
|
7
9
|
/** Try and skip evaluating the right operand */
|
8
10
|
private shortCircuit;
|
@@ -9,6 +9,16 @@ class BinaryExpressionNode extends Node_1.default {
|
|
9
9
|
constructor(node, context) {
|
10
10
|
super(node, context, 'LogicalExpression');
|
11
11
|
}
|
12
|
+
validate(validateChildren) {
|
13
|
+
if (!BinaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
|
14
|
+
throw new Error(`Unsupported operator: ${this.node.operator}`);
|
15
|
+
}
|
16
|
+
if (!validateChildren) {
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
(0, utils_1.construct)(this.node.left, this.context).validate(true);
|
20
|
+
(0, utils_1.construct)(this.node.right, this.context).validate(true);
|
21
|
+
}
|
12
22
|
run() {
|
13
23
|
const left = (0, utils_1.construct)(this.node.left, this.context).run();
|
14
24
|
const shortCircuit = this.shortCircuit(left);
|
@@ -44,4 +54,5 @@ class BinaryExpressionNode extends Node_1.default {
|
|
44
54
|
}
|
45
55
|
}
|
46
56
|
}
|
57
|
+
BinaryExpressionNode.SUPPORTED_OPERATORS = new Set(['||', '&&', '??']);
|
47
58
|
exports.default = BinaryExpressionNode;
|
@@ -22,6 +22,7 @@ import Node from '../Node';
|
|
22
22
|
*/
|
23
23
|
export default class MemberExpressionNode extends Node<MemberExpression> {
|
24
24
|
constructor(node: AnyNode, context: Context);
|
25
|
+
validate(validateChildren?: boolean): void;
|
25
26
|
run(): unknown;
|
26
27
|
/** Returns the name of the property being accessed.
|
27
28
|
*
|
@@ -28,6 +28,13 @@ class MemberExpressionNode extends Node_1.default {
|
|
28
28
|
constructor(node, context) {
|
29
29
|
super(node, context, 'MemberExpression');
|
30
30
|
}
|
31
|
+
validate(validateChildren = false) {
|
32
|
+
if (!validateChildren) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
(0, utils_1.construct)(this.node.object, this.context).validate(true);
|
36
|
+
(0, utils_1.construct)(this.node.property, this.context).validate(true);
|
37
|
+
}
|
31
38
|
run() {
|
32
39
|
const object = (0, utils_1.construct)(this.node.object, this.context).run();
|
33
40
|
if (object === null || object === undefined) {
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { AnyNode, NewExpression } from 'acorn';
|
2
|
+
import Context from '../../Context';
|
3
|
+
import Node from '../Node';
|
4
|
+
export default class NewExpressionNode extends Node<NewExpression> {
|
5
|
+
constructor(node: AnyNode, context: Context);
|
6
|
+
validate(validateChildren?: boolean): void;
|
7
|
+
run(): unknown;
|
8
|
+
private spreadArgs;
|
9
|
+
}
|
@@ -0,0 +1,44 @@
|
|
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
|
+
const Node_1 = __importDefault(require("../Node"));
|
7
|
+
const utils_1 = require("../../utils");
|
8
|
+
class NewExpressionNode extends Node_1.default {
|
9
|
+
constructor(node, context) {
|
10
|
+
super(node, context, 'NewExpression');
|
11
|
+
}
|
12
|
+
validate(validateChildren = false) {
|
13
|
+
if (!this.context.isFunctionCallAllowed)
|
14
|
+
throw new Error('Constructors are not allowed');
|
15
|
+
if (!validateChildren) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
(0, utils_1.construct)(this.node.callee, this.context).validate(true);
|
19
|
+
for (const arg of this.node.arguments) {
|
20
|
+
(0, utils_1.construct)(arg, this.context).validate(true);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
run() {
|
24
|
+
this.validate();
|
25
|
+
const callee = (0, utils_1.construct)(this.node.callee, this.context).run();
|
26
|
+
if (typeof callee !== 'function') {
|
27
|
+
throw new Error('callee is not a function');
|
28
|
+
}
|
29
|
+
const args = this.spreadArgs(this.node.arguments);
|
30
|
+
return new (Function.prototype.bind.apply(callee, [null, ...args]))();
|
31
|
+
}
|
32
|
+
spreadArgs(args) {
|
33
|
+
return args.reduce((acc, arg) => {
|
34
|
+
if (arg.type === 'SpreadElement') {
|
35
|
+
acc.push(...(0, utils_1.construct)(arg.argument, this.context).run());
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
acc.push((0, utils_1.construct)(arg, this.context).run());
|
39
|
+
}
|
40
|
+
return acc;
|
41
|
+
}, []);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
exports.default = NewExpressionNode;
|
@@ -3,6 +3,7 @@ import type Context from '../../Context';
|
|
3
3
|
import Node from '../Node';
|
4
4
|
export default class ObjectExpressionNode extends Node<ObjectExpression> {
|
5
5
|
constructor(node: AnyNode, context: Context);
|
6
|
+
validate(validateChildren: boolean): void;
|
6
7
|
run(): unknown;
|
7
8
|
private addProperty;
|
8
9
|
private spreadProperty;
|
@@ -9,6 +9,35 @@ class ObjectExpressionNode extends Node_1.default {
|
|
9
9
|
constructor(node, context) {
|
10
10
|
super(node, context, 'ObjectExpression');
|
11
11
|
}
|
12
|
+
validate(validateChildren) {
|
13
|
+
for (const property of this.node.properties) {
|
14
|
+
// SpreadElements do not need to be validated - they only have a single argument
|
15
|
+
if (property.type === 'SpreadElement') {
|
16
|
+
continue;
|
17
|
+
}
|
18
|
+
if (property.kind !== 'init') {
|
19
|
+
// do not support getters or setters
|
20
|
+
throw new Error('Only init properties are supported');
|
21
|
+
}
|
22
|
+
if (!property.computed) {
|
23
|
+
// ensure that the key is valid
|
24
|
+
this.getStaticKey(property.key);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
if (!validateChildren) {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
for (const property of this.node.properties) {
|
31
|
+
if (property.type === 'SpreadElement') {
|
32
|
+
(0, utils_1.construct)(property.argument, this.context).validate(true);
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
if (property.computed) {
|
36
|
+
(0, utils_1.construct)(property.key, this.context).validate(true);
|
37
|
+
}
|
38
|
+
(0, utils_1.construct)(property.value, this.context).validate(true);
|
39
|
+
}
|
40
|
+
}
|
12
41
|
run() {
|
13
42
|
const object = {};
|
14
43
|
for (const property of this.node.properties) {
|
@@ -6,7 +6,9 @@ import Node from '../Node';
|
|
6
6
|
* e.g. `+1`, `-2`, `!true`, `typeof x`
|
7
7
|
*/
|
8
8
|
export default class UnaryExpressionNode extends Node<UnaryExpression> {
|
9
|
+
private static readonly SUPPORTED_OPERATORS;
|
9
10
|
constructor(node: AnyNode, context: Context);
|
11
|
+
validate(validateChildren: boolean): void;
|
10
12
|
run(): unknown;
|
11
13
|
private arithmetic;
|
12
14
|
}
|
@@ -13,6 +13,14 @@ class UnaryExpressionNode extends Node_1.default {
|
|
13
13
|
constructor(node, context) {
|
14
14
|
super(node, context, 'UnaryExpression');
|
15
15
|
}
|
16
|
+
validate(validateChildren) {
|
17
|
+
if (!UnaryExpressionNode.SUPPORTED_OPERATORS.has(this.node.operator)) {
|
18
|
+
throw new Error(`Unsupported operator: ${this.node.operator}`);
|
19
|
+
}
|
20
|
+
if (validateChildren) {
|
21
|
+
(0, utils_1.construct)(this.node.argument, this.context).validate(true);
|
22
|
+
}
|
23
|
+
}
|
16
24
|
run() {
|
17
25
|
const argument = (0, utils_1.construct)(this.node.argument, this.context).run();
|
18
26
|
switch (this.node.operator) {
|
@@ -41,4 +49,5 @@ class UnaryExpressionNode extends Node_1.default {
|
|
41
49
|
}
|
42
50
|
}
|
43
51
|
}
|
52
|
+
UnaryExpressionNode.SUPPORTED_OPERATORS = new Set(['+', '-', '!', 'typeof']);
|
44
53
|
exports.default = UnaryExpressionNode;
|
@@ -1,4 +1,3 @@
|
|
1
|
-
export { default as ExpressionStatement } from './ExpressionStatement';
|
2
1
|
export { default as ArrayExpression } from './ArrayExpression';
|
3
2
|
export { default as ObjectExpression } from './ObjectExpression';
|
4
3
|
export { default as BinaryExpression } from './BinaryExpression';
|
@@ -9,3 +8,5 @@ export { default as CallExpression } from './CallExpression';
|
|
9
8
|
export { default as ArrowFunctionExpression } from './ArrowFunctionExpression';
|
10
9
|
export { default as MemberExpression } from './MemberExpression';
|
11
10
|
export { default as ChainExpression } from './ChainExpression';
|
11
|
+
export { default as NewExpression } from './NewExpression';
|
12
|
+
export { default as AssignmentExpression } from './AssignmentExpression';
|
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.ChainExpression = exports.MemberExpression = exports.ArrowFunctionExpression = exports.CallExpression = exports.ConditionalExpression = exports.LogicalExpression = exports.UnaryExpression = exports.BinaryExpression = exports.ObjectExpression = exports.ArrayExpression =
|
7
|
-
var ExpressionStatement_1 = require("./ExpressionStatement");
|
8
|
-
Object.defineProperty(exports, "ExpressionStatement", { enumerable: true, get: function () { return __importDefault(ExpressionStatement_1).default; } });
|
6
|
+
exports.AssignmentExpression = exports.NewExpression = exports.ChainExpression = exports.MemberExpression = exports.ArrowFunctionExpression = exports.CallExpression = exports.ConditionalExpression = exports.LogicalExpression = exports.UnaryExpression = exports.BinaryExpression = exports.ObjectExpression = exports.ArrayExpression = void 0;
|
9
7
|
var ArrayExpression_1 = require("./ArrayExpression");
|
10
8
|
Object.defineProperty(exports, "ArrayExpression", { enumerable: true, get: function () { return __importDefault(ArrayExpression_1).default; } });
|
11
9
|
var ObjectExpression_1 = require("./ObjectExpression");
|
@@ -26,3 +24,7 @@ var MemberExpression_1 = require("./MemberExpression");
|
|
26
24
|
Object.defineProperty(exports, "MemberExpression", { enumerable: true, get: function () { return __importDefault(MemberExpression_1).default; } });
|
27
25
|
var ChainExpression_1 = require("./ChainExpression");
|
28
26
|
Object.defineProperty(exports, "ChainExpression", { enumerable: true, get: function () { return __importDefault(ChainExpression_1).default; } });
|
27
|
+
var NewExpression_1 = require("./NewExpression");
|
28
|
+
Object.defineProperty(exports, "NewExpression", { enumerable: true, get: function () { return __importDefault(NewExpression_1).default; } });
|
29
|
+
var AssignmentExpression_1 = require("./AssignmentExpression");
|
30
|
+
Object.defineProperty(exports, "AssignmentExpression", { enumerable: true, get: function () { return __importDefault(AssignmentExpression_1).default; } });
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { ArrayExpression, ArrowFunctionExpression, BinaryExpression, CallExpression, ChainExpression, ConditionalExpression,
|
1
|
+
import { ArrayExpression, ArrowFunctionExpression, AssignmentExpression, BinaryExpression, CallExpression, ChainExpression, ConditionalExpression, LogicalExpression, MemberExpression, NewExpression, ObjectExpression, UnaryExpression } from './expressions';
|
2
|
+
import { BlockStatement, ExpressionStatement, ReturnStatement, SwitchStatement } from './statements';
|
2
3
|
import { AnyNode } from 'acorn';
|
3
4
|
import type Context from '../Context';
|
4
5
|
import Identifier from './Identifier';
|
@@ -6,6 +7,7 @@ import Literal from './Literal';
|
|
6
7
|
import Node from './Node';
|
7
8
|
import Program from './Program';
|
8
9
|
import TemplateLiteral from './TemplateLiteral';
|
10
|
+
import VariableDeclaration from './VariableDeclaration';
|
9
11
|
type NodeConstructor = {
|
10
12
|
new (node: AnyNode, scope: Context): Node<AnyNode>;
|
11
13
|
};
|
@@ -27,6 +29,12 @@ declare const nodes: {
|
|
27
29
|
readonly CallExpression: typeof CallExpression;
|
28
30
|
readonly MemberExpression: typeof MemberExpression;
|
29
31
|
readonly ChainExpression: typeof ChainExpression;
|
32
|
+
readonly NewExpression: typeof NewExpression;
|
33
|
+
readonly BlockStatement: typeof BlockStatement;
|
34
|
+
readonly ReturnStatement: typeof ReturnStatement;
|
35
|
+
readonly VariableDeclaration: typeof VariableDeclaration;
|
36
|
+
readonly AssignmentExpression: typeof AssignmentExpression;
|
37
|
+
readonly SwitchStatement: typeof SwitchStatement;
|
30
38
|
};
|
31
39
|
export type NodeType = keyof typeof nodes;
|
32
40
|
declare const _default: NodeMap;
|
@@ -4,14 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const expressions_1 = require("./expressions");
|
7
|
+
const statements_1 = require("./statements");
|
7
8
|
const Identifier_1 = __importDefault(require("./Identifier"));
|
8
9
|
const Literal_1 = __importDefault(require("./Literal"));
|
9
10
|
const Program_1 = __importDefault(require("./Program"));
|
10
11
|
const TemplateLiteral_1 = __importDefault(require("./TemplateLiteral"));
|
12
|
+
const VariableDeclaration_1 = __importDefault(require("./VariableDeclaration"));
|
11
13
|
const nodes = {
|
12
14
|
Program: Program_1.default,
|
13
15
|
Literal: Literal_1.default,
|
14
|
-
ExpressionStatement:
|
16
|
+
ExpressionStatement: statements_1.ExpressionStatement,
|
15
17
|
ArrayExpression: expressions_1.ArrayExpression,
|
16
18
|
ObjectExpression: expressions_1.ObjectExpression,
|
17
19
|
Identifier: Identifier_1.default,
|
@@ -25,5 +27,11 @@ const nodes = {
|
|
25
27
|
CallExpression: expressions_1.CallExpression,
|
26
28
|
MemberExpression: expressions_1.MemberExpression,
|
27
29
|
ChainExpression: expressions_1.ChainExpression,
|
30
|
+
NewExpression: expressions_1.NewExpression,
|
31
|
+
BlockStatement: statements_1.BlockStatement,
|
32
|
+
ReturnStatement: statements_1.ReturnStatement,
|
33
|
+
VariableDeclaration: VariableDeclaration_1.default,
|
34
|
+
AssignmentExpression: expressions_1.AssignmentExpression,
|
35
|
+
SwitchStatement: statements_1.SwitchStatement,
|
28
36
|
};
|
29
37
|
exports.default = new Map(Object.entries(nodes));
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { AnyNode, BlockStatement } from 'acorn';
|
2
|
+
import Context from '../../Context';
|
3
|
+
import Node from '../Node';
|
4
|
+
export default class BlockStatementNode extends Node<BlockStatement> {
|
5
|
+
constructor(node: AnyNode, context: Context);
|
6
|
+
validate(validateChildren?: boolean): void;
|
7
|
+
run(): unknown;
|
8
|
+
}
|
@@ -0,0 +1,29 @@
|
|
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
|
+
const Node_1 = __importDefault(require("../Node"));
|
7
|
+
const utils_1 = require("../../utils");
|
8
|
+
class BlockStatementNode extends Node_1.default {
|
9
|
+
constructor(node, context) {
|
10
|
+
super(node, context.newChild(), 'BlockStatement');
|
11
|
+
}
|
12
|
+
validate(validateChildren = false) {
|
13
|
+
if (!validateChildren) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
for (const statement of this.node.body) {
|
17
|
+
(0, utils_1.construct)(statement, this.context).validate(true);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
run() {
|
21
|
+
this.validate();
|
22
|
+
let result;
|
23
|
+
for (const statement of this.node.body) {
|
24
|
+
result = (0, utils_1.construct)(statement, this.context).run();
|
25
|
+
}
|
26
|
+
return result;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.default = BlockStatementNode;
|
@@ -9,9 +9,16 @@ class ExpressionStatementNode extends Node_1.default {
|
|
9
9
|
constructor(node, context) {
|
10
10
|
super(node, context, 'ExpressionStatement');
|
11
11
|
}
|
12
|
-
|
12
|
+
validate(validateChildren = false) {
|
13
13
|
if (this.node.directive)
|
14
14
|
throw new Error('Directives are not supported');
|
15
|
+
if (!validateChildren) {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
(0, utils_1.construct)(this.node.expression, this.context).validate(true);
|
19
|
+
}
|
20
|
+
run() {
|
21
|
+
this.validate();
|
15
22
|
return (0, utils_1.construct)(this.node.expression, this.context).run();
|
16
23
|
}
|
17
24
|
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { AnyNode, ReturnStatement } from 'acorn';
|
2
|
+
import type Context from '../../Context';
|
3
|
+
import Node from '../Node';
|
4
|
+
export declare class ReturnStatementError extends Error {
|
5
|
+
readonly value: unknown;
|
6
|
+
constructor(value: unknown);
|
7
|
+
}
|
8
|
+
export default class ReturnStatementNode extends Node<ReturnStatement> {
|
9
|
+
constructor(node: AnyNode, context: Context);
|
10
|
+
validate(validateChildren?: boolean): void;
|
11
|
+
run(): unknown;
|
12
|
+
}
|
@@ -0,0 +1,33 @@
|
|
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
|
+
exports.ReturnStatementError = void 0;
|
7
|
+
const Node_1 = __importDefault(require("../Node"));
|
8
|
+
const utils_1 = require("../../utils");
|
9
|
+
class ReturnStatementError extends Error {
|
10
|
+
constructor(value) {
|
11
|
+
super('Illegal return statement');
|
12
|
+
this.value = value;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.ReturnStatementError = ReturnStatementError;
|
16
|
+
class ReturnStatementNode extends Node_1.default {
|
17
|
+
constructor(node, context) {
|
18
|
+
super(node, context, 'ReturnStatement');
|
19
|
+
}
|
20
|
+
validate(validateChildren = false) {
|
21
|
+
const arg = this.node.argument;
|
22
|
+
if (!validateChildren || arg === undefined || arg === null) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
(0, utils_1.construct)(arg, this.context).validate(true);
|
26
|
+
}
|
27
|
+
run() {
|
28
|
+
this.validate();
|
29
|
+
const result = this.node.argument ? (0, utils_1.construct)(this.node.argument, this.context).run() : undefined;
|
30
|
+
throw new ReturnStatementError(result);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
exports.default = ReturnStatementNode;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { AnyNode, SwitchStatement } from 'acorn';
|
2
|
+
import Context from '../../Context';
|
3
|
+
import Node from '../Node';
|
4
|
+
export default class SwitchStatementNode extends Node<SwitchStatement> {
|
5
|
+
constructor(node: AnyNode, context: Context);
|
6
|
+
private test_match;
|
7
|
+
validate(validateChildren?: boolean): void;
|
8
|
+
run(): unknown;
|
9
|
+
}
|
@@ -0,0 +1,52 @@
|
|
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
|
+
const Node_1 = __importDefault(require("../Node"));
|
7
|
+
const utils_1 = require("../../utils");
|
8
|
+
class SwitchStatementNode extends Node_1.default {
|
9
|
+
constructor(node, context) {
|
10
|
+
super(node, context, 'SwitchStatement');
|
11
|
+
}
|
12
|
+
test_match(test, discriminant) {
|
13
|
+
if (!test) {
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
const testValue = (0, utils_1.construct)(test, this.context).run();
|
17
|
+
return testValue === discriminant;
|
18
|
+
}
|
19
|
+
validate(validateChildren = false) {
|
20
|
+
if (!validateChildren) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
(0, utils_1.construct)(this.node.discriminant, this.context).validate(true);
|
24
|
+
for (const c of this.node.cases) {
|
25
|
+
if (c.test) {
|
26
|
+
(0, utils_1.construct)(c.test, this.context).validate(true);
|
27
|
+
}
|
28
|
+
for (const s of c.consequent) {
|
29
|
+
(0, utils_1.construct)(s, this.context).validate(true);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
run() {
|
34
|
+
this.validate();
|
35
|
+
const discriminant = (0, utils_1.construct)(this.node.discriminant, this.context).run();
|
36
|
+
let result;
|
37
|
+
let matched = false;
|
38
|
+
for (const c of this.node.cases) {
|
39
|
+
if (!matched && this.test_match(c.test, discriminant)) {
|
40
|
+
matched = true;
|
41
|
+
}
|
42
|
+
if (!matched) {
|
43
|
+
continue;
|
44
|
+
}
|
45
|
+
for (const s of c.consequent) {
|
46
|
+
result = (0, utils_1.construct)(s, this.context).run();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.default = SwitchStatementNode;
|