Skip to content

Improve naming of hasNonBindableDynamicName #42297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -24397,7 +24397,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.
Expand Down Expand Up @@ -32288,7 +32288,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;
Expand Down Expand Up @@ -33614,7 +33614,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
Expand Down Expand Up @@ -35617,7 +35617,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);
Expand Down