Skip to content

Commit 3868ca4

Browse files
committed
remove check functions with duplicate structure
1 parent 63c8122 commit 3868ca4

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
@@ -3788,16 +3788,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37883788
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
37893789
if (meaning & SymbolFlags.Value) {
37903790
if (isPrimitiveTypeName(name)) {
3791-
// const grandparent = errorLocation.parent.parent;
3792-
// const parentOfGrandparent = grandparent.parent;
3793-
if (isExtendedByInterface(errorLocation)) {
3794-
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3795-
}
3796-
else if (isExtendedByClass(errorLocation)) {
3797-
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3798-
}
3799-
else if (isImplementedByClass(errorLocation)) {
3800-
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3791+
const grandparent = errorLocation.parent.parent;
3792+
if (grandparent && grandparent.parent && isHeritageClause(grandparent)) {
3793+
const heritageKind = grandparent.token;
3794+
const containerKind = grandparent.parent.kind;
3795+
if (containerKind === SyntaxKind.InterfaceDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3796+
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3797+
}
3798+
else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ExtendsKeyword) {
3799+
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
3800+
}
3801+
else if (containerKind === SyntaxKind.ClassDeclaration && heritageKind === SyntaxKind.ImplementsKeyword) {
3802+
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
3803+
}
38013804
}
38023805
else {
38033806
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3822,39 +3825,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38223825
}
38233826
return false;
38243827
}
3825-
3826-
function isExtendedByInterface(node: Node): boolean {
3827-
const grandparent = node.parent.parent;
3828-
const parentOfGrandparent = grandparent.parent;
3829-
if (grandparent && parentOfGrandparent) {
3830-
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3831-
const isInterface = isInterfaceDeclaration(parentOfGrandparent);
3832-
return isExtending && isInterface;
3833-
}
3834-
return false;
3835-
}
3836-
3837-
function isExtendedByClass(node: Node): boolean {
3838-
const grandparent = node.parent.parent;
3839-
const parentOfGrandparent = grandparent.parent;
3840-
if (grandparent && parentOfGrandparent) {
3841-
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
3842-
const isClass = isClassDeclaration(parentOfGrandparent);
3843-
return isExtending && isClass;
3844-
}
3845-
return false;
3846-
}
3847-
3848-
function isImplementedByClass(node: Node): boolean {
3849-
const grandparent = node.parent.parent;
3850-
const parentOfGrandparent = grandparent.parent;
3851-
if (grandparent && parentOfGrandparent) {
3852-
const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
3853-
const isClass = isClassDeclaration(parentOfGrandparent);
3854-
return isImplementing && isClass;
3855-
}
3856-
return false;
3857-
}
38583828

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

0 commit comments

Comments
 (0)