Skip to content

Commit 279791e

Browse files
committed
Merge branch 'master' into symbolInfoFormatting
2 parents 58cfc98 + 400f6eb commit 279791e

File tree

5 files changed

+257
-234
lines changed

5 files changed

+257
-234
lines changed

src/compiler/checker.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7134,6 +7134,22 @@ module ts {
71347134
return mapToArray(symbols);
71357135
}
71367136

7137+
function isTypeDeclarationName(name: Node): boolean {
7138+
return name.kind == SyntaxKind.Identifier &&
7139+
isTypeDeclaration(name.parent) &&
7140+
(<Declaration>name.parent).name === name;
7141+
}
7142+
7143+
function isTypeDeclaration(node: Node): boolean {
7144+
switch (node.kind) {
7145+
case SyntaxKind.TypeParameter:
7146+
case SyntaxKind.ClassDeclaration:
7147+
case SyntaxKind.InterfaceDeclaration:
7148+
case SyntaxKind.EnumDeclaration:
7149+
return true;
7150+
}
7151+
}
7152+
71377153
// True if the given identifier is part of a type reference
71387154
function isTypeReferenceIdentifier(entityName: EntityName): boolean {
71397155
var node: Node = entityName;
@@ -7212,6 +7228,78 @@ module ts {
72127228
return false;
72137229
}
72147230

7231+
function isTypeNode(node: Node): boolean {
7232+
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
7233+
return true;
7234+
}
7235+
7236+
switch (node.kind) {
7237+
case SyntaxKind.AnyKeyword:
7238+
case SyntaxKind.NumberKeyword:
7239+
case SyntaxKind.StringKeyword:
7240+
case SyntaxKind.BooleanKeyword:
7241+
return true;
7242+
case SyntaxKind.VoidKeyword:
7243+
return node.parent.kind !== SyntaxKind.PrefixOperator;
7244+
case SyntaxKind.StringLiteral:
7245+
// Specialized signatures can have string literals as their parameters' type names
7246+
return node.parent.kind === SyntaxKind.Parameter;
7247+
7248+
// Identifiers and qualified names may be type nodes, depending on their context. Climb
7249+
// above them to find the lowest container
7250+
case SyntaxKind.Identifier:
7251+
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
7252+
if (node.parent.kind === SyntaxKind.QualifiedName) {
7253+
node = node.parent;
7254+
}
7255+
// fall through
7256+
case SyntaxKind.QualifiedName:
7257+
// At this point, node is either a qualified name or an identifier
7258+
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName, "'node' was expected to be a qualified name or identifier in 'isTypeNode'.");
7259+
7260+
var parent = node.parent;
7261+
if (parent.kind === SyntaxKind.TypeQuery) {
7262+
return false;
7263+
}
7264+
// Do not recursively call isTypeNode on the parent. In the example:
7265+
//
7266+
// var a: A.B.C;
7267+
//
7268+
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
7269+
// A.B.C is a type node.
7270+
if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) {
7271+
return true;
7272+
}
7273+
switch (parent.kind) {
7274+
case SyntaxKind.TypeParameter:
7275+
return node === (<TypeParameterDeclaration>parent).constraint;
7276+
case SyntaxKind.Property:
7277+
case SyntaxKind.Parameter:
7278+
case SyntaxKind.VariableDeclaration:
7279+
return node === (<VariableDeclaration>parent).type;
7280+
case SyntaxKind.FunctionDeclaration:
7281+
case SyntaxKind.FunctionExpression:
7282+
case SyntaxKind.ArrowFunction:
7283+
case SyntaxKind.Constructor:
7284+
case SyntaxKind.Method:
7285+
case SyntaxKind.GetAccessor:
7286+
case SyntaxKind.SetAccessor:
7287+
return node === (<FunctionDeclaration>parent).type;
7288+
case SyntaxKind.CallSignature:
7289+
case SyntaxKind.ConstructSignature:
7290+
case SyntaxKind.IndexSignature:
7291+
return node === (<SignatureDeclaration>parent).type;
7292+
case SyntaxKind.TypeAssertion:
7293+
return node === (<TypeAssertion>parent).type;
7294+
case SyntaxKind.CallExpression:
7295+
case SyntaxKind.NewExpression:
7296+
return (<CallExpression>parent).typeArguments && (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
7297+
}
7298+
}
7299+
7300+
return false;
7301+
}
7302+
72157303
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
72167304
while (node.parent.kind === SyntaxKind.QualifiedName) {
72177305
node = node.parent;

src/compiler/parser.ts

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -391,100 +391,6 @@ module ts {
391391
return false;
392392
}
393393

394-
/**
395-
* Note: this function only works when given a node with valid parent pointers.
396-
*/
397-
export function isTypeNode(node: Node): boolean {
398-
if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) {
399-
return true;
400-
}
401-
402-
switch (node.kind) {
403-
case SyntaxKind.AnyKeyword:
404-
case SyntaxKind.NumberKeyword:
405-
case SyntaxKind.StringKeyword:
406-
case SyntaxKind.BooleanKeyword:
407-
return true;
408-
case SyntaxKind.VoidKeyword:
409-
return node.parent.kind !== SyntaxKind.PrefixOperator;
410-
case SyntaxKind.StringLiteral:
411-
// Specialized signatures can have string literals as their parameters' type names
412-
return node.parent.kind === SyntaxKind.Parameter;
413-
// Identifiers and qualified names may be type nodes, depending on their context. Climb
414-
// above them to find the lowest container
415-
case SyntaxKind.Identifier:
416-
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
417-
if (node.parent.kind === SyntaxKind.QualifiedName) {
418-
node = node.parent;
419-
}
420-
// Fall through
421-
case SyntaxKind.QualifiedName:
422-
// At this point, node is either a qualified name or an identifier
423-
var parent = node.parent;
424-
if (parent.kind === SyntaxKind.TypeQuery) {
425-
return false;
426-
}
427-
// Do not recursively call isTypeNode on the parent. In the example:
428-
//
429-
// var a: A.B.C;
430-
//
431-
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
432-
// A.B.C is a type node.
433-
if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) {
434-
return true;
435-
}
436-
switch (parent.kind) {
437-
case SyntaxKind.TypeParameter:
438-
return node === (<TypeParameterDeclaration>parent).constraint;
439-
case SyntaxKind.Property:
440-
case SyntaxKind.Parameter:
441-
case SyntaxKind.VariableDeclaration:
442-
return node === (<VariableDeclaration>parent).type;
443-
case SyntaxKind.FunctionDeclaration:
444-
case SyntaxKind.FunctionExpression:
445-
case SyntaxKind.ArrowFunction:
446-
case SyntaxKind.Constructor:
447-
case SyntaxKind.Method:
448-
case SyntaxKind.GetAccessor:
449-
case SyntaxKind.SetAccessor:
450-
return node === (<FunctionDeclaration>parent).type;
451-
case SyntaxKind.CallSignature:
452-
case SyntaxKind.ConstructSignature:
453-
case SyntaxKind.IndexSignature:
454-
return node === (<SignatureDeclaration>parent).type;
455-
case SyntaxKind.TypeAssertion:
456-
return node === (<TypeAssertion>parent).type;
457-
case SyntaxKind.CallExpression:
458-
case SyntaxKind.NewExpression:
459-
return (<CallExpression>parent).typeArguments && (<CallExpression>parent).typeArguments.indexOf(node) >= 0;
460-
}
461-
}
462-
463-
return false;
464-
}
465-
466-
/**
467-
* Note: this function only works when given a node with valid parent pointers.
468-
*
469-
* returns true if the given identifier is the name of a type declaration node (class, interface, enum, type parameter, etc)
470-
*/
471-
export function isTypeDeclarationName(name: Node): boolean {
472-
return name.kind == SyntaxKind.Identifier &&
473-
isTypeDeclaration(name.parent) &&
474-
(<Declaration>name.parent).name === name;
475-
}
476-
477-
478-
export function isTypeDeclaration(node: Node): boolean {
479-
switch (node.kind) {
480-
case SyntaxKind.TypeParameter:
481-
case SyntaxKind.ClassDeclaration:
482-
case SyntaxKind.InterfaceDeclaration:
483-
case SyntaxKind.EnumDeclaration:
484-
return true;
485-
}
486-
}
487-
488394
export function getContainingFunction(node: Node): SignatureDeclaration {
489395
while (true) {
490396
node = node.parent;

0 commit comments

Comments
 (0)