Improve naming of hasNonBindableDynamicName (#42297)

hasNonBindableDynamicName

1. Has 'non' in the name, and is only ever used negated.
2. Is true for a case that's not reflected correctly in the name -- it's
true for non-dynamic names as well.

I considered hasEarlyOrLateBindableName, but decided to use
hasBindableName for now.
This commit is contained in:
Nathan Shively-Sanders
2021-01-12 13:15:54 -08:00
committed by GitHub
parent c3dd845923
commit 2f5863754f

View File

@@ -8202,7 +8202,7 @@ namespace ts {
if (isParameter(declaration)) {
const func = <FunctionLikeDeclaration>declaration.parent;
// For a parameter of a set accessor, use the type of the get accessor if one is present
if (func.kind === SyntaxKind.SetAccessor && !hasNonBindableDynamicName(func)) {
if (func.kind === SyntaxKind.SetAccessor && hasBindableName(func)) {
const getter = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(declaration.parent), SyntaxKind.GetAccessor);
if (getter) {
const getterSignature = getSignatureFromDeclaration(getter);
@@ -9877,10 +9877,10 @@ namespace ts {
}
/**
* Indicates whether a declaration has a dynamic name that cannot be late-bound.
* Indicates whether a declaration has an early-bound name or a dynamic name that can be late-bound.
*/
function hasNonBindableDynamicName(node: Declaration) {
return hasDynamicName(node) && !hasLateBindableName(node);
function hasBindableName(node: Declaration) {
return !hasDynamicName(node) || hasLateBindableName(node);
}
/**
@@ -11827,7 +11827,7 @@ namespace ts {
// If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation
if ((declaration.kind === SyntaxKind.GetAccessor || declaration.kind === SyntaxKind.SetAccessor) &&
!hasNonBindableDynamicName(declaration) &&
hasBindableName(declaration) &&
(!hasThisParameter || !thisParameter)) {
const otherKind = declaration.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
const other = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(declaration), otherKind);
@@ -12051,7 +12051,7 @@ namespace ts {
if (typeNode) {
return getTypeFromTypeNode(typeNode);
}
if (declaration.kind === SyntaxKind.GetAccessor && !hasNonBindableDynamicName(declaration)) {
if (declaration.kind === SyntaxKind.GetAccessor && hasBindableName(declaration)) {
const jsDocType = isInJSFile(declaration) && getTypeForDeclarationFromJSDocComment(declaration);
if (jsDocType) {
return jsDocType;
@@ -24414,7 +24414,7 @@ namespace ts {
const objectLiteral = <ObjectLiteralExpression>element.parent;
const type = getApparentTypeOfContextualType(objectLiteral, contextFlags);
if (type) {
if (!hasNonBindableDynamicName(element)) {
if (hasBindableName(element)) {
// For a (non-symbol) computed property, there is no reason to look up the name
// in the type. It will just be "__computed", which does not appear in any
// SymbolTable.
@@ -32305,7 +32305,7 @@ namespace ts {
if (isPrivateIdentifier(node.name)) {
error(node.name, Diagnostics.An_accessor_cannot_be_named_with_a_private_identifier);
}
if (!hasNonBindableDynamicName(node)) {
if (hasBindableName(node)) {
// TypeScript 1.0 spec (April 2014): 8.4.3
// Accessors for the same member name must specify the same accessibility.
const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
@@ -33631,7 +33631,7 @@ namespace ts {
checkComputedPropertyName(node.name);
}
if (!hasNonBindableDynamicName(node)) {
if (hasBindableName(node)) {
// first we want to check the local symbol that contain this declaration
// - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
// - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
@@ -35634,7 +35634,7 @@ namespace ts {
// Only process instance properties with computed names here.
// Static properties cannot be in conflict with indexers,
// and properties with literal names were already checked.
if (!hasSyntacticModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) {
if (!hasSyntacticModifier(member, ModifierFlags.Static) && !hasBindableName(member)) {
const symbol = getSymbolOfNode(member);
const propType = getTypeOfSymbol(symbol);
checkIndexConstraintForProperty(symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);