Skip to content

Commit ae28cfb

Browse files
author
Andy Hanson
committed
Remove unused internal utilities
1 parent eee4c61 commit ae28cfb

File tree

3 files changed

+7
-196
lines changed

3 files changed

+7
-196
lines changed

src/compiler/transformers/jsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace ts {
114114
compilerOptions.reactNamespace,
115115
tagName,
116116
objectProperties,
117-
filter(map(children, transformJsxChildToExpression), isDefined),
117+
mapDefined(children, transformJsxChildToExpression),
118118
node,
119119
location
120120
);

src/compiler/utilities.ts

Lines changed: 5 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ namespace ts {
2626
return undefined;
2727
}
2828

29-
export function findDeclaration<T extends Declaration>(symbol: Symbol, predicate: (node: Declaration) => node is T): T | undefined;
30-
export function findDeclaration(symbol: Symbol, predicate: (node: Declaration) => boolean): Declaration | undefined;
31-
export function findDeclaration(symbol: Symbol, predicate: (node: Declaration) => boolean): Declaration | undefined {
32-
const declarations = symbol.declarations;
33-
if (declarations) {
34-
for (const declaration of declarations) {
35-
if (predicate(declaration)) {
36-
return declaration;
37-
}
38-
}
39-
}
40-
return undefined;
41-
}
42-
4329
export interface StringSymbolWriter extends SymbolWriter {
4430
string(): string;
4531
}
@@ -115,19 +101,16 @@ namespace ts {
115101
sourceFile.resolvedTypeReferenceDirectiveNames.set(typeReferenceDirectiveName, resolvedTypeReferenceDirective);
116102
}
117103

118-
/* @internal */
119104
export function moduleResolutionIsEqualTo(oldResolution: ResolvedModuleFull, newResolution: ResolvedModuleFull): boolean {
120105
return oldResolution.isExternalLibraryImport === newResolution.isExternalLibraryImport &&
121106
oldResolution.extension === newResolution.extension &&
122107
oldResolution.resolvedFileName === newResolution.resolvedFileName;
123108
}
124109

125-
/* @internal */
126110
export function typeDirectiveIsEqualTo(oldResolution: ResolvedTypeReferenceDirective, newResolution: ResolvedTypeReferenceDirective): boolean {
127111
return oldResolution.resolvedFileName === newResolution.resolvedFileName && oldResolution.primary === newResolution.primary;
128112
}
129113

