@@ -386,8 +386,8 @@ namespace ts {
386386 // local variables of the constructor. This effectively means that entities from outer scopes
387387 // by the same name as a constructor parameter or local variable are inaccessible
388388 // in initializer expressions for instance member variables.
389- if (location.parent.kind === SyntaxKind.ClassDeclaration && !(location.flags & NodeFlags.Static)) {
390- let ctor = findConstructorDeclaration(<ClassDeclaration >location.parent);
389+ if (isClassLike( location.parent) && !(location.flags & NodeFlags.Static)) {
390+ let ctor = findConstructorDeclaration(<ClassLikeDeclaration >location.parent);
391391 if (ctor && ctor.locals) {
392392 if (getSymbol(ctor.locals, name, meaning & SymbolFlags.Value)) {
393393 // Remember the property node, it will be used later to report appropriate error
@@ -397,6 +397,7 @@ namespace ts {
397397 }
398398 break;
399399 case SyntaxKind.ClassDeclaration:
400+ case SyntaxKind.ClassExpression:
400401 case SyntaxKind.InterfaceDeclaration:
401402 if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & SymbolFlags.Type)) {
402403 if (lastLocation && lastLocation.flags & NodeFlags.Static) {
@@ -420,7 +421,7 @@ namespace ts {
420421 //
421422 case SyntaxKind.ComputedPropertyName:
422423 grandparent = location.parent.parent;
423- if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) {
424+ if (isClassLike( grandparent) || grandparent.kind === SyntaxKind.InterfaceDeclaration) {
424425 // A reference to this grandparent's type parameters would be an error
425426 if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) {
426427 error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
@@ -1009,7 +1010,7 @@ namespace ts {
10091010 return false;
10101011 }
10111012
1012- function findConstructorDeclaration(node: ClassDeclaration ): ConstructorDeclaration {
1013+ function findConstructorDeclaration(node: ClassLikeDeclaration ): ConstructorDeclaration {
10131014 let members = node.members;
10141015 for (let member of members) {
10151016 if (member.kind === SyntaxKind.Constructor && nodeIsPresent((<ConstructorDeclaration>member).body)) {
@@ -2562,10 +2563,10 @@ namespace ts {
25622563 if (!node) {
25632564 return typeParameters;
25642565 }
2565- if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.FunctionDeclaration ||
2566- node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.MethodDeclaration ||
2567- node.kind === SyntaxKind.ArrowFunction) {
2568- let declarations = (<ClassDeclaration | FunctionLikeDeclaration>node).typeParameters;
2566+ if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression ||
2567+ node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression ||
2568+ node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind. ArrowFunction) {
2569+ let declarations = (<ClassLikeDeclaration | FunctionLikeDeclaration>node).typeParameters;
25692570 if (declarations) {
25702571 return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations);
25712572 }
@@ -2575,16 +2576,17 @@ namespace ts {
25752576
25762577 // The outer type parameters are those defined by enclosing generic classes, methods, or functions.
25772578 function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] {
2578- var kind = symbol.flags & SymbolFlags.Class ? SyntaxKind.ClassDeclaration : SyntaxKind.InterfaceDeclaration;
2579- return appendOuterTypeParameters(undefined, getDeclarationOfKind(symbol, kind) );
2579+ var declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration) ;
2580+ return appendOuterTypeParameters(undefined, declaration );
25802581 }
25812582
25822583 // The local type parameters are the combined set of type parameters from all declarations of the class,
25832584 // interface, or type alias.
25842585 function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol: Symbol): TypeParameter[] {
25852586 let result: TypeParameter[];
25862587 for (let node of symbol.declarations) {
2587- if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
2588+ if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration ||
2589+ node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.TypeAliasDeclaration) {
25882590 let declaration = <InterfaceDeclaration | TypeAliasDeclaration>node;
25892591 if (declaration.typeParameters) {
25902592 result = appendTypeParameters(result, declaration.typeParameters);
@@ -5884,9 +5886,9 @@ namespace ts {
58845886 }
58855887
58865888 function captureLexicalThis(node: Node, container: Node): void {
5887- let classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined;
58885889 getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis;
58895890 if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) {
5891+ let classNode = container.parent;
58905892 getNodeLinks(classNode).flags |= NodeCheckFlags.CaptureThis;
58915893 }
58925894 else {
@@ -5939,7 +5941,7 @@ namespace ts {
59395941 captureLexicalThis(node, container);
59405942 }
59415943
5942- let classNode = container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ? container.parent : undefined;
5944+ let classNode = isClassLike( container.parent) ? container.parent : undefined;
59435945 if (classNode) {
59445946 let symbol = getSymbolOfNode(classNode);
59455947 return container.flags & NodeFlags.Static ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol);
@@ -5958,7 +5960,7 @@ namespace ts {
59585960
59595961 function checkSuperExpression(node: Node): Type {
59605962 let isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (<CallExpression>node.parent).expression === node;
5961- let classDeclaration = <ClassDeclaration>getAncestor (node, SyntaxKind.ClassDeclaration );
5963+ let classDeclaration = getContainingClass (node);
59625964 let classType = classDeclaration && <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration));
59635965 let baseClassType = classType && getBaseTypes(classType)[0];
59645966
@@ -5993,7 +5995,7 @@ namespace ts {
59935995 }
59945996
59955997 // topmost container must be something that is directly nested in the class declaration
5996- if (container && container.parent && container.parent.kind === SyntaxKind.ClassDeclaration ) {
5998+ if (container && isClassLike( container.parent) ) {
59975999 if (container.flags & NodeFlags.Static) {
59986000 canUseSuperExpression =
59996001 container.kind === SyntaxKind.MethodDeclaration ||
@@ -6652,7 +6654,7 @@ namespace ts {
66526654 }
66536655 // Property is known to be private or protected at this point
66546656 // Get the declaring and enclosing class instance types
6655- let enclosingClassDeclaration = getAncestor (node, SyntaxKind.ClassDeclaration );
6657+ let enclosingClassDeclaration = getContainingClass (node);
66566658 let enclosingClass = enclosingClassDeclaration ? <InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
66576659 let declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(prop.parent);
66586660 // Private property is accessible if declaring and enclosing class are the same
@@ -7426,7 +7428,7 @@ namespace ts {
74267428 if (superType !== unknownType) {
74277429 // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated
74287430 // with the type arguments specified in the extends clause.
7429- let baseTypeNode = getClassExtendsHeritageClauseElement(<ClassDeclaration>getAncestor (node, SyntaxKind.ClassDeclaration ));
7431+ let baseTypeNode = getClassExtendsHeritageClauseElement(getContainingClass (node));
74307432 let baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments);
74317433 return resolveCall(node, baseConstructors, candidatesOutArray);
74327434 }
@@ -8354,7 +8356,7 @@ namespace ts {
83548356 if (isFunctionLike(parent) && current === (<FunctionLikeDeclaration>parent).body) {
83558357 return false;
83568358 }
8357- else if (current.kind === SyntaxKind.ClassDeclaration || current.kind === SyntaxKind.ClassExpression ) {
8359+ else if (isClassLike( current) ) {
83588360 return true;
83598361 }
83608362
@@ -9648,7 +9650,7 @@ namespace ts {
96489650 }
96499651
96509652 // bubble up and find containing type
9651- let enclosingClass = <ClassDeclaration>getAncestor (node, SyntaxKind.ClassDeclaration );
9653+ let enclosingClass = getContainingClass (node);
96529654 // if containing type was not found or it is ambient - exit (no codegen)
96539655 if (!enclosingClass || isInAmbientContext(enclosingClass)) {
96549656 return;
@@ -10456,8 +10458,8 @@ namespace ts {
1045610458 checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number);
1045710459 });
1045810460
10459- if (type.flags & TypeFlags.Class && type.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration ) {
10460- let classDeclaration = <ClassDeclaration >type.symbol.valueDeclaration;
10461+ if (type.flags & TypeFlags.Class && isClassLike( type.symbol.valueDeclaration) ) {
10462+ let classDeclaration = <ClassLikeDeclaration >type.symbol.valueDeclaration;
1046110463 for (let member of classDeclaration.members) {
1046210464 // Only process instance properties with computed names here.
1046310465 // Static properties cannot be in conflict with indexers,
@@ -11727,6 +11729,11 @@ namespace ts {
1172711729 case SyntaxKind.EnumDeclaration:
1172811730 copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember);
1172911731 break;
11732+ case SyntaxKind.ClassExpression:
11733+ if ((<ClassExpression>location).name) {
11734+ copySymbol(location.symbol, meaning);
11735+ }
11736+ // Fall through
1173011737 case SyntaxKind.ClassDeclaration:
1173111738 case SyntaxKind.InterfaceDeclaration:
1173211739 if (!(memberFlags & NodeFlags.Static)) {
@@ -11766,42 +11773,6 @@ namespace ts {
1176611773 }
1176711774 }
1176811775 }
11769-
11770- if (isInsideWithStatementBody(location)) {
11771- // We cannot answer semantic questions within a with block, do not proceed any further
11772- return [];
11773- }
11774-
11775- while (location) {
11776- if (location.locals && !isGlobalSourceFile(location)) {
11777- copySymbols(location.locals, meaning);
11778- }
11779- switch (location.kind) {
11780- case SyntaxKind.SourceFile:
11781- if (!isExternalModule(<SourceFile>location)) break;
11782- case SyntaxKind.ModuleDeclaration:
11783- copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember);
11784- break;
11785- case SyntaxKind.EnumDeclaration:
11786- copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember);
11787- break;
11788- case SyntaxKind.ClassDeclaration:
11789- case SyntaxKind.InterfaceDeclaration:
11790- if (!(memberFlags & NodeFlags.Static)) {
11791- copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type);
11792- }
11793- break;
11794- case SyntaxKind.FunctionExpression:
11795- if ((<FunctionExpression>location).name) {
11796- copySymbol(location.symbol, meaning);
11797- }
11798- break;
11799- }
11800- memberFlags = location.flags;
11801- location = location.parent;
11802- }
11803- copySymbols(globals, meaning);
11804- return symbolsToArray(symbols);
1180511776 }
1180611777
1180711778 function isTypeDeclarationName(name: Node): boolean {
@@ -13213,7 +13184,7 @@ namespace ts {
1321313184 }
1321413185 }
1321513186
13216- if (node.parent.kind === SyntaxKind.ClassDeclaration ) {
13187+ if (isClassLike( node.parent) ) {
1321713188 if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional)) {
1321813189 return true;
1321913190 }
@@ -13505,7 +13476,7 @@ namespace ts {
1350513476 }
1350613477
1350713478 function checkGrammarProperty(node: PropertyDeclaration) {
13508- if (node.parent.kind === SyntaxKind.ClassDeclaration ) {
13479+ if (isClassLike( node.parent) ) {
1350913480 if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.A_class_member_cannot_be_declared_optional) ||
1351013481 checkGrammarForNonSymbolComputedProperty(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) {
1351113482 return true;
0 commit comments