greybel-interpreter 2.3.2 → 2.3.4
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/dist/cps.js
CHANGED
|
@@ -32,7 +32,6 @@ const negated_binary_1 = require("./operations/negated-binary");
|
|
|
32
32
|
const new_instance_1 = require("./operations/new-instance");
|
|
33
33
|
const noop_1 = require("./operations/noop");
|
|
34
34
|
const not_1 = require("./operations/not");
|
|
35
|
-
const resolve_1 = require("./operations/resolve");
|
|
36
35
|
const return_1 = require("./operations/return");
|
|
37
36
|
const while_1 = require("./operations/while");
|
|
38
37
|
const error_1 = require("./utils/error");
|
|
@@ -56,12 +55,11 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
56
55
|
case greyscript_core_1.ASTType.AssignmentStatement:
|
|
57
56
|
return (0, create_assign_1.createAssign)(item, currentTarget).build(defaultVisit);
|
|
58
57
|
case greyscript_core_1.ASTType.MemberExpression:
|
|
58
|
+
case greyscript_core_1.ASTType.IndexExpression:
|
|
59
|
+
case greyscript_core_1.ASTType.SliceExpression:
|
|
59
60
|
return (0, create_resolve_1.createResolve)(item, currentTarget).build(defaultVisit);
|
|
60
61
|
case greyscript_core_1.ASTType.Identifier:
|
|
61
62
|
return (0, create_resolve_1.createIdentifierResolve)(item, currentTarget).build(defaultVisit);
|
|
62
|
-
case greyscript_core_1.ASTType.IndexExpression:
|
|
63
|
-
case greyscript_core_1.ASTType.SliceExpression:
|
|
64
|
-
return new resolve_1.Resolve(item, currentTarget).build(defaultVisit);
|
|
65
63
|
case greyscript_core_1.ASTType.FunctionDeclaration:
|
|
66
64
|
return new function_1.FunctionOperation(item, currentTarget).build(defaultVisit);
|
|
67
65
|
case greyscript_core_1.ASTType.InvalidCodeExpression:
|
|
@@ -108,20 +108,23 @@ class Resolve extends operation_1.Operation {
|
|
|
108
108
|
switch (node.type) {
|
|
109
109
|
case greyscript_core_1.ASTType.MemberExpression: {
|
|
110
110
|
const memberExpr = node;
|
|
111
|
-
|
|
111
|
+
if (memberExpr.base != null)
|
|
112
|
+
yield this.buildProcessor(memberExpr.base, visit);
|
|
112
113
|
yield this.buildProcessor(memberExpr.identifier, visit);
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
case greyscript_core_1.ASTType.IndexExpression: {
|
|
116
117
|
const indexExpr = node;
|
|
117
|
-
|
|
118
|
+
if (indexExpr.base != null)
|
|
119
|
+
yield this.buildProcessor(indexExpr.base, visit);
|
|
118
120
|
const indexSegment = new IndexSegment(yield visit(indexExpr.index));
|
|
119
121
|
this.path.push(indexSegment);
|
|
120
122
|
break;
|
|
121
123
|
}
|
|
122
124
|
case greyscript_core_1.ASTType.SliceExpression: {
|
|
123
125
|
const sliceExpr = node;
|
|
124
|
-
|
|
126
|
+
if (sliceExpr.base != null)
|
|
127
|
+
yield this.buildProcessor(sliceExpr.base, visit);
|
|
125
128
|
const left = yield visit(sliceExpr.left);
|
|
126
129
|
const right = yield visit(sliceExpr.right);
|
|
127
130
|
const sliceSegment = new SliceSegment(left, right);
|
|
@@ -34,21 +34,16 @@ const optResolveMap = {
|
|
|
34
34
|
outer: resolve_outer_1.ResolveOuter
|
|
35
35
|
};
|
|
36
36
|
function createResolve(item, target) {
|
|
37
|
-
if (item instanceof greyscript_core_1.ASTMemberExpression
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (item instanceof greyscript_core_1.ASTMemberExpression ||
|
|
38
|
+
item instanceof greyscript_core_1.ASTIndexExpression ||
|
|
39
|
+
item instanceof greyscript_core_1.ASTSliceExpression) {
|
|
40
|
+
const path = (0, lookup_path_1.lookupPath)(item);
|
|
40
41
|
if (path.length > 0 &&
|
|
41
|
-
path[0] instanceof greyscript_core_1.ASTMemberExpression &&
|
|
42
42
|
path[0].base instanceof greyscript_core_1.ASTIdentifier &&
|
|
43
43
|
hasOwnProperty.call(optResolveMap, path[0].base.name)) {
|
|
44
44
|
const OptResolve = optResolveMap[path[0].base.name];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return new OptResolve(right, target);
|
|
48
|
-
}
|
|
49
|
-
const newBase = path[1];
|
|
50
|
-
newBase.base = right;
|
|
51
|
-
return new OptResolve(memberExpr, target);
|
|
45
|
+
path[0].base = null;
|
|
46
|
+
return new OptResolve(item, target);
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
return new resolve_1.Resolve(item, target);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type PathItem =
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export declare function lookupPath(item: ASTMemberExpression): PathItem[];
|
|
1
|
+
import { ASTIndexExpression, ASTMemberExpression, ASTSliceExpression } from 'greyscript-core';
|
|
2
|
+
export type PathItem = ASTMemberExpression | ASTIndexExpression | ASTSliceExpression;
|
|
3
|
+
export declare function lookupPath(item: PathItem): PathItem[];
|