greybel-interpreter 1.6.5 → 1.6.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.
- package/dist/cps.js +25 -6
- package/package.json +1 -1
package/dist/cps.js
CHANGED
|
@@ -46,8 +46,9 @@ class CPSContext {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
exports.CPSContext = CPSContext;
|
|
49
|
-
const visit = (context,
|
|
50
|
-
const
|
|
49
|
+
const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const currentTarget = stack[stack.length - 1];
|
|
51
|
+
const defaultVisit = visit.bind(null, context, stack);
|
|
51
52
|
switch (item.type) {
|
|
52
53
|
case greyscript_core_1.ASTType.MapConstructorExpression:
|
|
53
54
|
return new map_1.default(item, currentTarget).build(defaultVisit);
|
|
@@ -83,34 +84,52 @@ const visit = (context, currentTarget, item) => __awaiter(void 0, void 0, void 0
|
|
|
83
84
|
case greybel_core_1.ASTType.FeatureImportExpression: {
|
|
84
85
|
const importExpr = item;
|
|
85
86
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
|
|
87
|
+
if (stack.includes(target)) {
|
|
88
|
+
console.warn('Found circluar dependency. Using noop operation.');
|
|
89
|
+
return new noop_1.default(item, target);
|
|
90
|
+
}
|
|
91
|
+
stack.push(target);
|
|
86
92
|
const code = yield context.handler.resourceHandler.get(target);
|
|
87
93
|
if (code == null) {
|
|
88
94
|
throw new Error(`Cannot find import ${currentTarget}.`);
|
|
89
95
|
}
|
|
90
|
-
const subVisit = visit.bind(null, context,
|
|
96
|
+
const subVisit = visit.bind(null, context, stack);
|
|
91
97
|
const importStatement = yield new import_1.default(importExpr, target, code).build(subVisit);
|
|
98
|
+
stack.pop();
|
|
92
99
|
return importStatement;
|
|
93
100
|
}
|
|
94
101
|
case greybel_core_1.ASTType.FeatureIncludeExpression: {
|
|
95
102
|
const includeExpr = item;
|
|
96
103
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
|
|
104
|
+
if (stack.includes(target)) {
|
|
105
|
+
console.warn('Found circluar dependency. Using noop operation.');
|
|
106
|
+
return new noop_1.default(item, target);
|
|
107
|
+
}
|
|
108
|
+
stack.push(target);
|
|
97
109
|
const code = yield context.handler.resourceHandler.get(target);
|
|
98
110
|
if (code == null) {
|
|
99
111
|
throw new Error(`Cannot find include ${currentTarget}.`);
|
|
100
112
|
}
|
|
101
|
-
const subVisit = visit.bind(null, context,
|
|
113
|
+
const subVisit = visit.bind(null, context, stack);
|
|
102
114
|
const importStatement = yield new include_1.default(includeExpr, target, code).build(subVisit);
|
|
115
|
+
stack.pop();
|
|
103
116
|
return importStatement;
|
|
104
117
|
}
|
|
105
118
|
case greyscript_core_1.ASTType.ImportCodeExpression: {
|
|
106
119
|
const importExpr = item;
|
|
107
120
|
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.fileSystemDirectory);
|
|
121
|
+
if (stack.includes(target)) {
|
|
122
|
+
console.warn('Found circluar dependency. Using noop operation.');
|
|
123
|
+
return new noop_1.default(item, target);
|
|
124
|
+
}
|
|
125
|
+
stack.push(target);
|
|
108
126
|
const code = yield context.handler.resourceHandler.get(target);
|
|
109
127
|
if (code == null) {
|
|
110
128
|
throw new Error(`Cannot find native import ${currentTarget}.`);
|
|
111
129
|
}
|
|
112
|
-
const subVisit = visit.bind(null, context,
|
|
130
|
+
const subVisit = visit.bind(null, context, stack);
|
|
113
131
|
const importStatement = yield new include_1.default(importExpr, target, code).build(subVisit);
|
|
132
|
+
stack.pop();
|
|
114
133
|
return importStatement;
|
|
115
134
|
}
|
|
116
135
|
case greybel_core_1.ASTType.FeatureDebuggerExpression:
|
|
@@ -155,7 +174,7 @@ const visit = (context, currentTarget, item) => __awaiter(void 0, void 0, void 0
|
|
|
155
174
|
class CPS {
|
|
156
175
|
constructor(context) {
|
|
157
176
|
this.context = context;
|
|
158
|
-
this.__visit = visit.bind(null, context, context.target);
|
|
177
|
+
this.__visit = visit.bind(null, context, [context.target]);
|
|
159
178
|
}
|
|
160
179
|
visit(item) {
|
|
161
180
|
return this.__visit(item);
|