@ohm-js/wasm 0.6.4 → 0.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.
@@ -61,6 +61,7 @@ export declare class CstNode {
61
61
  isLexical(ruleName?: string): boolean;
62
62
  toString(): string;
63
63
  map<T>(callbackFn: (...args: CstNode[]) => T): T[];
64
+ unpack<T>(someFn: (...args: CstNode[]) => T, noneFn: () => T): T;
64
65
  }
65
66
  export declare function dumpCstNode(node: CstNode, depth?: number): void;
66
67
  export declare class MatchResult {
@@ -328,6 +328,7 @@ export class CstNode {
328
328
  const { sourceString, startIdx } = this;
329
329
  return `CstNode {ctorName: ${ctorName}, sourceString: ${sourceString}, startIdx: ${startIdx} }`;
330
330
  }
331
+ // Other possible names: collect, mapChildren, mapUnpack, unpackEach, …
331
332
  map(callbackFn) {
332
333
  const { arity, children } = this;
333
334
  assert(callbackFn.length === arity, 'bad arity');
@@ -337,6 +338,13 @@ export class CstNode {
337
338
  }
338
339
  return ans;
339
340
  }
341
+ unpack(someFn, noneFn) {
342
+ assert(this.isOptional(), 'Not an optional');
343
+ if (this.children.length === 0)
344
+ return noneFn();
345
+ assert(someFn.length === this.children.length, `bad arity: expected ${this.children.length}, got ${someFn.length}`);
346
+ return someFn(...this.children);
347
+ }
340
348
  }
341
349
  export function dumpCstNode(node, depth = 0) {
342
350
  const { _base, children, ctorName, matchLength, startIdx } = node;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@ohm-js/wasm",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Compile Ohm.js grammars to WebAsssembly",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/index.js",
8
+ "default": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts"
10
10
  },
11
11
  "./compat": {
12
- "import": "./dist/src/compat.js",
12
+ "default": "./dist/src/compat.js",
13
13
  "types": "./dist/src/compat.d.ts"
14
14
  },
15
15
  "./compiler": {
16
- "import": "./dist/src/Compiler.js",
16
+ "default": "./dist/src/Compiler.js",
17
17
  "types": "./dist/src/Compiler.d.ts"
18
18
  }
19
19
  },