@weborigami/language 0.6.14 → 0.6.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/language",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
4
4
  "description": "Web Origami expression language compiler and runtime",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -11,7 +11,7 @@
11
11
  "typescript": "5.9.3"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/async-tree": "0.6.14",
14
+ "@weborigami/async-tree": "0.6.16",
15
15
  "exif-parser": "0.1.12",
16
16
  "watcher": "2.3.1",
17
17
  "yaml": "2.8.2"
@@ -1,7 +1,8 @@
1
1
  import { Mixin } from "../../index.ts";
2
2
 
3
3
  declare const WatchFilesMixin: Mixin<{
4
- watch(): Promise<void>;
4
+ unwatch(): void;
5
+ watch(): void;
5
6
  }>;
6
7
 
7
8
  export default WatchFilesMixin;
@@ -27,7 +27,7 @@ export default function WatchFilesMixin(Base) {
27
27
  this.dispatchEvent(new TreeEvent("change", { filePath }));
28
28
  }
29
29
 
30
- async unwatch() {
30
+ unwatch() {
31
31
  if (!this.watching) {
32
32
  return;
33
33
  }
@@ -37,7 +37,7 @@ export default function WatchFilesMixin(Base) {
37
37
  }
38
38
 
39
39
  // Turn on watching for the directory.
40
- async watch() {
40
+ watch() {
41
41
  if (this.watching) {
42
42
  return;
43
43
  }
@@ -27,8 +27,9 @@ export default async function explainTraverseError(error) {
27
27
  }
28
28
 
29
29
  // The key that caused the error is the one before the current position
30
- const path = pathFromKeys(keys.slice(0, position));
31
- let message = `The path traversal ended unexpectedly at: ${path}`;
30
+ const path = pathFromKeys(keys);
31
+ const problemKey = keys[position - 1];
32
+ let message = `Tried to traverse path: ${path}\nStopped unexpectedly at: ${problemKey}`;
32
33
 
33
34
  const key = trailingSlash.remove(keys[position - 1]);
34
35
 
@@ -92,7 +92,7 @@ export async function cache(cache, path, code) {
92
92
  }
93
93
 
94
94
  // Don't await: might get another request for this before promise resolves
95
- const promise = await execute(code);
95
+ const promise = execute(code);
96
96
 
97
97
  // Save promise so another request will get the same promise
98
98
  cache[path] = promise;
@@ -178,7 +178,10 @@ addOpLabel(exponentiation, "«ops.exponentiation»");
178
178
  * @param {...any} args
179
179
  */
180
180
  export async function flat(...args) {
181
- return Tree.flat(args);
181
+ // Unpack packed arguments so they can be flattened
182
+ const unpacked = args.map((arg) => (isUnpackable(arg) ? arg.unpack() : arg));
183
+ // Flatten to depth 2: 1 for args array, 1 for flattening
184
+ return Tree.flat(unpacked, 2);
182
185
  }
183
186
  addOpLabel(flat, "«ops.flat»");
184
187
 
@@ -258,7 +261,8 @@ export function lambda(length, parameters, code, state = {}) {
258
261
  // interim stack frame.
259
262
  const interimStack = stack.slice();
260
263
  interimStack.push(args);
261
- const frame = await expressionObject(parameters, { stack: interimStack });
264
+ const paramState = { ...state, stack: interimStack };
265
+ const frame = await expressionObject(parameters, paramState);
262
266
  // Record which code this stack frame is associated with
263
267
  Object.defineProperty(frame, codeSymbol, {
264
268
  value: code,
@@ -210,7 +210,8 @@ evaluating: \x1B[31mrepeat\x1B[0m`,
210
210
  await assertError(
211
211
  `a/b/sup/c`,
212
212
  `TraverseError: A path hit a null or undefined value.
213
- The path traversal ended unexpectedly at: a/b/sup/
213
+ Tried to traverse path: a/b/sup/c
214
+ Stopped unexpectedly at: sup/
214
215
  Perhaps you intended: sub/
215
216
  evaluating: \x1B[31msup/\x1B[0m`,
216
217
  { parent },
@@ -224,7 +225,8 @@ evaluating: \x1B[31msup/\x1B[0m`,
224
225
  await assertError(
225
226
  `map/1/a`,
226
227
  `TraverseError: A path hit a null or undefined value.
227
- The path traversal ended unexpectedly at: map/1/
228
+ Tried to traverse path: map/1/a
229
+ Stopped unexpectedly at: 1/
228
230
  Slash-separated keys are searched as strings. Here there's no string "1" key, but there is a number 1 key.
229
231
  To get the value for that number key, use parentheses: map/(1)
230
232
  evaluating: \x1B[31m1/\x1B[0m`,
@@ -239,25 +241,27 @@ evaluating: \x1B[31m1/\x1B[0m`,
239
241
  await assertError(
240
242
  `file.foo/bar`,
241
243
  `TraverseError: A path hit binary file data that can't be unpacked.
242
- The path traversal ended unexpectedly at: file.foo/
244
+ Tried to traverse path: file.foo/bar
245
+ Stopped unexpectedly at: file.foo/
243
246
  The value couldn't be unpacked because no file extension handler is registered for ".foo".
244
247
  evaluating: \x1B[31mfile.foo/\x1B[0m`,
245
248
  { parent },
246
249
  );
247
250
  });
248
251
 
249
- test("identifies when a value didn't need to be unpacked", async () => {
252
+ test("identifies when data was already unpacked", async () => {
250
253
  const parent = {
251
254
  a: {
252
- b: 1,
255
+ "b.json": 1,
253
256
  },
254
257
  };
255
258
  await assertError(
256
- `a/b/`,
259
+ `a/b.json/`,
257
260
  `TraverseError: A path tried to unpack data that's already unpacked.
258
- The path traversal ended unexpectedly at: a/b/
259
- You can drop the trailing slash and just use: b
260
- evaluating: \x1B[31mb/\x1B[0m`,
261
+ Tried to traverse path: a/b.json/
262
+ Stopped unexpectedly at: b.json/
263
+ You can drop the trailing slash and just use: b.json
264
+ evaluating: \x1B[31mb.json/\x1B[0m`,
261
265
  { parent },
262
266
  );
263
267
  });
@@ -269,7 +273,8 @@ evaluating: \x1B[31mb/\x1B[0m`,
269
273
  await assertError(
270
274
  `a/b/`,
271
275
  `TraverseError: A path tried to unpack a value that doesn't exist.
272
- The path traversal ended unexpectedly at: a/b/
276
+ Tried to traverse path: a/b/
277
+ Stopped unexpectedly at: b/
273
278
  evaluating: \x1B[31mb/\x1B[0m`,
274
279
  { parent },
275
280
  );
@@ -158,7 +158,8 @@ describe("ops", () => {
158
158
  d: 4,
159
159
  });
160
160
  const array = [5, 6];
161
- const result = await ops.flat(object, tree, array);
161
+ const set = new Set([7, 8]);
162
+ const result = await ops.flat(object, tree, array, set);
162
163
  assert.deepEqual(await Tree.plain(result), {
163
164
  a: 1,
164
165
  b: 2,
@@ -166,6 +167,8 @@ describe("ops", () => {
166
167
  d: 4,
167
168
  0: 5,
168
169
  1: 6,
170
+ 2: 7,
171
+ 3: 8,
169
172
  });
170
173
  });
171
174
  });