Skip to content

Commit 1bb904c

Browse files
committed
remove check functions with duplicate structure
1 parent cb4d663 commit 1bb904c

File tree

1 file changed

+13
-43
lines changed

1 file changed

+13
-43
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,16 +3752,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37523752
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
37533753
if (meaning & SymbolFlags.Value) {
37543754
if (isPrimitiveTypeName(name)) {
3755-
// const grandparent = errorLocation.parent.parent;
3756-
// const parentOfGrandparent = grandparent.parent;
3757-
if (isExtendedByInterface(errorLocation)) {
3758-
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3759-
}
3760-
else if (isExtendedByClass(errorLocation)) {
3761-
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3762-
}
3763-
else if (isImplementedByClass(errorLocation)) {
3764-
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3755+
const grandparent = errorLocation.parent.parent;
3756+
if (grandparent && grandparent.parent && isHeritageClause(grandparent)) {
3757+
const heritageKind = grandparent.token;
3758+
const containerKind = grandparent.parent.kind;
3759+
if (containerKind === SyntaxKind.InterfaceDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3760+
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3761+
}
3762+
else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3763+
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3764+
}
3765+
else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ImplementsKeyword) {
3766+
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3767+
}
37653768
}
37663769
else {
37673770
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3786,39 +3789,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37863789
}
37873790
return false;
37883791
}
3789-
3790-
function isExtendedByInterface(node: Node): boolean {
3791-
const grandparent = node.parent.parent;
3792-
const parentOfGrandparent = grandparent.parent;
3793-
if (grandparent && parentOfGrandparent) {
3794-
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3795-
const isInterface = isInterfaceDeclaration(parentOfGrandparent);
3796-
return isExtending && isInterface;
3797-
}
3798-
return false;
3799-
}
3800-
3801-
function isExtendedByClass(node: Node): boolean {
3802-
const grandparent = node.parent.parent;
3803-
const parentOfGrandparent = grandparent.parent;
3804-
if (grandparent && parentOfGrandparent) {
3805-
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3806-
const isClass = isClassDeclaration(parentOfGrandparent);
3807-
return isExtending && isClass;
3808-
}
3809-
return false;
3810-
}
3811-
3812-
function isImplementedByClass(node: Node): boolean {
3813-
const grandparent = node.parent.parent;
3814-
const parentOfGrandparent = grandparent.parent;
3815-
if (grandparent && parentOfGrandparent) {
3816-
const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
3817-
const isClass = isClassDeclaration(parentOfGrandparent);
3818-
return isImplementing && isClass;
3819-
}
3820-
return false;
3821-
}
38223792

38233793
function maybeMappedType(node: Node, symbol: Symbol) {
38243794
const container = findAncestor(node.parent, n => isComputedPropertyName(n) || isPropertySignature(n) ? false : isTypeLiteralNode(n) || "quit") as TypeLiteralNode | undefined;

0 commit comments

Comments
 (0)