Skip to content

Commit 67a6b20

Browse files
author
Andy Hanson
committed
Remove unused internal utilities
1 parent 61c6ecb commit 67a6b20

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+
children && 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
}
@@ -111,19 +97,16 @@ namespace ts {
11197
sourceFile.resolvedTypeReferenceDirectiveNames.set(typeReferenceDirectiveName, resolvedTypeReferenceDirective);
11298
}
11399

114-
/* @internal */
115100
export function moduleResolutionIsEqualTo(oldResolution: ResolvedModuleFull, newResolution: ResolvedModuleFull): boolean {
116101
return oldResolution.isExternalLibraryImport === newResolution.isExternalLibraryImport &&
117102
oldResolution.extension === newResolution.extension &&
118103
oldResolution.resolvedFileName === newResolution.resolvedFileName;
119104
}
120105

121-
/* @internal */
122106
export function typeDirectiveIsEqualTo(oldResolution: ResolvedTypeReferenceDirective, newResolution: ResolvedTypeReferenceDirective): boolean {
123107
return oldResolution.resolvedFileName === newResolution.resolvedFileName && oldResolution.primary === newResolution.primary;
124108
}
125109

126-
/* @internal */
127110
export function hasChangesInResolutions<T>(
128111
names: ReadonlyArray<string>,
129112
newResolutions: ReadonlyArray<T>,
@@ -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);
@@ -436,7 +411,7 @@ namespace ts {
436411
return isExternalModule(node) || compilerOptions.isolatedModules;
437412
}
438413