130-
/* @internal */
131114
export function hasChangesInResolutions<T>(names: string[], newResolutions: T[], oldResolutions: Map<T>, comparer: (oldResolution: T, newResolution: T) => boolean): boolean {
132115
Debug.assert(names.length === newResolutions.length);
133116

@@ -202,14 +185,6 @@ namespace ts {
202185
return `${file.fileName}(${loc.line + 1},${loc.character + 1})`;
203186
}
204187

205-
export function getStartPosOfNode(node: Node): number {
206-
return node.pos;
207-
}
208-
209-
export function isDefined(value: any): boolean {
210-
return value !== undefined;
211-
}
212-
213188
export function getEndLinePosition(line: number, sourceFile: SourceFileLike): number {
214189
Debug.assert(line >= 0);
215190
const lineStarts = getLineStarts(sourceFile);
@@ -431,7 +406,7 @@ namespace ts {
431406
return isExternalModule(node) || compilerOptions.isolatedModules;
432407
}
433408

434-
export function isBlockScope(node: Node, parentNode: Node) {
409+
function isBlockScope(node: Node, parentNode: Node) {
435410
switch (node.kind) {
436411
case SyntaxKind.SourceFile:
437412
case SyntaxKind.CaseBlock:
@@ -632,28 +607,24 @@ namespace ts {
632607
return getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
633608
}
634609

635-
export function getLeadingCommentRangesOfNodeFromText(node: Node, text: string) {
636-
return getLeadingCommentRanges(text, node.pos);
637-
}
638-
639610
export function getJSDocCommentRanges(node: Node, text: string) {
640611
const commentRanges = (node.kind === SyntaxKind.Parameter ||
641612
node.kind === SyntaxKind.TypeParameter ||
642613
node.kind === SyntaxKind.FunctionExpression ||
643614
node.kind === SyntaxKind.ArrowFunction ||
644615
node.kind === SyntaxKind.ParenthesizedExpression) ?
645616
concatenate(getTrailingCommentRanges(text, node.pos), getLeadingCommentRanges(text, node.pos)) :
646-
getLeadingCommentRangesOfNodeFromText(node, text);
617+
getLeadingCommentRanges(text, node.pos);
647618
// True if the comment starts with '/**' but not if it is '/**/'
648619
return filter(commentRanges, comment =>
649620
text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk &&
650621
text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk &&
651622
text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash);
652623
}
653624

654-
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
655-
export let fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*<reference\s+types\s*=\s*)('|")(.+?)\2.*?\/>/;
656-
export let fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
625+
export const fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
626+
export const fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*<reference\s+types\s*=\s*)('|")(.+?)\2.*?\/>/;
627+
export const fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
657628

658629
export function isPartOfTypeNode(node: Node): boolean {
659630
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
@@ -2067,10 +2038,6 @@ namespace ts {
20672038
return getParseTreeNode(sourceFile, isSourceFile) || sourceFile;
20682039
}
20692040

2070-
export function getOriginalSourceFiles(sourceFiles: SourceFile[]) {
2071-
return sameMap(sourceFiles, getOriginalSourceFile);
2072-
}
2073-
20742041
export const enum Associativity {
20752042
Left,
20762043
Right
@@ -3056,24 +3023,6 @@ namespace ts {
30563023
return false;
30573024
}
30583025

3059-
// Returns false if this heritage clause element's expression contains something unsupported
3060-
// (i.e. not a name or dotted name).
3061-
export function isSupportedExpressionWithTypeArguments(node: ExpressionWithTypeArguments): boolean {
3062-
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
3063-
}
3064-
3065-
function isSupportedExpressionWithTypeArgumentsRest(node: Expression): boolean {
3066-
if (node.kind === SyntaxKind.Identifier) {
3067-
return true;
3068-
}
3069-
else if (isPropertyAccessExpression(node)) {
3070-
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
3071-
}
3072-
else {
3073-
return false;
3074-
}
3075-
}
3076-
30773026
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
30783027
return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined;
30793028
}
@@ -3210,81 +3159,6 @@ namespace ts {
32103159
return carriageReturnLineFeed;
32113160
}
32123161

3213-
/**
3214-
* Tests whether a node and its subtree is simple enough to have its position
3215-
* information ignored when emitting source maps in a destructuring assignment.
3216-
*
3217-
* @param node The expression to test.
3218-
*/
3219-
export function isSimpleExpression(node: Expression): boolean {
3220-
return isSimpleExpressionWorker(node, 0);
3221-
}
3222-
3223-
function isSimpleExpressionWorker(node: Expression, depth: number): boolean {
3224-
if (depth <= 5) {
3225-
const kind = node.kind;
3226-
if (kind === SyntaxKind.StringLiteral
3227-
|| kind === SyntaxKind.NumericLiteral
3228-
|| kind === SyntaxKind.RegularExpressionLiteral
3229-
|| kind === SyntaxKind.NoSubstitutionTemplateLiteral
3230-
|| kind === SyntaxKind.Identifier
3231-
|| kind === SyntaxKind.ThisKeyword
3232-
|| kind === SyntaxKind.SuperKeyword
3233-
|| kind === SyntaxKind.TrueKeyword
3234-
|| kind === SyntaxKind.FalseKeyword
3235-
|| kind === SyntaxKind.NullKeyword) {
3236-
return true;
3237-
}
3238-
else if (kind === SyntaxKind.PropertyAccessExpression) {
3239-
return isSimpleExpressionWorker((<PropertyAccessExpression>node).expression, depth + 1);
3240-
}
3241-
else if (kind === SyntaxKind.ElementAccessExpression) {
3242-
return isSimpleExpressionWorker((<ElementAccessExpression>node).expression, depth + 1)
3243-
&& isSimpleExpressionWorker((<ElementAccessExpression>node).argumentExpression, depth + 1);
3244-
}
3245-
else if (kind === SyntaxKind.PrefixUnaryExpression
3246-
|| kind === SyntaxKind.PostfixUnaryExpression) {
3247-
return isSimpleExpressionWorker((<PrefixUnaryExpression | PostfixUnaryExpression>node).operand, depth + 1);
3248-
}
3249-
else if (kind === SyntaxKind.BinaryExpression) {
3250-
return (<BinaryExpression>node).operatorToken.kind !== SyntaxKind.AsteriskAsteriskToken
3251-
&& isSimpleExpressionWorker((<BinaryExpression>node).left, depth + 1)
3252-
&& isSimpleExpressionWorker((<BinaryExpression>node).right, depth + 1);
3253-
}
3254-
else if (kind === SyntaxKind.ConditionalExpression) {
3255-
return isSimpleExpressionWorker((<ConditionalExpression>node).condition, depth + 1)
3256-
&& isSimpleExpressionWorker((<ConditionalExpression>node).whenTrue, depth + 1)
3257-
&& isSimpleExpressionWorker((<ConditionalExpression>node).whenFalse, depth + 1);
3258-
}
3259-
else if (kind === SyntaxKind.VoidExpression
3260-
|| kind === SyntaxKind.TypeOfExpression
3261-
|| kind === SyntaxKind.DeleteExpression) {
3262-
return isSimpleExpressionWorker((<VoidExpression | TypeOfExpression | DeleteExpression>node).expression, depth + 1);
3263-
}
3264-
else if (kind === SyntaxKind.ArrayLiteralExpression) {
3265-
return (<ArrayLiteralExpression>node).elements.length === 0;
3266-
}
3267-
else if (kind === SyntaxKind.ObjectLiteralExpression) {
3268-
return (<ObjectLiteralExpression>node).properties.length === 0;
3269-
}
3270-
else if (kind === SyntaxKind.CallExpression) {
3271-
if (!isSimpleExpressionWorker((<CallExpression>node).expression, depth + 1)) {
3272-
return false;
3273-
}
3274-
3275-
for (const argument of (<CallExpression>node).arguments) {
3276-
if (!isSimpleExpressionWorker(argument, depth + 1)) {
3277-
return false;
3278-
}
3279-
}
3280-
3281-
return true;
3282-
}
3283-
}
3284-
3285-
return false;
3286-
}
3287-
32883162
/**
32893163
* Formats an enum value as a string for debugging and debug assertions.
32903164
*/
@@ -3357,24 +3231,6 @@ namespace ts {
33573231
return formatEnum(flags, (<any>ts).ObjectFlags, /*isFlags*/ true);
33583232
}
33593233

3360-
export function getRangePos(range: TextRange | undefined) {
3361-
return range ? range.pos : -1;
3362-
}
3363-
3364-
export function getRangeEnd(range: TextRange | undefined) {
3365-
return range ? range.end : -1;
3366-
}
3367-
3368-
/**
3369-
* Increases (or decreases) a position by the provided amount.
3370-
*
3371-
* @param pos The position.
3372-
* @param value The delta.
3373-
*/
3374-
export function movePos(pos: number, value: number) {
3375-
return positionIsSynthesized(pos) ? -1 : pos + value;
3376-
}
3377-
33783234
/**
33793235
* Creates a new TextRange from the provided pos and end.
33803236
*
@@ -3432,26 +3288,6 @@ namespace ts {
34323288
return range.pos === range.end;
34333289
}
34343290

3435-
/**
3436-
* Creates a new TextRange from a provided range with its end position collapsed to its
3437-
* start position.
3438-
*
3439-
* @param range A TextRange.
3440-
*/
3441-
export function collapseRangeToStart(range: TextRange): TextRange {
3442-
return isCollapsedRange(range) ? range : moveRangeEnd(range, range.pos);
3443-
}
3444-
3445-
/**
3446-
* Creates a new TextRange from a provided range with its start position collapsed to its
3447-
* end position.
3448-
*
3449-
* @param range A TextRange.
3450-
*/
3451-
export function collapseRangeToEnd(range: TextRange): TextRange {
3452-
return isCollapsedRange(range) ? range : moveRangePos(range, range.end);
3453-
}
3454-
34553291
/**
34563292
* Creates a new TextRange for a token at the provides start position.
34573293
*
@@ -3515,31 +3351,6 @@ namespace ts {
35153351
return node.initializer !== undefined;
35163352
}
35173353

3518-
/**
3519-
* Gets a value indicating whether a node is merged with a class declaration in the same scope.
3520-
*/
3521-
export function isMergedWithClass(node: Node) {
3522-
if (node.symbol) {
3523-
for (const declaration of node.symbol.declarations) {
3524-
if (declaration.kind === SyntaxKind.ClassDeclaration && declaration !== node) {
3525-
return true;
3526-
}
3527-
}
3528-
}
3529-
3530-
return false;
3531-
}
3532-
3533-
/**
3534-
* Gets a value indicating whether a node is the first declaration of its kind.
3535-
*
3536-
* @param node A Declaration node.
3537-
* @param kind The SyntaxKind to find among related declarations.
3538-
*/
3539-
export function isFirstDeclarationOfKind(node: Node, kind: SyntaxKind) {
3540-
return node.symbol && getDeclarationOfKind(node.symbol, kind) === node;
3541-
}
3542-
35433354
export function isWatchSet(options: CompilerOptions) {
35443355
// Firefox has Object.prototype.watch
35453356
return options.watch && options.hasOwnProperty("watch");

src/services/symbolDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace ts.SymbolDisplay {
203203
// get the signature from the declaration and write it
204204
const functionDeclaration = <FunctionLike>location.parent;
205205
// Use function declaration to write the signatures only if the symbol corresponding to this declaration
206-
const locationIsSymbolDeclaration = findDeclaration(symbol, declaration =>
206+
const locationIsSymbolDeclaration = find(symbol.declarations, declaration =>
207207
declaration === (location.kind === SyntaxKind.ConstructorKeyword ? functionDeclaration.parent : functionDeclaration));
208208

209209
if (locationIsSymbolDeclaration) {

0 commit comments

Comments
 (0)