@@ -361,104 +361,44 @@ module ts {
361
361
return false ;
362
362
}
363
363
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 ;
388
382
}
389
383
return false ;
390
384
}
391
385
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
+ }
398
391
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 ;
455
395
}
456
- return false ;
457
- }
458
396
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 ;
462
402
}
463
403
464
404
enum ParsingContext {
0 commit comments