MISC: Remove testing code in ScriptTransformer (#1499)

This commit is contained in:
catloversg 2024-07-18 13:23:18 +07:00 committed by GitHub
parent ea83138722
commit ceaf27714b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 20 deletions

@ -92,7 +92,7 @@ function generateLoadedModule(script: Script, scripts: Map<ScriptFilePath, Scrip
case FileType.JSX:
case FileType.TS:
case FileType.TSX:
scriptCode = transformScript(script.filename, script.code, fileType);
scriptCode = transformScript(script.code, fileType);
break;
default:
throw new Error(`Invalid file type: ${fileType}. Filename: ${script.filename}, server: ${script.server}.`);

@ -4,12 +4,6 @@ import * as acorn from "acorn";
import { resolveScriptFilePath, validScriptExtensions, type ScriptFilePath } from "../Paths/ScriptFilePath";
import type { Script } from "../Script/Script";
// This is only for testing. It will be removed after we decide between Babel and SWC.
declare global {
// eslint-disable-next-line no-var
var forceBabelTransform: boolean;
}
export type AcornASTProgram = acorn.Program;
export type BabelASTProgram = object;
export type AST = AcornASTProgram | BabelASTProgram;
@ -130,27 +124,15 @@ 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 filename
* @param code
* @param fileType
* @returns
*/
export function transformScript(filename: string, code: string, fileType: FileType): string | null | undefined {
export function transformScript(code: string, fileType: FileType): string | null | undefined {
if (supportedFileTypes.every((v) => v !== fileType)) {
throw new Error(`Invalid file type: ${fileType}`);
}
const fileTypeFeature = getFileTypeFeature(fileType);
// This is only for testing. It will be removed after we decide between Babel and SWC.
if (globalThis.forceBabelTransform) {
const presets = [];
if (fileTypeFeature.isReact) {
presets.push("react");
}
if (fileTypeFeature.isTypeScript) {
presets.push("typescript");
}
return babel.transform(code, { filename: filename, presets: presets }).code;
}
let parserConfig: ParserConfig;
if (fileTypeFeature.isTypeScript) {
parserConfig = {