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 27, 2022
1 parent 4bc100d commit 1fe1940
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 73 deletions.
3 changes: 1 addition & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import { getNodeId } from "./checker";
import {
append, appendIfUnique, cast, concatenate, contains, every, forEach, getRangesWhere, isString, length, Pattern,
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
15 changes: 7 additions & 8 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import { convertToObjectWorker } from "./commandLineParser";
import {
addRange, append, AssertionLevel, concatenate, emptyArray, emptyMap, findIndex, forEach, getSpellingSuggestion,
Expand All @@ -13,7 +12,7 @@ import {
isAsyncModifier, isExportAssignment, isExportDeclaration, isExportModifier, isExternalModuleReference,
isFunctionTypeNode, isImportDeclaration, isImportEqualsDeclaration, isJSDocFunctionType, isJSDocNullableType,
isJSDocReturnTag, isJSDocTypeTag, isJsxOpeningElement, isJsxOpeningFragment, isMetaProperty, isNonNullExpression,
isPrivateIdentifier, isTaggedTemplateExpression, isTypeReferenceNode,
isPrivateIdentifier, isTaggedTemplateExpression, isTypeReferenceNode, isIdentifier as isIdentifierNode,
} from "./factory/nodeTests";
import { setTextRange } from "./factory/utilitiesPublic";
import { fileExtensionIsOneOf, normalizePath } from "./path";
Expand Down Expand Up @@ -1757,7 +1756,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 +6334,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 +8392,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 +8663,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 +8689,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/resolutionCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import {
arrayToMap, contains, createMultiMap, emptyIterator, endsWith, firstDefinedIterator, GetCanonicalFileName, isString,
length, memoize, removeSuffix, returnTrue, some, startsWith, stringContains, unorderedRemoveItem,
Expand All @@ -10,6 +9,7 @@ import {
CacheWithRedirects, createCacheWithRedirects, createModeAwareCache, createModuleResolutionCache,
createTypeReferenceDirectiveResolutionCache, getEffectiveTypeRoots, isTraceEnabled, loadModuleFromGlobalCache,
ModeAwareCache, ModuleResolutionCache, parseNodeModuleFromPath, pathContainsNodeModules, PerModuleNameCache, trace,
resolveTypeReferenceDirective as internalResolveTypeReferenceDirective, resolveModuleName as internalResolveModuleName,
} from "./moduleNameResolver";
import {
directorySeparator, fileExtensionIs, fileExtensionIsOneOf, getDirectoryPath, getNormalizedAbsolutePath,
Expand Down Expand Up @@ -349,7 +349,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
}

function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: never, mode?: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): CachedResolvedModuleWithFailedLookupLocations {
const primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
const primaryResult = internalResolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
// return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
if (!resolutionHost.getGlobalCache) {
return primaryResult;
Expand Down Expand Up @@ -381,7 +381,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
}

function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: SourceFile, resolutionMode?: SourceFile["impliedNodeFormat"] | undefined): CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations {
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
return internalResolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
}

interface ResolveNamesWithLocalCacheInput<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName> {
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/transformers/declarations/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "../../_namespaces/ts";
import { Debug } from "../../debug";
import { Diagnostics } from "../../diagnosticInformationMap.generated";
import {
Expand Down Expand Up @@ -185,7 +184,7 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
return getTypeAliasDeclarationVisibilityError;
}
else {
return Debug.assertNever(node, `Attempted to set a declaration diagnostic context for unhandled node kind: ${(ts as any).SyntaxKind[(node as any).kind]}`);
return Debug.assertNever(node, `Attempted to set a declaration diagnostic context for unhandled node kind: ${Debug.formatSyntaxKind((node as any).kind)}`);
}

function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
Expand Down Expand Up @@ -414,7 +413,7 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
Diagnostics.Parameter_0_of_accessor_has_or_is_using_private_name_1;

default:
return Debug.fail(`Unknown parent for parameter: ${(ts as any).SyntaxKind[node.parent.kind]}`);
return Debug.fail(`Unknown parent for parameter: ${Debug.formatSyntaxKind(node.parent.kind)}`);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import {
AffectedFileResult, BuilderProgram, EmitAndSemanticDiagnosticsBuilderProgram, SemanticDiagnosticsBuilderProgram,
} from "./builderPublic";
Expand All @@ -23,7 +22,7 @@ import {
resolveTypeReferenceDirective, TypeReferenceDirectiveResolutionCache,
} from "./moduleNameResolver";
import { isDeclarationFileName } from "./parser";
import { convertToRelativePath, getDirectoryPath, resolvePath } from "./path";
import { convertToRelativePath, getDirectoryPath, resolvePath, toPath as internalToPath } from "./path";
import {
changeCompilerHostLikeToUseCache, flattenDiagnosticMessageText, ForegroundColorEscapeSequences, formatColorAndReset,
getConfigFileParsingDiagnostics, loadWithModeAwareCache, loadWithTypeDirectiveCache,
Expand Down Expand Up @@ -408,7 +407,7 @@ function createSolutionBuilderState<T extends BuilderProgram>(watch: boolean, ho
}

function toPath(state: SolutionBuilderState, fileName: string) {
return ts.toPath(fileName, state.currentDirectory, state.getCanonicalFileName);
return internalToPath(fileName, state.currentDirectory, state.getCanonicalFileName);
}

function toResolvedConfigFilePath(state: SolutionBuilderState, fileName: ResolvedConfigFileName): ResolvedConfigFilePath {
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import {
BuilderProgram, createEmitAndSemanticDiagnosticsBuilderProgram, EmitAndSemanticDiagnosticsBuilderProgram,
} from "./builderPublic";
Expand Down Expand Up @@ -42,7 +41,7 @@ import {
createIncrementalCompilerHost, createIncrementalProgram, CreateProgram, ProgramHost, WatchCompilerHost,
WatchCompilerHostOfConfigFile, WatchCompilerHostOfFilesAndCompilerOptions, WatchHost, WatchStatusReporter,
} from "./watchPublic";
import { DirectoryStructureHost, getWatchFactory, WatchFactoryHost, WatchLogLevel } from "./watchUtilities";
import { DirectoryStructureHost, getWatchFactory, WatchFactoryHost, WatchLogLevel, WatchFactory as InternalWatchFactory } from "./watchUtilities";

const sysFormatDiagnosticsHost: FormatDiagnosticsHost | undefined = sys ? {
getCurrentDirectory: () => sys.getCurrentDirectory(),
Expand Down Expand Up @@ -613,7 +612,7 @@ export interface WatchTypeRegistry {
NodeModulesForModuleSpecifierCache: "node_modules for module specifier cache invalidation",
}

interface WatchFactory<X, Y = undefined> extends ts.WatchFactory<X, Y> {
interface WatchFactory<X, Y = undefined> extends InternalWatchFactory<X, Y> {
writeLog: (s: string) => void;
}

Expand Down
8 changes: 0 additions & 8 deletions src/debug/dbg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Debug from "./_namespaces/Debug";

/// <reference lib="es2019" />

interface Node {
Expand Down Expand Up @@ -510,9 +508,3 @@ export function formatControlFlowGraph(flowNode: FlowNode) {
return s;
}
}

// Export as a module. NOTE: Can't use module exports as this is built using --outFile
declare const module: { exports: {} };
if (typeof module !== "undefined" && module.exports) {
module.exports = Debug;
}
Loading

0 comments on commit 1fe1940

Please sign in to comment.