Skip to content

Commit

Permalink
Remove a bunch of namespace uses
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed May 28, 2022
1 parent 4167e86 commit 0192dc8
Show file tree
Hide file tree
Showing 190 changed files with 306 additions and 359 deletions.
5 changes: 2 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as ts from "./_namespaces/ts";
import { performance } from "./_namespaces/ts";
import { getNodeId } from "./checker";
import {
append, appendIfUnique, cast, concatenate, contains, every, forEach, getRangesWhere, isString, length, Pattern,
Expand All @@ -19,6 +17,7 @@ import {
import { createBinaryExpressionTrampoline } from "./factory/utilities";
import { forEachChild, isExternalModule } from "./parser";
import { perfLogger } from "./perfLogger";
import * as performance from "./performance";
import { tokenToString } from "./scanner";
import { tracing, TracingNode } from "./tracing";
import {
Expand Down Expand Up @@ -471,7 +470,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
case SyntaxKind.Parameter:
// Parameters with names are handled at the top of this function. Parameters
// without names can only come from JSDocFunctionTypes.
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType, "Impossible parameter parent kind", () => `parent is: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[node.parent.kind] : node.parent.kind}, expected JSDocFunctionType`);
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType, "Impossible parameter parent kind", () => `parent is: ${Debug.formatSyntaxKind(node.parent.kind)}, expected JSDocFunctionType`);
const functionType = node.parent as JSDocFunctionType;
const index = functionType.parameters.indexOf(node as ParameterDeclaration);
return "arg" + index as __String;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import {
AffectedFileResult, BuilderProgram, BuilderProgramHost, EmitAndSemanticDiagnosticsBuilderProgram,
SemanticDiagnosticsBuilderProgram,
Expand All @@ -16,6 +15,7 @@ import { getTsBuildInfoEmitOutputFilePath } from "./emitter";
import { isDeclarationFileName } from "./parser";
import {
ensurePathIsNonModuleName, getDirectoryPath, getNormalizedAbsolutePath, getRelativePathFromDirectory,
toPath as toPathInternal,
} from "./path";
import { createProgram, emitSkippedWithNoDiagnostics, filterSemanticDiagnostics, handleNoEmitOptions } from "./program";
import { generateDjb2Hash } from "./sys";
Expand Down Expand Up @@ -328,7 +328,7 @@ function convertToDiagnostics(diagnostics: readonly ReusableDiagnostic[], newPro
});

function toPath(path: string) {
return ts.toPath(path, buildInfoDirectory, getCanonicalFileName);
return toPathInternal(path, buildInfoDirectory, getCanonicalFileName);
}
}

Expand Down Expand Up @@ -1456,7 +1456,7 @@ export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInf
};

function toPath(path: string) {
return ts.toPath(path, buildInfoDirectory, getCanonicalFileName);
return toPathInternal(path, buildInfoDirectory, getCanonicalFileName);
}

