@ohm-js/wasm 0.6.13 → 0.6.15
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CstNode, CstNodeChildren, MatchResult, NonterminalNode, TerminalNode } from './miniohm.ts';
|
|
2
2
|
export type AstNodeTemplate<R> = {
|
|
3
|
-
[property: string]: number | string | boolean | object | null | ((children: CstNodeChildren) => R);
|
|
3
|
+
[property: string]: number | string | boolean | object | null | ((this: CstNode, children: CstNodeChildren) => R);
|
|
4
4
|
};
|
|
5
5
|
export type AstMapping<R> = Record<string, AstNodeTemplate<R> | number | ((this: CstNode, ...children: CstNodeChildren) => R)>;
|
|
6
6
|
export declare function createToAst<TNode = any>(mapping: AstMapping<TNode>, opts?: {
|
package/dist/src/createToAst.js
CHANGED
|
@@ -91,7 +91,7 @@ export class AstBuilder {
|
|
|
91
91
|
}
|
|
92
92
|
else if (typeof mappedProp === 'function') {
|
|
93
93
|
// computed value
|
|
94
|
-
ans[prop] = mappedProp.call(this, children);
|
|
94
|
+
ans[prop] = mappedProp.call(this.currNode, children);
|
|
95
95
|
}
|
|
96
96
|
else if (mappedProp === undefined) {
|
|
97
97
|
const child = children[Number(prop)];
|
|
@@ -129,7 +129,7 @@ export class AstBuilder {
|
|
|
129
129
|
this.currNode = node;
|
|
130
130
|
ans =
|
|
131
131
|
typeof this._mapping[node.ctorName] === 'function'
|
|
132
|
-
? this._mapping[node.ctorName].apply(this, node.children)
|
|
132
|
+
? this._mapping[node.ctorName].apply(this.currNode, node.children)
|
|
133
133
|
: this._visitNonterminal(node);
|
|
134
134
|
this.currNode = undefined;
|
|
135
135
|
}
|
package/dist/src/miniohm.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export interface TerminalNode extends CstNodeBase {
|
|
|
71
71
|
type: typeof CstNodeType.TERMINAL;
|
|
72
72
|
ctorName: '_terminal';
|
|
73
73
|
leadingSpaces?: NonterminalNode;
|
|
74
|
+
children: readonly [];
|
|
74
75
|
value: string;
|
|
75
76
|
}
|
|
76
77
|
export interface ListNode<TNode extends CstNode = CstNode> extends CstNodeBase {
|
package/dist/src/miniohm.js
CHANGED
|
@@ -15,6 +15,7 @@ export const CstNodeType = {
|
|
|
15
15
|
OPT: 3,
|
|
16
16
|
SEQ: 4,
|
|
17
17
|
};
|
|
18
|
+
const EMPTY_CHILDREN = Object.freeze([]);
|
|
18
19
|
const compileOptions = {
|
|
19
20
|
builtins: ['js-string'],
|
|
20
21
|
};
|
|
@@ -261,6 +262,9 @@ export class CstNodeImpl {
|
|
|
261
262
|
startIdx,
|
|
262
263
|
endIdx: startIdx + this.sourceString.length,
|
|
263
264
|
};
|
|
265
|
+
if (this.matchRecordType === MatchRecordType.TERMINAL || this.count === 0) {
|
|
266
|
+
this._children = EMPTY_CHILDREN;
|
|
267
|
+
}
|
|
264
268
|
}
|
|
265
269
|
get type() {
|
|
266
270
|
switch (this._typeAndDetails & MATCH_RECORD_TYPE_MASK) {
|