MISC: Add source map to transformed scripts (#1812)

* MISC: Add source map to transformed scripts

* Print error to console
This commit is contained in:
catloversg
2025-01-20 04:50:50 +07:00
committed by GitHub
parent 7b009991e5
commit 9920b6ae4d
5 changed files with 52 additions and 11 deletions
+11 -7
View File
@@ -123,12 +123,11 @@ export function getModuleScript(
/**
* This function must be synchronous to avoid race conditions. Check https://github.com/bitburner-official/bitburner-src/pull/1173#issuecomment-2026940461
* for more information.
*
* @param code
* @param fileType
* @returns
*/
export function transformScript(code: string, fileType: FileType): string | null | undefined {
export function transformScript(
code: string,
fileType: FileType,
): { scriptCode: string; sourceMap: string | undefined } {
if (supportedFileTypes.every((v) => v !== fileType)) {
throw new Error(`Invalid file type: ${fileType}`);
}
@@ -149,11 +148,16 @@ export function transformScript(code: string, fileType: FileType): string | null
parserConfig.jsx = true;
}
}
return transformSync(code, {
const result = transformSync(code, {
jsc: {
parser: parserConfig,
// @ts-expect-error -- jsc supports "esnext" target, but the definition in wasm-web.d.ts is outdated. Ref: https://github.com/swc-project/swc/issues/9495
target: "esnext",
},
}).code;
sourceMaps: true,
});
return {
scriptCode: result.code,
sourceMap: result.map,
};
}