mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-25 22:01:51 -05:00
Fix late bound method name assignment, added tests (#43344)
* Fix late bound method name assignment, added tests * Refactor bindDynamicallyNamedthisPropertyAssignment * PR comments * Rollback allowJscheck fix
This commit is contained in:
@@ -410,13 +410,15 @@ namespace ts {
|
||||
* @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
|
||||
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
|
||||
*/
|
||||
function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean): Symbol {
|
||||
Debug.assert(!hasDynamicName(node));
|
||||
function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean, isComputedName?: boolean): Symbol {
|
||||
Debug.assert(isComputedName || !hasDynamicName(node));
|
||||
|
||||
const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default";
|
||||
|
||||
// The exported symbol for an export default function/class node is always named "default"
|
||||
const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node);
|
||||
const name = isComputedName ? InternalSymbolName.Computed
|
||||
: isDefaultExport && parent ? InternalSymbolName.Default
|
||||
: getDeclarationName(node);
|
||||
|
||||
let symbol: Symbol | undefined;
|
||||
if (name === undefined) {
|
||||
@@ -2929,7 +2931,7 @@ namespace ts {
|
||||
constructorSymbol.members = constructorSymbol.members || createSymbolTable();
|
||||
// It's acceptable for multiple 'this' assignments of the same identifier to occur
|
||||
if (hasDynamicName(node)) {
|
||||
bindDynamicallyNamedThisPropertyAssignment(node, constructorSymbol);
|
||||
bindDynamicallyNamedThisPropertyAssignment(node, constructorSymbol, constructorSymbol.members);
|
||||
}
|
||||
else {
|
||||
declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
|
||||
@@ -2948,7 +2950,7 @@ namespace ts {
|
||||
const containingClass = thisContainer.parent;
|
||||
const symbolTable = hasSyntacticModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!;
|
||||
if (hasDynamicName(node)) {
|
||||
bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol);
|
||||
bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol, symbolTable);
|
||||
}
|
||||
else {
|
||||
declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.None, /*isReplaceableByMethod*/ true);
|
||||
@@ -2972,8 +2974,8 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function bindDynamicallyNamedThisPropertyAssignment(node: BinaryExpression | DynamicNamedDeclaration, symbol: Symbol) {
|
||||
bindAnonymousDeclaration(node, SymbolFlags.Property, InternalSymbolName.Computed);
|
||||
function bindDynamicallyNamedThisPropertyAssignment(node: BinaryExpression | DynamicNamedDeclaration, symbol: Symbol, symbolTable: SymbolTable) {
|
||||
declareSymbol(symbolTable, symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true, /*isComputedName*/ true);
|
||||
addLateBoundAssignmentDeclarationToSymbol(node, symbol);
|
||||
}
|
||||
|
||||
|
||||
@@ -10243,7 +10243,7 @@ namespace ts {
|
||||
if (!symbol.declarations) {
|
||||
symbol.declarations = [member];
|
||||
}
|
||||
else {
|
||||
else if(!member.symbol.isReplaceableByMethod) {
|
||||
symbol.declarations.push(member);
|
||||
}
|
||||
if (symbolFlags & SymbolFlags.Value) {
|
||||
|
||||
Reference in New Issue
Block a user