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
2 changed files with 2 additions and 20 deletions
+1 -19
View File
@@ -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 = {