greybel-interpreter 2.1.1 → 2.1.3

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/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { ASTBase } from 'greyscript-core';
3
2
  import { EventEmitter } from 'events';
3
+ import { ASTBase } from 'greyscript-core';
4
4
  import { CPS } from './cps';
5
5
  import { HandlerContainer } from './handler-container';
6
6
  import { Operation } from './operations/operation';
package/dist/cps.js CHANGED
@@ -83,14 +83,15 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
83
83
  const importExpr = item;
84
84
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
85
85
  if (stack.includes(target)) {
86
- console.warn(`Found circluar dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
86
+ console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
87
87
  return new noop_1.Noop(item, target);
88
88
  }
89
89
  const code = yield context.handler.resourceHandler.get(target);
90
90
  if (code == null) {
91
- throw new error_1.PrepareError(`Cannot find import "${currentTarget}" at line ${item.start.line}.`, {
91
+ const range = new greyscript_core_1.ASTRange(item.start, item.end);
92
+ throw new error_1.PrepareError(`Cannot find import "${currentTarget}"`, {
92
93
  target: currentTarget,
93
- item
94
+ range
94
95
  });
95
96
  }
96
97
  try {
@@ -104,7 +105,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
104
105
  }
105
106
  throw new error_1.PrepareError(err.message, {
106
107
  target,
107
- item
108
+ range: new greyscript_core_1.ASTRange(item.start, item.end)
108
109
  }, err);
109
110
  }
110
111
  }
@@ -112,14 +113,15 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
112
113
  const includeExpr = item;
113
114
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
114
115
  if (stack.includes(target)) {
115
- console.warn(`Found circluar dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
116
+ console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
116
117
  return new noop_1.Noop(item, target);
117
118
  }
118
119
  const code = yield context.handler.resourceHandler.get(target);
119
120
  if (code == null) {
120
- throw new error_1.PrepareError(`Cannot find include "${currentTarget}" at line ${item.start.line}.`, {
121
+ const range = new greyscript_core_1.ASTRange(item.start, item.end);
122
+ throw new error_1.PrepareError(`Cannot find include "${currentTarget}"`, {
121
123
  target: currentTarget,
122
- item
124
+ range
123
125
  });
124
126
  }
125
127
  try {
@@ -133,7 +135,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
133
135
  }
134
136
  throw new error_1.PrepareError(err.message, {
135
137
  target,
136
- item
138
+ range: new greyscript_core_1.ASTRange(item.start, item.end)
137
139
  }, err);
138
140
  }
139
141
  }
@@ -141,14 +143,15 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
141
143
  const importExpr = item;
142
144
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.directory);
143
145
  if (stack.includes(target)) {
144
- console.warn(`Found circluar dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
146
+ console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
145
147
  return new noop_1.Noop(item, target);
146
148
  }
147
149
  const code = yield context.handler.resourceHandler.get(target);
148
150
  if (code == null) {
149
- throw new error_1.PrepareError(`Cannot find native import "${currentTarget}" at line ${item.start.line}.`, {
151
+ const range = new greyscript_core_1.ASTRange(item.start, item.end);
152
+ throw new error_1.PrepareError(`Cannot find native import "${currentTarget}"`, {
150
153
  target: currentTarget,
151
- item
154
+ range
152
155
  });
153
156
  }
154
157
  try {
@@ -162,7 +165,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
162
165
  }
163
166
  throw new error_1.PrepareError(err.message, {
164
167
  target,
165
- item
168
+ range: new greyscript_core_1.ASTRange(item.start, item.end)
166
169
  }, err);
167
170
  }
168
171
  }
@@ -193,8 +196,10 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
193
196
  else if (unaryExpr.operator === '@') {
194
197
  return new function_reference_1.FunctionReference(unaryExpr).build(defaultVisit);
195
198
  }
196
- throw new error_1.RuntimeError('Unknown unary expression.', {
197
- target: currentTarget
199
+ const range = new greyscript_core_1.ASTRange(item.start, item.end);
200
+ throw new error_1.PrepareError(`Unknown unary expression`, {
201
+ target: currentTarget,
202
+ range
198
203
  });
199
204
  }
200
205
  case greyscript_core_1.ASTType.Chunk:
@@ -204,8 +209,10 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
204
209
  case greyscript_core_1.ASTType.ParenthesisExpression:
205
210
  return defaultVisit(item.expression);
206
211
  default:
207
- throw new error_1.RuntimeError(`Unexpected AST type ${item.type}.`, {
208
- target: currentTarget
212
+ const range = new greyscript_core_1.ASTRange(item.start, item.end);
213
+ throw new error_1.PrepareError(`Unexpected AST type ${item.type}`, {
214
+ target: currentTarget,
215
+ range
209
216
  });
210
217
  }
211
218
  });
@@ -94,7 +94,7 @@ class Interpreter extends events_1.EventEmitter {
94
94
  }
95
95
  else {
96
96
  this.handler.errorHandler.raise(new error_1.PrepareError(err.message, {
97
- item: null,
97
+ range: err.range,
98
98
  target: this.target
99
99
  }));
100
100
  }
@@ -1,4 +1,4 @@
1
- import { ASTBase } from 'greyscript-core';
1
+ import { ASTRange } from 'greyscript-core';
2
2
  import { Operation } from '../operations/operation';
3
3
  interface RuntimeContext {
4
4
  stackTrace?: Operation[];
@@ -12,12 +12,12 @@ export declare class RuntimeError extends Error {
12
12
  private createTrace;
13
13
  }
14
14
  interface PrepareContext {
15
- item: ASTBase;
15
+ range: ASTRange;
16
16
  target: string;
17
17
  }
18
18
  export declare class PrepareError extends Error {
19
- relatedItem: ASTBase | null;
20
- relatedTarget: string;
19
+ range: ASTRange;
20
+ target: string;
21
21
  source?: Error;
22
22
  constructor(message: string, context: PrepareContext, source?: Error);
23
23
  }
@@ -22,8 +22,8 @@ exports.RuntimeError = RuntimeError;
22
22
  class PrepareError extends Error {
23
23
  constructor(message, context, source) {
24
24
  super(message);
25
- this.relatedItem = context.item;
26
- this.relatedTarget = context.target;
25
+ this.range = context.range;
26
+ this.target = context.target;
27
27
  this.source = source;
28
28
  }
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -48,8 +48,8 @@
48
48
  "typescript": "^5.0.4"
49
49
  },
50
50
  "dependencies": {
51
- "greybel-core": "^0.9.1",
52
- "greyscript-core": "^0.9.1"
51
+ "greybel-core": "^0.9.3",
52
+ "greyscript-core": "^0.9.5"
53
53
  },
54
54
  "keywords": [
55
55
  "greyscript",