From 69bd2e7320430cd468f744d9b085e2abfc450828 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 22 Feb 2023 16:04:05 -0800 Subject: [PATCH 1/2] Add links to github above big var blocks --- src/compiler/binder.ts | 1 + src/compiler/checker.ts | 1 + src/compiler/emitter.ts | 2 ++ src/compiler/parser.ts | 1 + src/compiler/scanner.ts | 1 + src/compiler/sourcemap.ts | 1 + src/compiler/utilities.ts | 2 ++ 7 files changed, 9 insertions(+) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a6e497fc8a414..af5b5afbf9534 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -501,6 +501,7 @@ export function bindSourceFile(file: SourceFile, options: CompilerOptions) { } function createBinder(): (file: SourceFile, options: CompilerOptions) => void { + // Why var? 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..bf70ed08408d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1378,6 +1378,7 @@ export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums /** @internal */ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { + // Why var? 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..449b979ec82e8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -737,6 +737,7 @@ 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? 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 +1359,7 @@ 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? 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..aad830d02c28f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1401,6 +1401,7 @@ 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? 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..3798b8a3ab2bb 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -961,6 +961,7 @@ export function createScanner(languageVersion: ScriptTarget, start?: number, length?: number): Scanner { + // Why var? 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..b8be16a174a36 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -35,6 +35,7 @@ export interface SourceMapGeneratorOptions { /** @internal */ export function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator { + // Why var? 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..1c92025b6ed5b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,6 +596,7 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol { const stringWriter = createSingleLineStringWriter(); function createSingleLineStringWriter(): EmitTextWriter { + // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var str = ""; /* eslint-enable no-var */ @@ -5812,6 +5813,7 @@ export function isNightly() { /** @internal */ export function createTextWriter(newLine: string): EmitTextWriter { + // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 /* eslint-disable no-var */ var output: string; var indent: number; From f298e242661a369effe41bb6be16cdd9d191e920 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 22 Feb 2023 16:29:41 -0800 Subject: [PATCH 2/2] Update all comments --- src/compiler/binder.ts | 3 ++- src/compiler/checker.ts | 3 ++- src/compiler/emitter.ts | 6 ++++-- src/compiler/parser.ts | 3 ++- src/compiler/scanner.ts | 3 ++- src/compiler/sourcemap.ts | 3 ++- src/compiler/utilities.ts | 6 ++++-- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index af5b5afbf9534..78bf9e1f3a682 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -501,7 +501,8 @@ export function bindSourceFile(file: SourceFile, options: CompilerOptions) { } function createBinder(): (file: SourceFile, options: CompilerOptions) => void { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 bf70ed08408d9..beb75fd16d2dc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1378,7 +1378,8 @@ export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums /** @internal */ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 449b979ec82e8..05f117fdcfa12 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -737,7 +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? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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; @@ -1359,7 +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? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 aad830d02c28f..e157e0cebd413 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1401,7 +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? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 3798b8a3ab2bb..e517b18e685f8 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -961,7 +961,8 @@ export function createScanner(languageVersion: ScriptTarget, start?: number, length?: number): Scanner { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 b8be16a174a36..14b106b70a318 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -35,7 +35,8 @@ export interface SourceMapGeneratorOptions { /** @internal */ export function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 1c92025b6ed5b..af4730f848460 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,7 +596,8 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol { const stringWriter = createSingleLineStringWriter(); function createSingleLineStringWriter(): EmitTextWriter { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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 */ @@ -5813,7 +5814,8 @@ export function isNightly() { /** @internal */ export function createTextWriter(newLine: string): EmitTextWriter { - // Why var? See: https://github.com/microsoft/TypeScript/issues/52924 + // 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;