@ohm-js/wasm 0.6.13 → 0.6.14
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
|
}
|