diff --git a/src/Script/Script.ts b/src/Script/Script.ts index 108279d7f..6794cd11b 100644 --- a/src/Script/Script.ts +++ b/src/Script/Script.ts @@ -6,13 +6,11 @@ import { roundToTwo } from "../utils/helpers/roundToTwo"; import { RamCostConstants } from "../Netscript/RamCostGenerator"; import { ScriptFilePath } from "../Paths/ScriptFilePath"; import { ContentFile } from "../Paths/ContentFile"; -/** Type for ensuring script code is always trimmed */ -export type FormattedCode = string & { __type: "FormattedCode" }; /** A script file as a file on a server. * For the execution of a script, see RunningScript and WorkerScript */ export class Script implements ContentFile { - code: FormattedCode; + code: string; filename: ScriptFilePath; server: string; @@ -34,8 +32,7 @@ export class Script implements ContentFile { get content() { return this.code; } - set content(code: string) { - const newCode = Script.formatCode(code); + set content(newCode: string) { if (this.code === newCode) return; this.code = newCode; this.invalidateModule(); @@ -43,7 +40,7 @@ export class Script implements ContentFile { constructor(fn = "default.js" as ScriptFilePath, code = "", server = "") { this.filename = fn; - this.code = Script.formatCode(code); + this.code = code; this.server = server; // hostname of server this script is on } @@ -138,8 +135,8 @@ export class Script implements ContentFile { * @param {string} code - The code to format * @returns The formatted code */ - static formatCode(code: string): FormattedCode { - return code.replace(/^\s+|\s+$/g, "") as FormattedCode; + static formatCode(code: string): string { + return code.replace(/^\s+|\s+$/g, ""); } } diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index c1b1ef6cd..b31b6da7c 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -252,7 +252,7 @@ export abstract class BaseServer implements IServer { // Check if the script already exists, and overwrite it if it does const script = this.scripts.get(filename); if (script) { - // content setter handles module invalidation and code formatting + // content setter handles module invalidation script.content = code; return { overwritten: true }; } diff --git a/src/utils/v1APIBreak.ts b/src/utils/v1APIBreak.ts index 4f041021d..b43fb8d42 100644 --- a/src/utils/v1APIBreak.ts +++ b/src/utils/v1APIBreak.ts @@ -1,7 +1,7 @@ import { AugmentationNames } from "../Augmentation/data/AugmentationNames"; import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation"; import { Player } from "@player"; -import { FormattedCode, Script } from "../Script/Script"; +import { Script } from "../Script/Script"; import { GetAllServers } from "../Server/AllServers"; import { resolveTextFilePath } from "../Paths/TextFilePath"; import { resolveScriptFilePath } from "../Paths/ScriptFilePath"; @@ -54,7 +54,7 @@ function hasChanges(code: string): boolean { return false; } -function convert(code: string): FormattedCode { +function convert(code: string): string { const lines = code.split("\n"); const out: string[] = []; for (let i = 0; i < lines.length; i++) {