From af15775e5e3d55a9c1fc48d37fb44b1c07ffaa16 Mon Sep 17 00:00:00 2001 From: zongor Date: Mon, 27 May 2024 19:08:52 -0400 Subject: [PATCH] add imports if they need it --- tools/js-class-c-struct-transpiler/transpile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/js-class-c-struct-transpiler/transpile.js b/tools/js-class-c-struct-transpiler/transpile.js index 6d7235d..3261161 100644 --- a/tools/js-class-c-struct-transpiler/transpile.js +++ b/tools/js-class-c-struct-transpiler/transpile.js @@ -93,6 +93,7 @@ for (const type of Object.keys(schema)) { let containsString = false; let offset = 0; let size = 0; + let importStatements = ""; let jsData = ""; const props = schema[type]; cData += `typedef struct ${type} {`; @@ -145,9 +146,9 @@ for (const type of Object.keys(schema)) { set ${prop}(v) { this._data.set(v.bytes(), ${offset}); }`; + importStatements += `import ${propType} from "./${propType}"\n\n`; - cData += ` - ${types[propType].c} ${prop};`; + cData += `\n\t\t${types[propType].c} ${prop};`; break; case "array": break; @@ -178,6 +179,6 @@ export default ${type}`; `; - await Bun.write(Bun.file(values.jsout + type + ".js"), jsData); + await Bun.write(Bun.file(values.jsout + type + ".js"), (importStatements + jsData)); } await Bun.write(Bun.file(values.cout + "types.h"), cData);