diff --git a/Herebyfile.mjs b/Herebyfile.mjs index d9f87752e01..402f7917cf3 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -175,7 +175,6 @@ async function runDtsBundler(entrypoint, output) { * @property {boolean} [exportIsTsObject] * @property {boolean} [treeShaking] * @property {boolean} [usePublicAPI] - * @property {boolean} [tsgoCompat] * @property {() => void} [onWatchRebuild] */ function createBundler(entrypoint, outfile, taskOptions = {}) { @@ -197,9 +196,6 @@ function createBundler(entrypoint, outfile, taskOptions = {}) { treeShaking: taskOptions.treeShaking, packages: "external", logLevel: "warning", - define: { - __TSGO_COMPAT__: taskOptions.tsgoCompat ? "true" : "false", - }, // legalComments: "none", // If we add copyright headers to the source files, uncomment. }; @@ -236,8 +232,7 @@ function createBundler(entrypoint, outfile, taskOptions = {}) { const require = "require"; const fakeName = "Q".repeat(require.length); const fakeNameRegExp = new RegExp(fakeName, "g"); - options.define = options.define || {}; - options.define[require] = fakeName; + options.define = { [require]: fakeName }; // For historical reasons, TypeScript does not set __esModule. Hack esbuild's __toCommonJS to be a noop. // We reference `__copyProps` to ensure the final bundle doesn't have any unreferenced code. @@ -546,7 +541,6 @@ const { main: tests, watch: watchTests } = entrypointBuildTask({ output: testRunner, mainDeps: [generateLibs], bundlerOptions: { - tsgoCompat: true, // Ensure we never drop any dead code, which might be helpful while debugging. treeShaking: false, onWatchRebuild() { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 631d3cb3c95..8c1a5ae0c13 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1,5 +1,6 @@ import { __String, + __TSGO_COMPAT__, AccessExpression, AccessFlags, AccessorDeclaration, diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index 6325b7aa0bf..ac3d8e794e6 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -5,11 +5,10 @@ export const versionMajorMinor = "5.7"; /** The version of the TypeScript compiler release */ export const version: string = `${versionMajorMinor}.0-dev`; -declare global { - var __TSGO_COMPAT__: boolean | undefined; // eslint-disable-line no-var, @typescript-eslint/naming-convention -} +const tsgoCompatEnv = typeof process !== "undefined" && process.env ? process.env.TSGO_COMPAT : undefined; -globalThis.__TSGO_COMPAT__ ??= false; +/** @internal */ +export const __TSGO_COMPAT__: boolean = tsgoCompatEnv ? tsgoCompatEnv === "true" : true; /** * Type of objects whose values are all of the same type.