From ad0079146221d13a2a420907ad49e8d29a88185f Mon Sep 17 00:00:00 2001 From: zongor Date: Mon, 27 May 2024 19:13:13 -0400 Subject: [PATCH] fix to not import multiple times --- .../js-class-c-struct-transpiler/transpile.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/js-class-c-struct-transpiler/transpile.js b/tools/js-class-c-struct-transpiler/transpile.js index 3261161..8aafe92 100644 --- a/tools/js-class-c-struct-transpiler/transpile.js +++ b/tools/js-class-c-struct-transpiler/transpile.js @@ -51,12 +51,12 @@ const { values } = parseArgs({ short: "S", }, jsout: { - type: "string", - short: "j" + type: "string", + short: "j", }, cout: { - type: "string", - short: "c" + type: "string", + short: "c", }, }, strict: true, @@ -146,7 +146,10 @@ for (const type of Object.keys(schema)) { set ${prop}(v) { this._data.set(v.bytes(), ${offset}); }`; - importStatements += `import ${propType} from "./${propType}"\n\n`; + const importS = `import ${propType} from "./${propType}"\n\n`; + if (!importStatements.includes(importS)) { + importStatements += importS; + } cData += `\n\t\t${types[propType].c} ${prop};`; break; @@ -179,6 +182,9 @@ export default ${type}`; `; - await Bun.write(Bun.file(values.jsout + type + ".js"), (importStatements + jsData)); + await Bun.write( + Bun.file(values.jsout + type + ".js"), + importStatements + jsData + ); } await Bun.write(Bun.file(values.cout + "types.h"), cData);