mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Switch to var in emitter, writer, printer (#52906)
This commit is contained in:
parent
27f20c9fae
commit
b39f10f651
@ -737,15 +737,17 @@ 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 {
|
||||
const compilerOptions = host.getCompilerOptions();
|
||||
const sourceMapDataList: SourceMapEmitResult[] | undefined = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined;
|
||||
const emittedFilesList: string[] | undefined = compilerOptions.listEmittedFiles ? [] : undefined;
|
||||
const emitterDiagnostics = createDiagnosticCollection();
|
||||
const newLine = getNewLineCharacter(compilerOptions);
|
||||
const writer = createTextWriter(newLine);
|
||||
const { enter, exit } = performance.createTimer("printTime", "beforePrint", "afterPrint");
|
||||
let bundleBuildInfo: BundleBuildInfo | undefined;
|
||||
let emitSkipped = false;
|
||||
/* eslint-disable no-var */
|
||||
var compilerOptions = host.getCompilerOptions();
|
||||
var sourceMapDataList: SourceMapEmitResult[] | undefined = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined;
|
||||
var emittedFilesList: string[] | undefined = compilerOptions.listEmittedFiles ? [] : undefined;
|
||||
var emitterDiagnostics = createDiagnosticCollection();
|
||||
var newLine = getNewLineCharacter(compilerOptions);
|
||||
var writer = createTextWriter(newLine);
|
||||
var { enter, exit } = performance.createTimer("printTime", "beforePrint", "afterPrint");
|
||||
var bundleBuildInfo: BundleBuildInfo | undefined;
|
||||
var emitSkipped = false;
|
||||
/* eslint-enable no-var */
|
||||
|
||||
// Emit each output file
|
||||
enter();
|
||||
@ -1356,7 +1358,8 @@ export const createPrinterWithRemoveCommentsNeverAsciiEscape = /* @__PURE__ */ m
|
||||
export const createPrinterWithRemoveCommentsOmitTrailingSemicolon = /* @__PURE__ */ memoize(() => createPrinter({ removeComments: true, omitTrailingSemicolon: true }));
|
||||
|
||||
export function createPrinter(printerOptions: PrinterOptions = {}, handlers: PrintHandlers = {}): Printer {
|
||||
const {
|
||||
/* eslint-disable no-var */
|
||||
var {
|
||||
hasGlobalName,
|
||||
onEmitNode = noEmitNotification,
|
||||
isEmitNotificationEnabled,
|
||||
@ -1369,63 +1372,64 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
onAfterEmitToken
|
||||
} = handlers;
|
||||
|
||||
const extendedDiagnostics = !!printerOptions.extendedDiagnostics;
|
||||
const newLine = getNewLineCharacter(printerOptions);
|
||||
const moduleKind = getEmitModuleKind(printerOptions);
|
||||
const bundledHelpers = new Map<string, boolean>();
|
||||
var extendedDiagnostics = !!printerOptions.extendedDiagnostics;
|
||||
var newLine = getNewLineCharacter(printerOptions);
|
||||
var moduleKind = getEmitModuleKind(printerOptions);
|
||||
var bundledHelpers = new Map<string, boolean>();
|
||||
|
||||
let currentSourceFile: SourceFile | undefined;
|
||||
let nodeIdToGeneratedName: string[]; // Map of generated names for specific nodes.
|
||||
let nodeIdToGeneratedPrivateName: string[]; // Map of generated names for specific nodes.
|
||||
let autoGeneratedIdToGeneratedName: string[]; // Map of generated names for temp and loop variables.
|
||||
let generatedNames: Set<string>; // Set of names generated by the NameGenerator.
|
||||
let formattedNameTempFlagsStack: (Map<string, TempFlags> | undefined)[];
|
||||
let formattedNameTempFlags: Map<string, TempFlags> | undefined;
|
||||
let privateNameTempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes.
|
||||
let privateNameTempFlags: TempFlags; // TempFlags for the current name generation scope.
|
||||
let tempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes.
|
||||
let tempFlags: TempFlags; // TempFlags for the current name generation scope.
|
||||
let reservedNamesStack: (Set<string> | undefined)[]; // Stack of reserved names in enclosing name generation scopes.
|
||||
let reservedNames: Set<string> | undefined; // Names reserved in nested name generation scopes.
|
||||
let reservedPrivateNamesStack: (Set<string> | undefined)[]; // Stack of reserved member names in enclosing name generation scopes.
|
||||
let reservedPrivateNames: Set<string> | undefined; // Member names reserved in nested name generation scopes.
|
||||
let preserveSourceNewlines = printerOptions.preserveSourceNewlines; // Can be overridden inside nodes with the `IgnoreSourceNewlines` emit flag.
|
||||
let nextListElementPos: number | undefined; // See comment in `getLeadingLineTerminatorCount`.
|
||||
var currentSourceFile: SourceFile | undefined;
|
||||
var nodeIdToGeneratedName: string[]; // Map of generated names for specific nodes.
|
||||
var nodeIdToGeneratedPrivateName: string[]; // Map of generated names for specific nodes.
|
||||
var autoGeneratedIdToGeneratedName: string[]; // Map of generated names for temp and loop variables.
|
||||
var generatedNames: Set<string>; // Set of names generated by the NameGenerator.
|
||||
var formattedNameTempFlagsStack: (Map<string, TempFlags> | undefined)[];
|
||||
var formattedNameTempFlags: Map<string, TempFlags> | undefined;
|
||||
var privateNameTempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes.
|
||||
var privateNameTempFlags: TempFlags; // TempFlags for the current name generation scope.
|
||||
var tempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes.
|
||||
var tempFlags: TempFlags; // TempFlags for the current name generation scope.
|
||||
var reservedNamesStack: (Set<string> | undefined)[]; // Stack of reserved names in enclosing name generation scopes.
|
||||
var reservedNames: Set<string> | undefined; // Names reserved in nested name generation scopes.
|
||||
var reservedPrivateNamesStack: (Set<string> | undefined)[]; // Stack of reserved member names in enclosing name generation scopes.
|
||||
var reservedPrivateNames: Set<string> | undefined; // Member names reserved in nested name generation scopes.
|
||||
var preserveSourceNewlines = printerOptions.preserveSourceNewlines; // Can be overridden inside nodes with the `IgnoreSourceNewlines` emit flag.
|
||||
var nextListElementPos: number | undefined; // See comment in `getLeadingLineTerminatorCount`.
|
||||
|
||||
let writer: EmitTextWriter;
|
||||
let ownWriter: EmitTextWriter; // Reusable `EmitTextWriter` for basic printing.
|
||||
let write = writeBase;
|
||||
let isOwnFileEmit: boolean;
|
||||
const bundleFileInfo = printerOptions.writeBundleFileInfo ? { sections: [] } as BundleFileInfo : undefined;
|
||||
const relativeToBuildInfo = bundleFileInfo ? Debug.checkDefined(printerOptions.relativeToBuildInfo) : undefined;
|
||||
const recordInternalSection = printerOptions.recordInternalSection;
|
||||
let sourceFileTextPos = 0;
|
||||
let sourceFileTextKind: BundleFileTextLikeKind = BundleFileSectionKind.Text;
|
||||
var writer: EmitTextWriter;
|
||||
var ownWriter: EmitTextWriter; // Reusable `EmitTextWriter` for basic printing.
|
||||
var write = writeBase;
|
||||
var isOwnFileEmit: boolean;
|
||||
var bundleFileInfo = printerOptions.writeBundleFileInfo ? { sections: [] } as BundleFileInfo : undefined;
|
||||
var relativeToBuildInfo = bundleFileInfo ? Debug.checkDefined(printerOptions.relativeToBuildInfo) : undefined;
|
||||
var recordInternalSection = printerOptions.recordInternalSection;
|
||||
var sourceFileTextPos = 0;
|
||||
var sourceFileTextKind: BundleFileTextLikeKind = BundleFileSectionKind.Text;
|
||||
|
||||
// Source Maps
|
||||
let sourceMapsDisabled = true;
|
||||
let sourceMapGenerator: SourceMapGenerator | undefined;
|
||||
let sourceMapSource: SourceMapSource;
|
||||
let sourceMapSourceIndex = -1;
|
||||
let mostRecentlyAddedSourceMapSource: SourceMapSource;
|
||||
let mostRecentlyAddedSourceMapSourceIndex = -1;
|
||||
var sourceMapsDisabled = true;
|
||||
var sourceMapGenerator: SourceMapGenerator | undefined;
|
||||
var sourceMapSource: SourceMapSource;
|
||||
var sourceMapSourceIndex = -1;
|
||||
var mostRecentlyAddedSourceMapSource: SourceMapSource;
|
||||
var mostRecentlyAddedSourceMapSourceIndex = -1;
|
||||
|
||||
// Comments
|
||||
let containerPos = -1;
|
||||
let containerEnd = -1;
|
||||
let declarationListContainerEnd = -1;
|
||||
let currentLineMap: readonly number[] | undefined;
|
||||
let detachedCommentsInfo: { nodePos: number, detachedCommentEndPos: number }[] | undefined;
|
||||
let hasWrittenComment = false;
|
||||
let commentsDisabled = !!printerOptions.removeComments;
|
||||
let lastSubstitution: Node | undefined;
|
||||
let currentParenthesizerRule: ParenthesizerRule<any> | undefined;
|
||||
const { enter: enterComment, exit: exitComment } = performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
|
||||
const parenthesizer = factory.parenthesizer;
|
||||
const typeArgumentParenthesizerRuleSelector: OrdinalParentheizerRuleSelector<TypeNode> = {
|
||||
var containerPos = -1;
|
||||
var containerEnd = -1;
|
||||
var declarationListContainerEnd = -1;
|
||||
var currentLineMap: readonly number[] | undefined;
|
||||
var detachedCommentsInfo: { nodePos: number, detachedCommentEndPos: number }[] | undefined;
|
||||
var hasWrittenComment = false;
|
||||
var commentsDisabled = !!printerOptions.removeComments;
|
||||
var lastSubstitution: Node | undefined;
|
||||
var currentParenthesizerRule: ParenthesizerRule<any> | undefined;
|
||||
var { enter: enterComment, exit: exitComment } = performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
|
||||
var parenthesizer = factory.parenthesizer;
|
||||
var typeArgumentParenthesizerRuleSelector: OrdinalParentheizerRuleSelector<TypeNode> = {
|
||||
select: index => index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined
|
||||
};
|
||||
const emitBinaryExpression = createEmitBinaryExpression();
|
||||
var emitBinaryExpression = createEmitBinaryExpression();
|
||||
/* eslint-enable no-var */
|
||||
|
||||
reset();
|
||||
return {
|
||||
@ -1567,7 +1571,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
writeLine();
|
||||
const pos = writer.getTextPos();
|
||||
const savedSections = bundleFileInfo && bundleFileInfo.sections;
|
||||
if (savedSections) bundleFileInfo.sections = [];
|
||||
if (savedSections) bundleFileInfo!.sections = [];
|
||||
print(EmitHint.Unspecified, prepend, /*sourceFile*/ undefined);
|
||||
if (bundleFileInfo) {
|
||||
const newSections = bundleFileInfo.sections;
|
||||
|
||||
@ -35,39 +35,41 @@ export interface SourceMapGeneratorOptions {
|
||||
|
||||
/** @internal */
|
||||
export function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator {
|
||||
const { enter, exit } = generatorOptions.extendedDiagnostics
|
||||
/* eslint-disable no-var */
|
||||
var { enter, exit } = generatorOptions.extendedDiagnostics
|
||||
? performance.createTimer("Source Map", "beforeSourcemap", "afterSourcemap")
|
||||
: performance.nullTimer;
|
||||
|
||||
// Current source map file and its index in the sources list
|
||||
const rawSources: string[] = [];
|
||||
const sources: string[] = [];
|
||||
const sourceToSourceIndexMap = new Map<string, number>();
|
||||
let sourcesContent: (string | null)[] | undefined;
|
||||
var rawSources: string[] = [];
|
||||
var sources: string[] = [];
|
||||
var sourceToSourceIndexMap = new Map<string, number>();
|
||||
var sourcesContent: (string | null)[] | undefined;
|
||||
|
||||
const names: string[] = [];
|
||||
let nameToNameIndexMap: Map<string, number> | undefined;
|
||||
const mappingCharCodes: number[] = [];
|
||||
let mappings = "";
|
||||
var names: string[] = [];
|
||||
var nameToNameIndexMap: Map<string, number> | undefined;
|
||||
var mappingCharCodes: number[] = [];
|
||||
var mappings = "";
|
||||
|
||||
// Last recorded and encoded mappings
|
||||
let lastGeneratedLine = 0;
|
||||
let lastGeneratedCharacter = 0;
|
||||
let lastSourceIndex = 0;
|
||||
let lastSourceLine = 0;
|
||||
let lastSourceCharacter = 0;
|
||||
let lastNameIndex = 0;
|
||||
let hasLast = false;
|
||||
var lastGeneratedLine = 0;
|
||||
var lastGeneratedCharacter = 0;
|
||||
var lastSourceIndex = 0;
|
||||
var lastSourceLine = 0;
|
||||
var lastSourceCharacter = 0;
|
||||
var lastNameIndex = 0;
|
||||
var hasLast = false;
|
||||
|
||||
let pendingGeneratedLine = 0;
|
||||
let pendingGeneratedCharacter = 0;
|
||||
let pendingSourceIndex = 0;
|
||||
let pendingSourceLine = 0;
|
||||
let pendingSourceCharacter = 0;
|
||||
let pendingNameIndex = 0;
|
||||
let hasPending = false;
|
||||
let hasPendingSource = false;
|
||||
let hasPendingName = false;
|
||||
var pendingGeneratedLine = 0;
|
||||
var pendingGeneratedCharacter = 0;
|
||||
var pendingSourceIndex = 0;
|
||||
var pendingSourceLine = 0;
|
||||
var pendingSourceCharacter = 0;
|
||||
var pendingNameIndex = 0;
|
||||
var hasPending = false;
|
||||
var hasPendingSource = false;
|
||||
var hasPendingName = false;
|
||||
/* eslint-enable no-var */
|
||||
|
||||
return {
|
||||
getSources: () => rawSources,
|
||||
|
||||
@ -596,7 +596,9 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol {
|
||||
const stringWriter = createSingleLineStringWriter();
|
||||
|
||||
function createSingleLineStringWriter(): EmitTextWriter {
|
||||
let str = "";
|
||||
/* eslint-disable no-var */
|
||||
var str = "";
|
||||
/* eslint-enable no-var */
|
||||
const writeText: (text: string) => void = text => str += text;
|
||||
return {
|
||||
getText: () => str,
|
||||
@ -5810,12 +5812,14 @@ export function isNightly() {
|
||||
|
||||
/** @internal */
|
||||
export function createTextWriter(newLine: string): EmitTextWriter {
|
||||
let output: string;
|
||||
let indent: number;
|
||||
let lineStart: boolean;
|
||||
let lineCount: number;
|
||||
let linePos: number;
|
||||
let hasTrailingComment = false;
|
||||
/* eslint-disable no-var */
|
||||
var output: string;
|
||||
var indent: number;
|
||||
var lineStart: boolean;
|
||||
var lineCount: number;
|
||||
var linePos: number;
|
||||
var hasTrailingComment = false;
|
||||
/* eslint-enable no-var */
|
||||
|
||||
function updateLineCountAndPosFor(s: string) {
|
||||
const lineStartsOfS = computeLineStarts(s);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user