Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temporary error when imports are used, support circular imports #169

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};
};