Skip to content

Commit 1ade73d

Browse files
authored
Stop calling our own @deprecrated APIs (#46831)
* Clean up createMap * Delete dead createMapFromTemplate * Clean up assertDefined * Delete dead assertEachDefined * Delete dead createUnderscoreEscapedMap * Delete dead hasEntries * Delete dead ReadonlyNodeSet, NodeSet, ReadonlyNodeMap, NodeMap * Use updated SyntaxKind names * Update API baselines
1 parent de4ba0f commit 1ade73d

File tree

13 files changed

+23
-90
lines changed

13 files changed

+23
-90
lines changed

src/compiler/core.ts

-28
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@ namespace ts {
2323
export const emptyMap: ReadonlyESMap<never, never> = new Map<never, never>();
2424
export const emptySet: ReadonlySet<never> = new Set<never>();
2525

26-
/**
27-
* Create a new map.
28-
* @deprecated Use `new Map()` instead.
29-
*/
30-
export function createMap<K, V>(): ESMap<K, V>;
31-
export function createMap<T>(): ESMap<string, T>;
32-
export function createMap<K, V>(): ESMap<K, V> {
33-
return new Map<K, V>();
34-
}
35-
36-
/**
37-
* Create a new map from a template object is provided, the map will copy entries from it.
38-
* @deprecated Use `new Map(getEntries(template))` instead.
39-
*/
40-
export function createMapFromTemplate<T>(template: MapLike<T>): ESMap<string, T> {
41-
const map: ESMap<string, T> = new Map<string, T>();
42-
43-
// Copies keys/values from template. Note that for..in will not throw if
44-
// template is undefined, and instead will just exit the loop.
45-
for (const key in template) {
46-
if (hasOwnProperty.call(template, key)) {
47-
map.set(key, template[key]);
48-
}
49-
}
50-
51-
return map;
52-
}
53-
5426
export function length(array: readonly any[] | undefined): number {
5527
return array ? array.length : 0;
5628
}

src/compiler/debug.ts

-12
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,6 @@ namespace ts {
171171
return value;
172172
}
173173

174-
/**
175-
* @deprecated Use `checkDefined` to check whether a value is defined inline. Use `assertIsDefined` to check whether
176-
* a value is defined at the statement level.
177-
*/
178-
export const assertDefined = checkDefined;
179-
180174
export function assertEachIsDefined<T extends Node>(value: NodeArray<T>, message?: string, stackCrawlMark?: AnyFunction): asserts value is NodeArray<T>;
181175
export function assertEachIsDefined<T>(value: readonly T[], message?: string, stackCrawlMark?: AnyFunction): asserts value is readonly NonNullable<T>[];
182176
export function assertEachIsDefined<T>(value: readonly T[], message?: string, stackCrawlMark?: AnyFunction) {
@@ -190,12 +184,6 @@ namespace ts {
190184
return value;
191185
}
192186

193-
/**
194-
* @deprecated Use `checkEachDefined` to check whether the elements of an array are defined inline. Use `assertEachIsDefined` to check whether
195-
* the elements of an array are defined at the statement level.
196-
*/
197-
export const assertEachDefined = checkEachDefined;
198-
199187
export function assertNever(member: never, message = "Illegal value:", stackCrawlMark?: AnyFunction): never {
200188
const detail = typeof member === "object" && hasProperty(member, "kind") && hasProperty(member, "pos") && formatSyntaxKind ? "SyntaxKind: " + formatSyntaxKind((member as Node).kind) : JSON.stringify(member);
201189
return fail(`${message} ${detail}`, stackCrawlMark || assertNever);

src/compiler/factory/nodeFactory.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6387,7 +6387,7 @@ namespace ts {
63876387
sourceMapText = mapTextOrStripInternal as string;
63886388
}
63896389
const node = oldFileOfCurrentEmit ?
6390-
parseOldFileOfCurrentEmit(Debug.assertDefined(bundleFileInfo)) :
6390+
parseOldFileOfCurrentEmit(Debug.checkDefined(bundleFileInfo)) :
63916391
parseUnparsedSourceFile(bundleFileInfo, stripInternal, length);
63926392
node.fileName = fileName;
63936393
node.sourceMapPath = sourceMapPath;
@@ -6587,13 +6587,13 @@ namespace ts {
65876587
};
65886588
node.javascriptPath = declarationTextOrJavascriptPath;
65896589
node.javascriptMapPath = javascriptMapPath;
6590-
node.declarationPath = Debug.assertDefined(javascriptMapTextOrDeclarationPath);
6590+
node.declarationPath = Debug.checkDefined(javascriptMapTextOrDeclarationPath);
65916591
node.declarationMapPath = declarationMapPath;
65926592
node.buildInfoPath = declarationMapTextOrBuildInfoPath;
65936593
Object.defineProperties(node, {
65946594
javascriptText: { get() { return definedTextGetter(declarationTextOrJavascriptPath); } },
65956595
javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, // TODO:: if there is inline sourceMap in jsFile, use that
6596-
declarationText: { get() { return definedTextGetter(Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
6596+
declarationText: { get() { return definedTextGetter(Debug.checkDefined(javascriptMapTextOrDeclarationPath)); } },
65976597
declarationMapText: { get() { return textGetter(declarationMapPath); } }, // TODO:: if there is inline sourceMap in dtsFile, use that
65986598
buildInfo: { get() { return getAndCacheBuildInfo(() => textGetter(declarationMapTextOrBuildInfoPath)); } }
65996599
});

src/compiler/resolutionCache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ namespace ts {
619619
) {
620620
if (resolution.refCount) {
621621
resolution.refCount++;
622-
Debug.assertDefined(resolution.files);
622+
Debug.assertIsDefined(resolution.files);
623623
}
624624
else {
625625
resolution.refCount = 1;
@@ -696,7 +696,7 @@ namespace ts {
696696
filePath: Path,
697697
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>,
698698
) {
699-
unorderedRemoveItem(Debug.assertDefined(resolution.files), filePath);
699+
unorderedRemoveItem(Debug.checkDefined(resolution.files), filePath);
700700
resolution.refCount!--;
701701
if (resolution.refCount) {
702702
return;
@@ -798,7 +798,7 @@ namespace ts {
798798
for (const resolution of resolutions) {
799799
if (resolution.isInvalidated || !canInvalidate(resolution)) continue;
800800
resolution.isInvalidated = invalidated = true;
801-
for (const containingFilePath of Debug.assertDefined(resolution.files)) {
801+
for (const containingFilePath of Debug.checkDefined(resolution.files)) {
802802
(filesWithInvalidatedResolutions || (filesWithInvalidatedResolutions = new Set())).add(containingFilePath);
803803
// When its a file with inferred types resolution, invalidate type reference directive resolution
804804
hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames || endsWith(containingFilePath, inferredTypesContainingFile);

src/compiler/transformers/es2018.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ namespace ts {
282282
function visitYieldExpression(node: YieldExpression) {
283283
if (enclosingFunctionFlags & FunctionFlags.Async && enclosingFunctionFlags & FunctionFlags.Generator) {
284284
if (node.asteriskToken) {
285-
const expression = visitNode(Debug.assertDefined(node.expression), visitor, isExpression);
285+
const expression = visitNode(Debug.checkDefined(node.expression), visitor, isExpression);
286286

287287
return setOriginalNode(
288288
setTextRange(

src/compiler/transformers/jsx.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ namespace ts {
4848
return existing.name;
4949
}
5050
if (!currentFileState.utilizedImplicitRuntimeImports) {
51-
currentFileState.utilizedImplicitRuntimeImports = createMap();
51+
currentFileState.utilizedImplicitRuntimeImports = new Map();
5252
}
5353
let specifierSourceImports = currentFileState.utilizedImplicitRuntimeImports.get(importSource);
5454
if (!specifierSourceImports) {
55-
specifierSourceImports = createMap();
55+
specifierSourceImports = new Map();
5656
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
5757
}
5858
const generatedName = factory.createUniqueName(`_${name}`, GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel | GeneratedIdentifierFlags.AllowNameSubstitution);

src/compiler/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ namespace ts {
16091609
export interface TypePredicateNode extends TypeNode {
16101610
readonly kind: SyntaxKind.TypePredicate;
16111611
readonly parent: SignatureDeclaration | JSDocTypeExpression;
1612-
readonly assertsModifier?: AssertsToken;
1612+
readonly assertsModifier?: AssertsKeyword;
16131613
readonly parameterName: Identifier | ThisTypeNode;
16141614
readonly type?: TypeNode;
16151615
}
@@ -1702,7 +1702,7 @@ namespace ts {
17021702

17031703
export interface MappedTypeNode extends TypeNode, Declaration {
17041704
readonly kind: SyntaxKind.MappedType;
1705-
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
1705+
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
17061706
readonly typeParameter: TypeParameterDeclaration;
17071707
readonly nameType?: TypeNode;
17081708
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@@ -2756,7 +2756,7 @@ namespace ts {
27562756

27572757
export interface ForOfStatement extends IterationStatement {
27582758
readonly kind: SyntaxKind.ForOfStatement;
2759-
readonly awaitModifier?: AwaitKeywordToken;
2759+
readonly awaitModifier?: AwaitKeyword;
27602760
readonly initializer: ForInitializer;
27612761
readonly expression: Expression;
27622762
}

src/compiler/utilities.ts

-27
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ namespace ts {
2020
return undefined;
2121
}
2222

23-
/**
24-
* Create a new escaped identifier map.
25-
* @deprecated Use `new Map<__String, T>()` instead.
26-
*/
27-
export function createUnderscoreEscapedMap<T>(): UnderscoreEscapedMap<T> {
28-
return new Map<__String, T>();
29-
}
30-
31-
/**
32-
* @deprecated Use `!!map?.size` instead
33-
*/
34-
export function hasEntries(map: ReadonlyCollection<any> | undefined): map is ReadonlyCollection<any> {
35-
return !!map && !!map.size;
36-
}
37-
3823
export function createSymbolTable(symbols?: readonly Symbol[]): SymbolTable {
3924
const result = new Map<__String, Symbol>();
4025
if (symbols) {
@@ -6994,18 +6979,6 @@ namespace ts {
69946979
return { min, max };
69956980
}
69966981

6997-
/** @deprecated Use `ReadonlySet<TNode>` instead. */
6998-
export type ReadonlyNodeSet<TNode extends Node> = ReadonlySet<TNode>;
6999-
7000-
/** @deprecated Use `Set<TNode>` instead. */
7001-
export type NodeSet<TNode extends Node> = Set<TNode>;
7002-
7003-
/** @deprecated Use `ReadonlyMap<TNode, TValue>` instead. */
7004-
export type ReadonlyNodeMap<TNode extends Node, TValue> = ReadonlyESMap<TNode, TValue>;
7005-
7006-
/** @deprecated Use `Map<TNode, TValue>` instead. */
7007-
export type NodeMap<TNode extends Node, TValue> = ESMap<TNode, TValue>;
7008-
70096982
export function rangeOfNode(node: Node): TextRange {
70106983
return { pos: getTokenPosOfNode(node), end: node.end };
70116984
}

src/server/session.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ namespace ts.server {
21122112
private getFullNavigateToItems(args: protocol.NavtoRequestArgs): CombineOutputResult<NavigateToItem> {
21132113
const { currentFileOnly, searchValue, maxResultCount, projectFileName } = args;
21142114
if (currentFileOnly) {
2115-
Debug.assertDefined(args.file);
2115+
Debug.assertIsDefined(args.file);
21162116
const { file, project } = this.getFileAndProject(args as protocol.FileRequestArgs);
21172117
return [{ project, result: project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, file) }];
21182118
}

src/services/codefixes/fixImplicitThis.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ namespace ts.codefix {
2626
if (!isFunctionDeclaration(fn) && !isFunctionExpression(fn)) return undefined;
2727

2828
if (!isSourceFile(getThisContainer(fn, /*includeArrowFunctions*/ false))) { // 'this' is defined outside, convert to arrow function
29-
const fnKeyword = Debug.assertDefined(findChildOfKind(fn, SyntaxKind.FunctionKeyword, sourceFile));
29+
const fnKeyword = Debug.checkDefined(findChildOfKind(fn, SyntaxKind.FunctionKeyword, sourceFile));
3030
const { name } = fn;
31-
const body = Debug.assertDefined(fn.body); // Should be defined because the function contained a 'this' expression
31+
const body = Debug.checkDefined(fn.body); // Should be defined because the function contained a 'this' expression
3232
if (isFunctionExpression(fn)) {
3333
if (name && FindAllReferences.Core.isSymbolReferencedInFile(name, checker, sourceFile, body)) {
3434
// Function expression references itself. To fix we would have to extract it to a const.

src/testRunner/unittests/tsserver/autoImportProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ namespace ts.projectSystem {
326326
};
327327

328328
function updateFile(path: string, newText: string) {
329-
Debug.assertDefined(files.find(f => f.path === path));
329+
Debug.assertIsDefined(files.find(f => f.path === path));
330330
session.executeCommandSeq<protocol.ApplyChangedToOpenFilesRequest>({
331331
command: protocol.CommandTypes.ApplyChangedToOpenFiles,
332332
arguments: {
@@ -339,7 +339,7 @@ namespace ts.projectSystem {
339339
}
340340

341341
function findAllReferences(file: string, line: number, offset: number) {
342-
Debug.assertDefined(files.find(f => f.path === file));
342+
Debug.assertIsDefined(files.find(f => f.path === file));
343343
session.executeCommandSeq<protocol.ReferencesRequest>({
344344
command: protocol.CommandTypes.References,
345345
arguments: {

tests/baselines/reference/api/tsserverlibrary.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ declare namespace ts {
897897
export interface TypePredicateNode extends TypeNode {
898898
readonly kind: SyntaxKind.TypePredicate;
899899
readonly parent: SignatureDeclaration | JSDocTypeExpression;
900-
readonly assertsModifier?: AssertsToken;
900+
readonly assertsModifier?: AssertsKeyword;
901901
readonly parameterName: Identifier | ThisTypeNode;
902902
readonly type?: TypeNode;
903903
}
@@ -968,7 +968,7 @@ declare namespace ts {
968968
}
969969
export interface MappedTypeNode extends TypeNode, Declaration {
970970
readonly kind: SyntaxKind.MappedType;
971-
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
971+
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
972972
readonly typeParameter: TypeParameterDeclaration;
973973
readonly nameType?: TypeNode;
974974
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@@ -1465,7 +1465,7 @@ declare namespace ts {
14651465
}
14661466
export interface ForOfStatement extends IterationStatement {
14671467
readonly kind: SyntaxKind.ForOfStatement;
1468-
readonly awaitModifier?: AwaitKeywordToken;
1468+
readonly awaitModifier?: AwaitKeyword;
14691469
readonly initializer: ForInitializer;
14701470
readonly expression: Expression;
14711471
}

tests/baselines/reference/api/typescript.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ declare namespace ts {
897897
export interface TypePredicateNode extends TypeNode {
898898
readonly kind: SyntaxKind.TypePredicate;
899899
readonly parent: SignatureDeclaration | JSDocTypeExpression;
900-
readonly assertsModifier?: AssertsToken;
900+
readonly assertsModifier?: AssertsKeyword;
901901
readonly parameterName: Identifier | ThisTypeNode;
902902
readonly type?: TypeNode;
903903
}
@@ -968,7 +968,7 @@ declare namespace ts {
968968
}
969969
export interface MappedTypeNode extends TypeNode, Declaration {
970970
readonly kind: SyntaxKind.MappedType;
971-
readonly readonlyToken?: ReadonlyToken | PlusToken | MinusToken;
971+
readonly readonlyToken?: ReadonlyKeyword | PlusToken | MinusToken;
972972
readonly typeParameter: TypeParameterDeclaration;
973973
readonly nameType?: TypeNode;
974974
readonly questionToken?: QuestionToken | PlusToken | MinusToken;
@@ -1465,7 +1465,7 @@ declare namespace ts {
14651465
}
14661466
export interface ForOfStatement extends IterationStatement {
14671467
readonly kind: SyntaxKind.ForOfStatement;
1468-
readonly awaitModifier?: AwaitKeywordToken;
1468+
readonly awaitModifier?: AwaitKeyword;
14691469
readonly initializer: ForInitializer;
14701470
readonly expression: Expression;
14711471
}

0 commit comments

Comments
 (0)