mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-08 08:43:53 +01:00
MISC: Remove testing code in ScriptTransformer (#1499)
This commit is contained in:
parent
ea83138722
commit
ceaf27714b
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user