mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +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.JSX:
|
||||||
case FileType.TS:
|
case FileType.TS:
|
||||||
case FileType.TSX:
|
case FileType.TSX:
|
||||||
scriptCode = transformScript(script.filename, script.code, fileType);
|
scriptCode = transformScript(script.code, fileType);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid file type: ${fileType}. Filename: ${script.filename}, server: ${script.server}.`);
|
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 { resolveScriptFilePath, validScriptExtensions, type ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||||
import type { Script } from "../Script/Script";
|
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 AcornASTProgram = acorn.Program;
|
||||||
export type BabelASTProgram = object;
|
export type BabelASTProgram = object;
|
||||||
export type AST = AcornASTProgram | BabelASTProgram;
|
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
|
* This function must be synchronous to avoid race conditions. Check https://github.com/bitburner-official/bitburner-src/pull/1173#issuecomment-2026940461
|
||||||
* for more information.
|
* for more information.
|
||||||
*
|
*
|
||||||
* @param filename
|
|
||||||
* @param code
|
* @param code
|
||||||
* @param fileType
|
* @param fileType
|
||||||
* @returns
|
* @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)) {
|
if (supportedFileTypes.every((v) => v !== fileType)) {
|
||||||
throw new Error(`Invalid file type: ${fileType}`);
|
throw new Error(`Invalid file type: ${fileType}`);
|
||||||
}
|
}
|
||||||
const fileTypeFeature = getFileTypeFeature(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;
|
let parserConfig: ParserConfig;
|
||||||
if (fileTypeFeature.isTypeScript) {
|
if (fileTypeFeature.isTypeScript) {
|
||||||
parserConfig = {
|
parserConfig = {
|
||||||
|
Loading…
Reference in New Issue
Block a user