Skip to content

Commit dbf9e47

Browse files
committed
use isDeclarationOrFunctionExpressionOrCatchVariableName instead of isDeclarationIdentifier in the language service and remove unused functions
1 parent 6965a06 commit dbf9e47

File tree

3 files changed

+33
-133
lines changed

3 files changed

+33
-133
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6587,24 +6587,6 @@ module ts {
65876587
(<Declaration>name.parent).name === name;
65886588
}
65896589

6590-
// True if the given identifier, string literal, or number literal is the name of a declaration node
6591-
function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean {
6592-
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
6593-
return false;
6594-
}
6595-
6596-
var parent = name.parent;
6597-
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) {
6598-
return (<Declaration>parent).name === name;
6599-
}
6600-
6601-
if (parent.kind === SyntaxKind.CatchBlock) {
6602-
return (<CatchBlock>parent).variable === name;
6603-
}
6604-
6605-
return false;
6606-
}
6607-
66086590
function isTypeDeclaration(node: Node): boolean {
66096591
switch (node.kind) {
66106592
case SyntaxKind.TypeParameter:
@@ -6615,28 +6597,6 @@ module ts {
66156597
}
66166598
}
66176599

6618-
function isDeclaration(node: Node): boolean {
6619-
switch (node.kind) {
6620-
case SyntaxKind.TypeParameter:
6621-
case SyntaxKind.Parameter:
6622-
case SyntaxKind.VariableDeclaration:
6623-
case SyntaxKind.Property:
6624-
case SyntaxKind.PropertyAssignment:
6625-
case SyntaxKind.EnumMember:
6626-
case SyntaxKind.Method:
6627-
case SyntaxKind.FunctionDeclaration:
6628-
case SyntaxKind.GetAccessor:
6629-
case SyntaxKind.SetAccessor:
6630-
case SyntaxKind.ClassDeclaration:
6631-
case SyntaxKind.InterfaceDeclaration:
6632-
case SyntaxKind.EnumDeclaration:
6633-
case SyntaxKind.ModuleDeclaration:
6634-
case SyntaxKind.ImportDeclaration:
6635-
return true;
6636-
}
6637-
return false;
6638-
}
6639-
66406600
// True if the given identifier is part of a type reference
66416601
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
66426602
var node: Node = entityName;

src/compiler/parser.ts

Lines changed: 31 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -361,104 +361,44 @@ module ts {
361361
return false;
362362
}
363363

364-
// True if the given identifier is the identifier of a declaration node
365-
export function isDeclarationIdentifier(identifier: Identifier): boolean {
366-
if (identifier.parent) {
367-
switch (identifier.parent.kind) {
368-
case SyntaxKind.TypeParameter:
369-
case SyntaxKind.Parameter:
370-
case SyntaxKind.VariableDeclaration:
371-
case SyntaxKind.Property:
372-
case SyntaxKind.PropertyAssignment:
373-
case SyntaxKind.EnumMember:
374-
case SyntaxKind.Method:
375-
case SyntaxKind.FunctionDeclaration:
376-
case SyntaxKind.FunctionExpression:
377-
case SyntaxKind.GetAccessor:
378-
case SyntaxKind.SetAccessor:
379-
case SyntaxKind.ClassDeclaration:
380-
case SyntaxKind.InterfaceDeclaration:
381-
case SyntaxKind.EnumDeclaration:
382-
case SyntaxKind.ModuleDeclaration:
383-
case SyntaxKind.ImportDeclaration:
384-
return (<Declaration>identifier.parent).name === identifier;
385-
case SyntaxKind.CatchBlock:
386-
return (<CatchBlock>identifier.parent).variable === identifier;
387-
}
364+
export function isDeclaration(node: Node): boolean {
365+
switch (node.kind) {
366+
case SyntaxKind.TypeParameter:
367+
case SyntaxKind.Parameter:
368+
case SyntaxKind.VariableDeclaration:
369+
case SyntaxKind.Property:
370+
case SyntaxKind.PropertyAssignment:
371+
case SyntaxKind.EnumMember:
372+
case SyntaxKind.Method:
373+
case SyntaxKind.FunctionDeclaration:
374+
case SyntaxKind.GetAccessor:
375+
case SyntaxKind.SetAccessor:
376+
case SyntaxKind.ClassDeclaration:
377+
case SyntaxKind.InterfaceDeclaration:
378+
case SyntaxKind.EnumDeclaration:
379+
case SyntaxKind.ModuleDeclaration:
380+
case SyntaxKind.ImportDeclaration:
381+
return true;
388382
}
389383
return false;
390384
}
391385

392-
// True if the given identifier is part of a type reference
393-
export function isTypeReferenceIdentifier(entityName: EntityName): boolean {
394-
var node: Node = entityName;
395-
while (node.parent && node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
396-
return node.parent && node.parent.kind === SyntaxKind.TypeReference;
397-
}
386+
// True if the given identifier, string literal, or number literal is the name of a declaration node
387+
export function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean {
388+
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) {
389+
return false;
390+
}
398391

399-
export function isExpression(node: Node): boolean {
400-
switch (node.kind) {
401-
case SyntaxKind.ThisKeyword:
402-
case SyntaxKind.SuperKeyword:
403-
case SyntaxKind.NullKeyword:
404-
case SyntaxKind.TrueKeyword:
405-
case SyntaxKind.FalseKeyword:
406-
case SyntaxKind.RegularExpressionLiteral:
407-
case SyntaxKind.ArrayLiteral:
408-
case SyntaxKind.ObjectLiteral:
409-
case SyntaxKind.PropertyAccess:
410-
case SyntaxKind.IndexedAccess:
411-
case SyntaxKind.CallExpression:
412-
case SyntaxKind.NewExpression:
413-
case SyntaxKind.TypeAssertion:
414-
case SyntaxKind.ParenExpression:
415-
case SyntaxKind.FunctionExpression:
416-
case SyntaxKind.ArrowFunction:
417-
case SyntaxKind.PrefixOperator:
418-
case SyntaxKind.PostfixOperator:
419-
case SyntaxKind.BinaryExpression:
420-
case SyntaxKind.ConditionalExpression:
421-
return true;
422-
case SyntaxKind.QualifiedName:
423-
while (node.parent && node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
424-
return node.parent && node.parent.kind === SyntaxKind.TypeQuery;
425-
case SyntaxKind.Identifier:
426-
case SyntaxKind.NumericLiteral:
427-
case SyntaxKind.StringLiteral:
428-
var parent = node.parent;
429-
if (parent) {
430-
if (isExpression(parent)) return true;
431-
switch (parent.kind) {
432-
case SyntaxKind.VariableDeclaration:
433-
case SyntaxKind.Parameter:
434-
case SyntaxKind.Property:
435-
case SyntaxKind.EnumMember:
436-
return (<VariableDeclaration>parent).initializer === node;
437-
case SyntaxKind.ExpressionStatement:
438-
case SyntaxKind.IfStatement:
439-
case SyntaxKind.DoStatement:
440-
case SyntaxKind.WhileStatement:
441-
case SyntaxKind.ReturnStatement:
442-
case SyntaxKind.WithStatement:
443-
case SyntaxKind.SwitchStatement:
444-
case SyntaxKind.CaseClause:
445-
case SyntaxKind.ThrowStatement:
446-
case SyntaxKind.SwitchStatement:
447-
return (<ExpressionStatement>parent).expression === node;
448-
case SyntaxKind.ForStatement:
449-
return (<ForStatement>parent).initializer === node || (<ForStatement>parent).condition === node ||
450-
(<ForStatement>parent).iterator === node;
451-
case SyntaxKind.ForInStatement:
452-
return (<ForInStatement>parent).variable === node || (<ForInStatement>parent).expression === node;
453-
}
454-
}
392+
var parent = name.parent;
393+
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) {
394+
return (<Declaration>parent).name === name;
455395
}
456-
return false;
457-
}
458396

459-
export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
460-
return (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccess) &&
461-
(<QualifiedName>node.parent).right === node;
397+
if (parent.kind === SyntaxKind.CatchBlock) {
398+
return (<CatchBlock>parent).variable === name;
399+
}
400+
401+
return false;
462402
}
463403

464404
enum ParsingContext {

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,7 @@ module ts {
25152515
else if (isInRightSideOfImport(node)) {
25162516
return getMeaningFromRightHandSideOfImport(node);
25172517
}
2518-
else if (isDeclarationIdentifier(<Identifier>node)) {
2518+
else if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
25192519
return getMeaningFromDeclaration(node.parent);
25202520
}
25212521
else if (isTypeReference(node)) {
@@ -2560,7 +2560,7 @@ module ts {
25602560

25612561
/// A node is considedered a writeAccess iff it is a name of a declaration or a target of an assignment
25622562
function isWriteAccess(node: Node): boolean {
2563-
if (node.kind === SyntaxKind.Identifier && isDeclarationIdentifier(<Identifier>node)) {
2563+
if (node.kind === SyntaxKind.Identifier && isDeclarationOrFunctionExpressionOrCatchVariableName(node)) {
25642564
return true;
25652565
}
25662566

0 commit comments

Comments
 (0)