function toAbsolutePath(path: string) {
Expand Down
17 changes: 9 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as ts from "./_namespaces/ts";
import { moduleSpecifiers, performance } from "./_namespaces/ts";
import { bindSourceFile, getModuleInstanceState, ModuleInstanceState } from "./binder";
import {
addRange, and, append, appendIfUnique, arrayFrom, arrayOf, arraysEqual, arrayToMultiMap, binarySearch,
Expand Down Expand Up @@ -49,13 +47,15 @@ import {
} from "./factory/utilities";
import { setTextRange } from "./factory/utilitiesPublic";
import { getTypesPackageName, mangleScopedPackageName } from "./moduleNameResolver";
import * as moduleSpecifiers from "./moduleSpecifiers";
import {
forEachChild, forEachChildRecursively, isExternalModule, parseIsolatedEntityName, parseNodeFactory,
} from "./parser";
import {
comparePaths, fileExtensionIs, fileExtensionIsOneOf, getDirectoryPath, getNormalizedAbsolutePath, hasExtension,
pathIsRelative,
} from "./path";
import * as performance from "./performance";
import {
getModeForUsageLocation, getResolutionDiagnostic, getResolutionModeOverrideForClause,
isExclusivelyTypeOnlyImportOrExport, resolveTripleslashReference,
Expand Down Expand Up @@ -211,8 +211,8 @@ import {
getEffectiveConstraintOfTypeParameter, getEffectiveTypeParameterDeclarations, getJSDocClassTag,
getJSDocDeprecatedTag, getJSDocEnumTag, getJSDocParameterTags, getJSDocTags, getJSDocThisTag, getJSDocType,
getJSDocTypeTag, getNameOfDeclaration, getOriginalNode, getParseTreeNode, getTextOfJSDocComment, hasInitializer,
hasJSDocNodes, hasJSDocParameterTags, hasOnlyExpressionInitializer, hasRestParameter, hasScopeMarker, idText,
isAccessor, isAssertionExpression, isAssignmentPattern, isBindingPattern, isCallChain, isCallLikeExpression,
hasJSDocNodes, hasJSDocParameterTags, hasOnlyExpressionInitializer, hasRestParameter, hasScopeMarker, hasType,
idText, isAccessor, isAssertionExpression, isAssignmentPattern, isBindingPattern, isCallChain, isCallLikeExpression,
isCallOrNewExpression, isClassElement, isClassLike, isConstTypeReference, isDeclaration, isEntityName, isExpression,
isExpressionOfOptionalChainRoot, isExternalModuleIndicator, isExternalModuleNameRelative, isForInOrOfStatement,
isFunctionLike, isFunctionLikeDeclaration, isFunctionLikeOrClassStaticBlockDeclaration, isFunctionOrModuleBlock,
Expand Down Expand Up @@ -965,6 +965,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isPropertyAccessible,
getTypeOnlyAliasDeclaration,
getMemberOverrideModifierStatus,
typeHasCallOrConstructSignatures,
};

function runWithInferenceBlockedFromSourceNode<T>(node: Node | undefined, fn: () => T): T {
Expand Down Expand Up @@ -8816,7 +8817,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function findResolutionCycleStartIndex(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): number {
for (let i = resolutionTargets.length - 1; i >= 0; i--) {
if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) {
if (resolutionTargetHasType(resolutionTargets[i], resolutionPropertyNames[i])) {
return -1;
}
if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) {
Expand All @@ -8826,7 +8827,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return -1;
}

function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean {
function resolutionTargetHasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean {
switch (propertyName) {
case TypeSystemPropertyName.Type:
return !!getSymbolLinks(target as Symbol).type;
Expand Down Expand Up @@ -17750,7 +17751,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}
// Or functions with annotated parameter types
if (some(node.parameters, ts.hasType)) {
if (some(node.parameters, hasType)) {
return false;
}
const sourceSig = getSingleCallSignature(source);
Expand Down Expand Up @@ -42642,7 +42643,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function typeHasCallOrConstructSignatures(type: Type): boolean {
return ts.typeHasCallOrConstructSignatures(type, checker);
return getSignaturesOfType(type, SignatureKind.Call).length !== 0 || getSignaturesOfType(type, SignatureKind.Construct).length !== 0;
}

function getRootSymbols(symbol: Symbol): readonly Symbol[] {
Expand Down
20 changes: 9 additions & 11 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as ts from "./_namespaces/ts";
import { performance } from "./_namespaces/ts";
import { OutputFile } from "./builderStatePublic";
import { getNodeId } from "./checker";
import {
arrayToMap, cast, clone, contains, createGetCanonicalFileName, createMultiMap, emptyArray, filter, findIndex,
forEach, GetCanonicalFileName, isArray, last, lastOrUndefined, length, memoize, notImplemented, returnFalse,
returnUndefined, singleOrUndefined, some, stableSort, stringContains,
} from "./core";
import { Comparison, Map, Set } from "./corePublic";
import { Comparison, Map, Set, version } from "./corePublic";
import { Debug } from "./debug";
import { compareEmitHelpers } from "./factory/emitHelpers";
import {
Expand All @@ -32,6 +30,7 @@ import {
getRelativePathFromDirectory, getRelativePathToDirectoryOrUrl, getRootLength, normalizePath, normalizeSlashes,
resolvePath,
} from "./path";
import * as performance from "./performance";
import { computeCommonSourceDirectoryOfFilenames, createPrependNodes } from "./program";
import {
computeLineStarts, forEachLeadingCommentRange, forEachTrailingCommentRange, getLeadingCommentRanges,
Expand Down Expand Up @@ -93,12 +92,12 @@ import {
getLinesBetweenRangeEndAndRangeStart, getLiteralText, GetLiteralTextFlags, getNewLineCharacter,
getOwnEmitOutputFilePath, getSourceFileOfNode, getSourceFilePathInNewDir, getSourceFilesToEmit,
getSourceTextOfNodeFromSourceFile, getTrailingSemicolonDeferringWriter, isAccessExpression, isBundleFileTextLike,
isIncrementalCompilation, isInJsonFile, isJsonSourceFile, isKeyword, isLet, isNodeDescendantOf, isPinnedComment,
isPrologueDirective, isRecognizedTripleSlashComment, isSourceFileNotJson, isVarConst, makeIdentifierFromModuleName,
nodeIsSynthesized, outFile, positionIsSynthesized, positionsAreOnSameLine, rangeEndIsOnSameLineAsRangeStart,
rangeEndPositionsAreOnSameLine, rangeIsOnSingleLine, rangeStartPositionsAreOnSameLine, removeFileExtension,
setEachParent, setParent, setTextRangePosEnd, setTextRangePosWidth, supportedJSExtensionsFlat, writeCommentRange,
writeFile,
isFileLevelUniqueName as isFileLevelUniqueNameInternal, isIncrementalCompilation, isInJsonFile, isJsonSourceFile,
isKeyword, isLet, isNodeDescendantOf, isPinnedComment, isPrologueDirective, isRecognizedTripleSlashComment,
isSourceFileNotJson, isVarConst, makeIdentifierFromModuleName, nodeIsSynthesized, outFile, positionIsSynthesized,
positionsAreOnSameLine, rangeEndIsOnSameLineAsRangeStart, rangeEndPositionsAreOnSameLine, rangeIsOnSingleLine,
rangeStartPositionsAreOnSameLine, removeFileExtension, setEachParent, setParent, setTextRangePosEnd,
setTextRangePosWidth, supportedJSExtensionsFlat, writeCommentRange, writeFile,
} from "./utilities";
import {
escapeLeadingUnderscores, getOriginalNode, getParseTreeNode, getTextOfJSDocComment, guessIndentation, idText,
Expand Down Expand Up @@ -472,7 +471,6 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
emitSkipped = true;
return;
}
const version = ts.version; // Extracted into a const so the form is stable between namespace and module
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
}

Expand Down Expand Up @@ -5210,7 +5208,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
* Returns a value indicating whether a name is unique globally or within the current file.
*/
function isFileLevelUniqueName(name: string) {
return currentSourceFile ? ts.isFileLevelUniqueName(currentSourceFile, name, hasGlobalName) : true;
return currentSourceFile ? isFileLevelUniqueNameInternal(currentSourceFile, name, hasGlobalName) : true;
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as ts from "./_namespaces/ts";
import { performance } from "./_namespaces/ts";
import { convertToObjectWorker } from "./commandLineParser";
import {
addRange, append, AssertionLevel, concatenate, emptyArray, emptyMap, findIndex, forEach, getSpellingSuggestion,
Expand All @@ -12,13 +10,15 @@ import { BaseNodeFactory } from "./factory/baseNodeFactory";
import { createNodeFactory, NodeFactoryFlags } from "./factory/nodeFactory";
import {
isAsyncModifier, isExportAssignment, isExportDeclaration, isExportModifier, isExternalModuleReference,
isFunctionTypeNode, isImportDeclaration, isImportEqualsDeclaration, isJSDocFunctionType, isJSDocNullableType,
isJSDocReturnTag, isJSDocTypeTag, isJsxOpeningElement, isJsxOpeningFragment, isMetaProperty, isNonNullExpression,
isPrivateIdentifier, isTaggedTemplateExpression, isTypeReferenceNode,
isFunctionTypeNode, isIdentifier as isIdentifierNode, isImportDeclaration, isImportEqualsDeclaration,
isJSDocFunctionType, isJSDocNullableType, isJSDocReturnTag, isJSDocTypeTag, isJsxOpeningElement,
isJsxOpeningFragment, isMetaProperty, isNonNullExpression, isPrivateIdentifier, isTaggedTemplateExpression,
isTypeReferenceNode,
} from "./factory/nodeTests";
import { setTextRange } from "./factory/utilitiesPublic";
import { fileExtensionIsOneOf, normalizePath } from "./path";
import { perfLogger } from "./perfLogger";
import * as performance from "./performance";
import {
createScanner, getLeadingCommentRanges, isIdentifierText, skipTrivia, textToKeywordObj, tokenIsIdentifierOrKeyword,
tokenIsIdentifierOrKeywordOrGreaterThan, tokenToString,
Expand Down Expand Up @@ -1757,7 +1757,7 @@ namespace Parser {
}

// Otherwise, if this isn't a well-known keyword-like identifier, give the generic fallback message.
const expressionText = ts.isIdentifier(node) ? idText(node) : undefined;
const expressionText = isIdentifierNode(node) ? idText(node) : undefined;
if (!expressionText || !isIdentifierText(expressionText, languageVersion)) {
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.SemicolonToken));
return;
Expand Down Expand Up @@ -6335,7 +6335,7 @@ namespace Parser {
let node: ExpressionStatement | LabeledStatement;
const hasParen = token() === SyntaxKind.OpenParenToken;
const expression = allowInAnd(parseExpression);
if (ts.isIdentifier(expression) && parseOptional(SyntaxKind.ColonToken)) {
if (isIdentifierNode(expression) && parseOptional(SyntaxKind.ColonToken)) {
node = factory.createLabeledStatement(expression, parseStatement());
}
else {
Expand Down Expand Up @@ -8393,7 +8393,7 @@ namespace Parser {
case SyntaxKind.ArrayType:
return isObjectOrObjectArrayTypeReference((node as ArrayTypeNode).elementType);
default:
return isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments;
return isTypeReferenceNode(node) && isIdentifierNode(node.typeName) && node.typeName.escapedText === "Object" && !node.typeArguments;
}
}

Expand Down Expand Up @@ -8664,8 +8664,8 @@ namespace Parser {
}

function escapedTextsEqual(a: EntityName, b: EntityName): boolean {
while (!ts.isIdentifier(a) || !ts.isIdentifier(b)) {
if (!ts.isIdentifier(a) && !ts.isIdentifier(b) && a.right.escapedText === b.right.escapedText) {
while (!isIdentifierNode(a) || !isIdentifierNode(b)) {
if (!isIdentifierNode(a) && !isIdentifierNode(b) && a.right.escapedText === b.right.escapedText) {
a = a.left;
b = b.left;
}
Expand All @@ -8690,7 +8690,7 @@ namespace Parser {
const child = tryParseChildTag(target, indent);
if (child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) &&
target !== PropertyLikeParse.CallbackParameter &&
name && (ts.isIdentifier(child.name) || !escapedTextsEqual(name, child.name.left))) {
name && (isIdentifierNode(child.name) || !escapedTextsEqual(name, child.name.left))) {
return false;
}
return child;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ts from "./_namespaces/ts";
import { performance } from "./_namespaces/ts";
import { BuilderProgram } from "./builderPublic";
import { createTypeChecker } from "./checker";
import {
Expand Down Expand Up @@ -42,8 +41,9 @@ import {
ensureTrailingDirectorySeparator, fileExtensionIs, fileExtensionIsOneOf, forEachAncestorDirectory, getBaseFileName,
getDirectoryPath, getNormalizedAbsolutePath, getNormalizedAbsolutePathWithoutRoot, getNormalizedPathComponents,
getPathFromPathComponents, getRootLength, hasExtension, isRootedDiskPath, normalizePath, pathIsAbsolute,
pathIsRelative,
pathIsRelative, toPath as toPathInternal,
} from "./path";
import * as performance from "./performance";
import {
computeLineAndCharacterOfPosition, getLineAndCharacterOfPosition, getLineStarts, getPositionOfLineAndCharacter,
isIdentifierText, skipTrivia, tokenToString,
Expand Down Expand Up @@ -1570,7 +1570,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}

function toPath(fileName: string): Path {
return ts.toPath(fileName, currentDirectory, getCanonicalFileName);
return toPathInternal(fileName, currentDirectory, getCanonicalFileName);
}

function getCommonSourceDirectory() {
Expand Down
Loading

0 comments on commit 0192dc8

Please sign in to comment.