From 45f3da23adead2fae573d8c762c1cf1a1942a82e Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 4 Apr 2024 22:05:53 +0200 Subject: [PATCH] JavaScript: use `this` as default `_root` only in top-level types See the same change in Lua: 1a0b2c07e5ced55319c18f62d41876159e1b1a62 This would have fixed the `NestedTypesImport` test for JavaScript if it weren't for the missing import of `NestedTypes3` it uses (in other words, this test still fails only because of https://github.com/kaitai-io/kaitai_struct/issues/703). --- .../io/kaitai/struct/languages/JavaScriptCompiler.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala index 68379985d..ae2408b46 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -97,7 +97,11 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.inc out.puts("this._io = _io;") out.puts("this._parent = _parent;") - out.puts("this._root = _root || this;") + if (name == rootClassName) { + out.puts("this._root = _root || this;") + } else { + out.puts("this._root = _root;") + } if (isHybrid) out.puts("this._is_le = _is_le;")