greybel-interpreter 1.6.5 → 1.6.7

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 (2) hide show
  1. package/dist/cps.js +19 -6
  2. 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, currentTarget, item) => __awaiter(void 0, void 0, void 0, function* () {
50
- const defaultVisit = visit.bind(null, context, currentTarget);
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,33 +84,45 @@ 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
+ }
86
91
  const code = yield context.handler.resourceHandler.get(target);
87
92
  if (code == null) {
88
93
  throw new Error(`Cannot find import ${currentTarget}.`);
89
94
  }
90
- const subVisit = visit.bind(null, context, target);
95
+ const subVisit = visit.bind(null, context, [...stack, target]);
91
96
  const importStatement = yield new import_1.default(importExpr, target, code).build(subVisit);
92
97
  return importStatement;
93
98
  }
94
99
  case greybel_core_1.ASTType.FeatureIncludeExpression: {
95
100
  const includeExpr = item;
96
101
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
102
+ if (stack.includes(target)) {
103
+ console.warn('Found circluar dependency. Using noop operation.');
104
+ return new noop_1.default(item, target);
105
+ }
97
106
  const code = yield context.handler.resourceHandler.get(target);
98
107
  if (code == null) {
99
108
  throw new Error(`Cannot find include ${currentTarget}.`);
100
109
  }
101
- const subVisit = visit.bind(null, context, target);
110
+ const subVisit = visit.bind(null, context, [...stack, target]);
102
111
  const importStatement = yield new include_1.default(includeExpr, target, code).build(subVisit);
103
112
  return importStatement;
104
113
  }
105
114
  case greyscript_core_1.ASTType.ImportCodeExpression: {
106
115
  const importExpr = item;
107
116
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.fileSystemDirectory);
117
+ if (stack.includes(target)) {
118
+ console.warn('Found circluar dependency. Using noop operation.');
119
+ return new noop_1.default(item, target);
120
+ }
108
121
  const code = yield context.handler.resourceHandler.get(target);
109
122
  if (code == null) {
110
123
  throw new Error(`Cannot find native import ${currentTarget}.`);
111
124
  }
112
- const subVisit = visit.bind(null, context, target);
125
+ const subVisit = visit.bind(null, context, [...stack, target]);
113
126
  const importStatement = yield new include_1.default(importExpr, target, code).build(subVisit);
114
127
  return importStatement;
115
128
  }
@@ -155,7 +168,7 @@ const visit = (context, currentTarget, item) => __awaiter(void 0, void 0, void 0
155
168
  class CPS {
156
169
  constructor(context) {
157
170
  this.context = context;
158
- this.__visit = visit.bind(null, context, context.target);
171
+ this.__visit = visit.bind(null, context, [context.target]);
159
172
  }
160
173
  visit(item) {
161
174
  return this.__visit(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",