Skip to content

Commit 2845d2f

Browse files
committed
Improve naming and documentation from PR
1 parent cabd276 commit 2845d2f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/compiler/binder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ namespace ts {
313313
// declaration we have for this symbol, and then create a new symbol for this
314314
// declaration.
315315
//
316+
// Note that when properties declared in Javascript constructors
317+
// (marked by isReplaceableByMethod) conflict with another symbol, the property loses.
318+
// Always. This allows the common Javascript pattern of overwriting a prototype method
319+
// with an bound instance method of the same type: `this.method = this.method.bind(this)`
320+
//
316321
// If we created a new symbol, either because we didn't have a symbol with this name
317322
// in the symbol table, or we conflicted with an existing symbol, then just add this
318323
// node as the sole declaration of the new symbol.
@@ -329,7 +334,7 @@ namespace ts {
329334
}
330335

331336
if (symbol.flags & excludes) {
332-
if (symbol.isDiscardable) {
337+
if (symbol.isReplaceableByMethod) {
333338
// Javascript constructor-declared symbols can be discarded in favor of
334339
// prototype symbols like methods.
335340
symbol = symbolTable[name] = createSymbol(SymbolFlags.None, name);
@@ -1988,7 +1993,7 @@ namespace ts {
19881993
// It's acceptable for multiple 'this' assignments of the same identifier to occur
19891994
// AND it can be overwritten by subsequent method declarations
19901995
const symbol = declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
1991-
symbol.isDiscardable = true;
1996+
symbol.isReplaceableByMethod = true;
19921997
}
19931998

19941999
function bindPrototypePropertyAssignment(node: BinaryExpression) {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ namespace ts {
21372137
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
21382138
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums
21392139
/* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere
2140-
/* @internal */ isDiscardable?: boolean; // True if a Javascript class property can be overwritten by a method
2140+
/* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol?
21412141
}
21422142

21432143
/* @internal */

0 commit comments

Comments
 (0)