Skip to content

Commit

Permalink
Merge pull request #169 from kaitai-io/fix-fresh-and-circular-imports
Browse files Browse the repository at this point in the history
Fix temporary error when imports are used, support circular imports
  • Loading branch information
generalmimon authored Feb 21, 2024
2 parents 00c6083 + 12d4036 commit db130c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/v1/kaitaiWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<any>x)).filter(x => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -156,4 +165,4 @@ myself.onmessage = (ev: MessageEvent) => {

//console.log("[Worker] Send response", msg, ev);
myself.postMessage(msg);
};
};

0 comments on commit db130c9

Please sign in to comment.