Skip to content

Commit 6d7cbee

Browse files
authored
Merge pull request #18 from lark-parser/issue17
Fix for issue #17: Renaming classes breaks deserialization
2 parents 0626280 + 18a482b commit 6d7cbee

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

larkjs/lark.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,6 @@ function _deserialize(data, namespace, memo) {
698698
class Serialize {
699699
static deserialize(data, memo) {
700700
const cls = this;
701-
let namespace = (cls && cls["__serialize_namespace__"]) || [];
702-
namespace = Object.fromEntries(namespace.map((c) => [c.name, c]));
703701
let fields = cls && cls["__serialize_fields__"];
704702
if ("@" in data) {
705703
return memo[data["@"]];
@@ -708,7 +706,7 @@ class Serialize {
708706
let inst = new_object(cls);
709707
for (const f of fields) {
710708
if (data && f in data) {
711-
inst[f] = _deserialize(data[f], namespace, memo);
709+
inst[f] = _deserialize(data[f], NAMESPACE, memo);
712710
} else {
713711
throw new KeyError("Cannot find key for class", cls, e);
714712
}
@@ -3911,6 +3909,16 @@ class PythonIndenter extends Indenter {
39113909
return this.constructor.tab_len;
39123910
}
39133911
}
3912+
3913+
const NAMESPACE = {
3914+
Terminal: Terminal,
3915+
NonTerminal: NonTerminal,
3916+
RuleOptions: RuleOptions,
3917+
PatternStr: PatternStr,
3918+
PatternRE: PatternRE,
3919+
TerminalDef: TerminalDef
3920+
}
3921+
39143922
module.exports = {
39153923
LarkError,
39163924
ConfigurationError,

0 commit comments

Comments
 (0)