mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Actually check types in checkClassExpression
This commit is contained in:
@@ -1402,15 +1402,8 @@ namespace ts {
|
||||
* for the name of the symbol if it is available to match how the user inputted the name.
|
||||
*/
|
||||
function appendSymbolNameOnly(symbol: Symbol, writer: SymbolWriter): void {
|
||||
if (symbol.declarations && symbol.declarations.length > 0) {
|
||||
let declaration = symbol.declarations[0];
|
||||
if (declaration.name) {
|
||||
writer.writeSymbol(declarationNameToString(declaration.name), symbol);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeSymbol(symbol.name, symbol);
|
||||
let name = symbol.declarations && symbol.declarations.length > 0 ? declarationToString(symbol.declarations[0]) : symbol.name;
|
||||
writer.writeSymbol(name, symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -10565,9 +10558,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkClassExpression(node: ClassExpression): Type {
|
||||
grammarErrorOnNode(node, Diagnostics.class_expressions_are_not_currently_supported);
|
||||
forEach(node.members, checkSourceElement);
|
||||
return unknownType;
|
||||
checkClassLikeDeclaration(node);
|
||||
return getTypeOfSymbol(getSymbolOfNode(node));
|
||||
}
|
||||
|
||||
function checkClassDeclaration(node: ClassDeclaration) {
|
||||
@@ -10575,7 +10567,10 @@ namespace ts {
|
||||
if (!node.name && !(node.flags & NodeFlags.Default)) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
|
||||
}
|
||||
checkClassLikeDeclaration(node);
|
||||
}
|
||||
|
||||
function checkClassLikeDeclaration(node: ClassLikeDeclaration) {
|
||||
checkGrammarClassDeclarationHeritageClauses(node);
|
||||
checkDecorators(node);
|
||||
if (node.name) {
|
||||
@@ -12921,7 +12916,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarClassDeclarationHeritageClauses(node: ClassDeclaration) {
|
||||
function checkGrammarClassDeclarationHeritageClauses(node: ClassLikeDeclaration) {
|
||||
let seenExtendsClause = false;
|
||||
let seenImplementsClause = false;
|
||||
|
||||
|
||||
@@ -247,6 +247,19 @@ namespace ts {
|
||||
declaration.parent.kind === SyntaxKind.CatchClause;
|
||||
}
|
||||
|
||||
export function declarationToString(declaration: Declaration) {
|
||||
if (!declaration.name) {
|
||||
switch (declaration.kind) {
|
||||
case SyntaxKind.ClassExpression:
|
||||
return "(Anonymous class)";
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return "(Anonymous function)";
|
||||
}
|
||||
}
|
||||
return declarationNameToString(declaration.name);
|
||||
}
|
||||
|
||||
// Return display name of an identifier
|
||||
// Computed property names will just be emitted as "[<expr>]", where <expr> is the source
|
||||
// text of the expression in the computed property.
|
||||
@@ -1234,7 +1247,7 @@ namespace ts {
|
||||
return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
|
||||
}
|
||||
|
||||
export function getClassImplementsHeritageClauseElements(node: ClassDeclaration) {
|
||||
export function getClassImplementsHeritageClauseElements(node: ClassLikeDeclaration) {
|
||||
let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ImplementsKeyword);
|
||||
return heritageClause ? heritageClause.types : undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user