Skip to content

Commit 2f58637

Browse files
authored
Improve naming of hasNonBindableDynamicName (microsoft#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.
1 parent c3dd845 commit 2f58637

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8202,7 +8202,7 @@ namespace ts {
82028202
if (isParameter(declaration)) {
82038203
const func = <FunctionLikeDeclaration>declaration.parent;
82048204
// For a parameter of a set accessor, use the type of the get accessor if one is present
8205-
if (func.kind === SyntaxKind.SetAccessor && !hasNonBindableDynamicName(func)) {
8205+
if (func.kind === SyntaxKind.SetAccessor && hasBindableName(func)) {
82068206
const getter = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(declaration.parent), SyntaxKind.GetAccessor);
82078207
if (getter) {
82088208
const getterSignature = getSignatureFromDeclaration(getter);
@@ -9877,10 +9877,10 @@ namespace ts {
98779877
}
98789878

98799879
/**
9880-
* Indicates whether a declaration has a dynamic name that cannot be late-bound.
9880+
* Indicates whether a declaration has an early-bound name or a dynamic name that can be late-bound.
98819881
*/
9882-
function hasNonBindableDynamicName(node: Declaration) {
9883-
return hasDynamicName(node) && !hasLateBindableName(node);
9882+
function hasBindableName(node: Declaration) {
9883+
return !hasDynamicName(node) || hasLateBindableName(node);
98849884
}
98859885

98869886
/**
@@ -11827,7 +11827,7 @@ namespace ts {
1182711827

1182811828
// If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation
1182911829
if ((declaration.kind === SyntaxKind.GetAccessor || declaration.kind === SyntaxKind.SetAccessor) &&
11830-
!hasNonBindableDynamicName(declaration) &&
11830+
hasBindableName(declaration) &&
1183111831
(!hasThisParameter || !thisParameter)) {
1183211832
const otherKind = declaration.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
1183311833
const other = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(declaration), otherKind);
@@ -12051,7 +12051,7 @@ namespace ts {
1205112051
if (typeNode) {
1205212052
return getTypeFromTypeNode(typeNode);
1205312053
}
12054-
if (declaration.kind === SyntaxKind.GetAccessor && !hasNonBindableDynamicName(declaration)) {
12054+
if (declaration.kind === SyntaxKind.GetAccessor && hasBindableName(declaration)) {
1205512055
const jsDocType = isInJSFile(declaration) && getTypeForDeclarationFromJSDocComment(declaration);
1205612056
if (jsDocType) {
1205712057
return jsDocType;
@@ -24414,7 +24414,7 @@ namespace ts {
2441424414
const objectLiteral = <ObjectLiteralExpression>element.parent;
2441524415
const type = getApparentTypeOfContextualType(objectLiteral, contextFlags);
2441624416
if (type) {
24417-
if (!hasNonBindableDynamicName(element)) {
24417+
if (hasBindableName(element)) {
2441824418
// For a (non-symbol) computed property, there is no reason to look up the name
2441924419
// in the type. It will just be "__computed", which does not appear in any
2442024420
// SymbolTable.
@@ -32305,7 +32305,7 @@ namespace ts {
3230532305
if (isPrivateIdentifier(node.name)) {
3230632306
error(node.name, Diagnostics.An_accessor_cannot_be_named_with_a_private_identifier);
3230732307
}
32308-
if (!hasNonBindableDynamicName(node)) {
32308+
if (hasBindableName(node)) {
3230932309
// TypeScript 1.0 spec (April 2014): 8.4.3
3231032310
// Accessors for the same member name must specify the same accessibility.
3231132311
const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
@@ -33631,7 +33631,7 @@ namespace ts {
3363133631
checkComputedPropertyName(node.name);
3363233632
}
3363333633

33634-
if (!hasNonBindableDynamicName(node)) {
33634+
if (hasBindableName(node)) {
3363533635
// first we want to check the local symbol that contain this declaration
3363633636
// - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
3363733637
// - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
@@ -35634,7 +35634,7 @@ namespace ts {
3563435634
// Only process instance properties with computed names here.
3563535635
// Static properties cannot be in conflict with indexers,
3563635636
// and properties with literal names were already checked.
35637-
if (!hasSyntacticModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) {
35637+
if (!hasSyntacticModifier(member, ModifierFlags.Static) && !hasBindableName(member)) {
3563835638
const symbol = getSymbolOfNode(member);
3563935639
const propType = getTypeOfSymbol(symbol);
3564035640
checkIndexConstraintForProperty(symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);

0 commit comments

Comments
 (0)