439-
export function isBlockScope(node: Node, parentNode: Node) {
414+
function isBlockScope(node: Node, parentNode: Node) {
440415
switch (node.kind) {
441416
case SyntaxKind.SourceFile:
442417
case SyntaxKind.CaseBlock:
@@ -637,28 +612,24 @@ namespace ts {
637612
return getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
638613
}
639614

640-
export function getLeadingCommentRangesOfNodeFromText(node: Node, text: string) {
641-
return getLeadingCommentRanges(text, node.pos);
642-
}
643-
644615
export function getJSDocCommentRanges(node: Node, text: string) {
645616
const commentRanges = (node.kind === SyntaxKind.Parameter ||
646617
node.kind === SyntaxKind.TypeParameter ||
647618
node.kind === SyntaxKind.FunctionExpression ||
648619
node.kind === SyntaxKind.ArrowFunction ||
649620
node.kind === SyntaxKind.ParenthesizedExpression) ?
650621
concatenate(getTrailingCommentRanges(text, node.pos), getLeadingCommentRanges(text, node.pos)) :
651-
getLeadingCommentRangesOfNodeFromText(node, text);
622+
getLeadingCommentRanges(text, node.pos);
652623
// True if the comment starts with '/**' but not if it is '/**/'
653624
return filter(commentRanges, comment =>
654625
text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk &&
655626
text.charCodeAt(comment.pos + 2) === CharacterCodes.asterisk &&
656627
text.charCodeAt(comment.pos + 3) !== CharacterCodes.slash);
657628
}
658629

659-
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
660-
export let fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*<reference\s+types\s*=\s*)('|")(.+?)\2.*?\/>/;
661-
export let fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
630+
export const fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
631+
export const fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*<reference\s+types\s*=\s*)('|")(.+?)\2.*?\/>/;
632+
export const fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
662633

663634
export function isPartOfTypeNode(node: Node): boolean {
664635
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
@@ -2072,10 +2043,6 @@ namespace ts {
20722043
return getParseTreeNode(sourceFile, isSourceFile) || sourceFile;
20732044
}
20742045

2075-
export function getOriginalSourceFiles(sourceFiles: ReadonlyArray<SourceFile>) {
2076-
return sameMap(sourceFiles, getOriginalSourceFile);
2077-
}
2078-
20792046
export const enum Associativity {
20802047
Left,
20812048
Right
@@ -3068,24 +3035,6 @@ namespace ts {
30683035
return false;
30693036
}
30703037

3071-
// Returns false if this heritage clause element's expression contains something unsupported
3072-
// (i.e. not a name or dotted name).
3073-
export function isSupportedExpressionWithTypeArguments(node: ExpressionWithTypeArguments): boolean {
3074-
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
3075-
}
3076-
3077-
function isSupportedExpressionWithTypeArgumentsRest(node: Expression): boolean {
3078-
if (node.kind === SyntaxKind.Identifier) {
3079-
return true;
3080-
}
3081-
else if (isPropertyAccessExpression(node)) {
3082-
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
3083-
}
3084-
else {
3085-
return false;
3086-
}
3087-
}
3088-
30893038
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
30903039
return tryGetClassExtendingExpressionWithTypeArguments(node) !== undefined;
30913040
}
@@ -3222,81 +3171,6 @@ namespace ts {
32223171
return carriageReturnLineFeed;
32233172
}
32243173

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

3372-
export function getRangePos(range: TextRange | undefined) {
3373-
return range ? range.pos : -1;
3374-
}
3375-
3376-
export function getRangeEnd(range: TextRange | undefined) {
3377-
return range ? range.end : -1;
3378-
}
3379-
3380-
/**
3381-
* Increases (or decreases) a position by the provided amount.
3382-
*
3383-
* @param pos The position.
3384-
* @param value The delta.
3385-
*/
3386-
export function movePos(pos: number, value: number) {
3387-
return positionIsSynthesized(pos) ? -1 : pos + value;
3388-
}
3389-
33903246
/**
33913247
* Creates a new TextRange from the provided pos and end.
33923248
*
@@ -3444,26 +3300,6 @@ namespace ts {
34443300
return range.pos === range.end;
34453301
}
34463302

3447-
/**
3448-
* Creates a new TextRange from a provided range with its end position collapsed to its
3449-
* start position.
3450-
*
3451-
* @param range A TextRange.
3452-
*/
3453-
export function collapseRangeToStart(range: TextRange): TextRange {
3454-
return isCollapsedRange(range) ? range : moveRangeEnd(range, range.pos);
3455-
}
3456-
3457-
/**
3458-
* Creates a new TextRange from a provided range with its start position collapsed to its
3459-
* end position.
3460-
*
3461-
* @param range A TextRange.
3462-
*/
3463-
export function collapseRangeToEnd(range: TextRange): TextRange {
3464-
return isCollapsedRange(range) ? range : moveRangePos(range, range.end);
3465-
}
3466-
34673303
/**
34683304
* Creates a new TextRange for a token at the provides start position.
34693305
*
@@ -3527,31 +3363,6 @@ namespace ts {
35273363
return node.initializer !== undefined;
35283364
}
35293365

3530-
/**
3531-
* Gets a value indicating whether a node is merged with a class declaration in the same scope.
3532-
*/
3533-
export function isMergedWithClass(node: Node) {
3534-
if (node.symbol) {
3535-
for (const declaration of node.symbol.declarations) {
3536-
if (declaration.kind === SyntaxKind.ClassDeclaration && declaration !== node) {
3537-
return true;
3538-
}
3539-
}
3540-
}
3541-
3542-
return false;
3543-
}
3544-
3545-
/**
3546-
* Gets a value indicating whether a node is the first declaration of its kind.
3547-
*
3548-
* @param node A Declaration node.
3549-
* @param kind The SyntaxKind to find among related declarations.
3550-
*/
3551-
export function isFirstDeclarationOfKind(node: Node, kind: SyntaxKind) {
3552-
return node.symbol && getDeclarationOfKind(node.symbol, kind) === node;
3553-
}
3554-
35553366
export function isWatchSet(options: CompilerOptions) {
35563367
// Firefox has Object.prototype.watch
35573368
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)