mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Fix longer type-only property access in non-emitting heritage clauses (#37264)
* Fix longer type-only property access in non-emitting heritage clauses * Rename misnomer function
This commit is contained in:
@@ -6267,7 +6267,7 @@ namespace ts {
|
||||
export function isValidTypeOnlyAliasUseSite(useSite: Node): boolean {
|
||||
return !!(useSite.flags & NodeFlags.Ambient)
|
||||
|| isPartOfTypeQuery(useSite)
|
||||
|| isFirstIdentifierOfNonEmittingHeritageClause(useSite)
|
||||
|| isIdentifierInNonEmittingHeritageClause(useSite)
|
||||
|| isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite)
|
||||
|| !isExpressionNode(useSite);
|
||||
}
|
||||
@@ -6290,10 +6290,20 @@ namespace ts {
|
||||
return containerKind === SyntaxKind.InterfaceDeclaration || containerKind === SyntaxKind.TypeLiteral;
|
||||
}
|
||||
|
||||
/** Returns true for the first identifier of 1) an `implements` clause, and 2) an `extends` clause of an interface. */
|
||||
function isFirstIdentifierOfNonEmittingHeritageClause(node: Node): boolean {
|
||||
// Number of parents to climb from identifier is 2 for `implements I`, 3 for `implements x.I`
|
||||
const heritageClause = tryCast(node.parent.parent, isHeritageClause) ?? tryCast(node.parent.parent?.parent, isHeritageClause);
|
||||
/** Returns true for an identifier in 1) an `implements` clause, and 2) an `extends` clause of an interface. */
|
||||
function isIdentifierInNonEmittingHeritageClause(node: Node): boolean {
|
||||
if (node.kind !== SyntaxKind.Identifier) return false;
|
||||
const heritageClause = findAncestor(node.parent, parent => {
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.HeritageClause:
|
||||
return true;
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return false;
|
||||
default:
|
||||
return "quit";
|
||||
}
|
||||
}) as HeritageClause | undefined;
|
||||
return heritageClause?.token === SyntaxKind.ImplementsKeyword || heritageClause?.parent.kind === SyntaxKind.InterfaceDeclaration;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user