diff --git a/package-lock.json b/package-lock.json index 927ab698..534c08b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -768,9 +768,9 @@ "integrity": "sha512-81oxVi/OY+LrzgrONX7ciD1wtvq24nb2M9iYixRiQG+1hrDrDRqFVWuQzF1fUexh3Sg/ol6eMAz1MOVYFouzUg==" }, "node_modules/kaitai-struct-compiler": { - "version": "0.11.0-SNAPSHOT20231104.124722.3af7a08", - "resolved": "https://registry.npmjs.org/kaitai-struct-compiler/-/kaitai-struct-compiler-0.11.0-SNAPSHOT20231104.124722.3af7a08.tgz", - "integrity": "sha512-iZFRd7Md3tK8+WlD3WBmrIIPTEfmVWWMSNgfeiHOjDS8XAXZBvbvjdtkuMcUgJ1AMbZfozvKK4ecDy6x/scaig==" + "version": "0.11.0-SNAPSHOT20240221.132806.29d37b8", + "resolved": "https://registry.npmjs.org/kaitai-struct-compiler/-/kaitai-struct-compiler-0.11.0-SNAPSHOT20240221.132806.29d37b8.tgz", + "integrity": "sha512-MfDkn1rJaEtPHBmUqu8PqinQvsbbso2UOydT/hZ1NAITngKRoQC085pX42YL6YQfViLUQyHTFGPvJIldmqnUEg==" }, "node_modules/lie": { "version": "3.1.1", diff --git a/src/v1/kaitaiWorker.ts b/src/v1/kaitaiWorker.ts index 72a16ae4..40800ee7 100644 --- a/src/v1/kaitaiWorker.ts +++ b/src/v1/kaitaiWorker.ts @@ -51,7 +51,16 @@ function exportValue(obj: any, debug: IDebugInfo, path: string[], noLazy?: boole if (debug && debug.enumName) { result.enumName = debug.enumName; var enumObj = myself; - debug.enumName.split(".").forEach(p => enumObj = enumObj[p]); + var enumPath = debug.enumName.split("."); + + // Because of https://github.com/kaitai-io/kaitai_struct/issues/1074, + // KSC-generated modules export a plain object (not the constructor + // function directly) - for example, the exported value from the + // `Zip.js` module is `{ Zip: function (_io, _parent, _root) {...} }`. + // + // This means we have to use the top-level name twice in the path resolution. + enumPath.unshift(enumPath[0]); + enumPath.forEach(p => enumObj = enumObj[p]); var flagCheck = 0, flagSuccess = true; var flagStr = Object.keys(enumObj).filter(x => isNaN(x)).filter(x => { @@ -114,7 +123,7 @@ importScripts("../../lib/_npm/kaitai-struct/KaitaiStream.js"); var apiMethods = { initCode: (sourceCode: string, mainClassName: string, ksyTypes: IKsyTypes) => { wi.ksyTypes = ksyTypes; - eval(`${sourceCode}\nwi.MainClass = ${mainClassName};`); + eval(`${sourceCode}\nwi.MainClass = ${mainClassName}.${mainClassName};`); }, setInput: (inputBuffer: ArrayBuffer) => wi.inputBuffer = inputBuffer, reparse: (eagerMode: boolean) => { @@ -156,4 +165,4 @@ myself.onmessage = (ev: MessageEvent) => { //console.log("[Worker] Send response", msg, ev); myself.postMessage(msg); -}; \ No newline at end of file +};