diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a6e497fc8a414..78bf9e1f3a682 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -501,6 +501,8 @@ export function bindSourceFile(file: SourceFile, options: CompilerOptions) { } function createBinder(): (file: SourceFile, options: CompilerOptions) => void { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var file: SourceFile; var options: CompilerOptions; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c0b9802d4021b..beb75fd16d2dc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1378,6 +1378,8 @@ export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums /** @internal */ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var getPackagesMap = memoize(() => { // A package name maps to true when we detect it has .d.ts files. diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fe198d629533c..05f117fdcfa12 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -737,6 +737,8 @@ export function getFirstProjectOutput(configFile: ParsedCommandLine, ignoreCase: /** @internal */ // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile | undefined, { scriptTransformers, declarationTransformers }: EmitTransformers, emitOnly?: boolean | EmitOnly, onlyBuildInfo?: boolean, forceDtsEmit?: boolean): EmitResult { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var compilerOptions = host.getCompilerOptions(); var sourceMapDataList: SourceMapEmitResult[] | undefined = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined; @@ -1358,6 +1360,8 @@ export const createPrinterWithRemoveCommentsNeverAsciiEscape = /* @__PURE__ */ m export const createPrinterWithRemoveCommentsOmitTrailingSemicolon = /* @__PURE__ */ memoize(() => createPrinter({ removeComments: true, omitTrailingSemicolon: true })); export function createPrinter(printerOptions: PrinterOptions = {}, handlers: PrintHandlers = {}): Printer { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var { hasGlobalName, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9bcf3c8c7dd53..e157e0cebd413 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1401,6 +1401,8 @@ export function parseJSDocTypeExpressionForTests(content: string, start?: number // parser instances can actually be expensive enough to impact us on projects with many source // files. namespace Parser { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ // Share a single scanner across all calls to parse a source file. This helps speed things diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 554800e28b9bb..e517b18e685f8 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -961,6 +961,8 @@ export function createScanner(languageVersion: ScriptTarget, start?: number, length?: number): Scanner { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var text = textInitial!; diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 8921bdfeba7de..14b106b70a318 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -35,6 +35,8 @@ export interface SourceMapGeneratorOptions { /** @internal */ export function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var { enter, exit } = generatorOptions.extendedDiagnostics ? performance.createTimer("Source Map", "beforeSourcemap", "afterSourcemap") diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 774b3fb2212a7..af4730f848460 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,6 +596,8 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol { const stringWriter = createSingleLineStringWriter(); function createSingleLineStringWriter(): EmitTextWriter { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var str = ""; /* eslint-enable no-var */ @@ -5812,6 +5814,8 @@ export function isNightly() { /** @internal */ export function createTextWriter(newLine: string): EmitTextWriter { + // Why var? It avoids TDZ checks in the runtime which can be costly. + // See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var output: string; var indent: number;