Skip to content

Conversation

sandersn
Copy link
Member

The check in getAssignedClassSymbol forgot to allow for default-property assignment declarations, in part because it wasn't using a utility function to do so.

Fixes #39167

The check in getAssignedClassSymbol forgot to allow for default-property
assignment declarations, in part because it wasn't using a utility
function to do so.
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 29, 2020
const exprType = checkJsxAttribute(attributeDecl, checkMode);
objectFlags |= getObjectFlags(exprType) & ObjectFlags.PropagatingFlags;

const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a drive-by fix; createSymbol always adds Transient.

isVariableDeclaration(decl.parent) && getSymbolOfNode(decl.parent));
const prototype = assignmentSymbol && assignmentSymbol.exports && assignmentSymbol.exports.get("prototype" as __String);
const init = prototype && prototype.valueDeclaration && getAssignedJSPrototype(prototype.valueDeclaration);
const assignmentSymbol = decl && getSymbolOfExpando(decl, /*allowDeclaration*/ true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the actual fix

return init ? getSymbolOfNode(init) : undefined;
}

function getSymbolOfExpando(node: Node, allowDeclaration?: boolean): Symbol | undefined {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes from the move:

  1. Return a Symbol instead of a Node, since all callers immediately do that anyway. This is why I moved it into the checker.
  2. Add a parameter allowDeclaration that allows node to be either the expando or its declaration. The parameter disables the checks that assert that node is the expando initialiser.
  3. Add a FunctionDeclaration case when allowDeclaration is true.

@sandersn sandersn merged commit f615e22 into master Sep 30, 2020
@sandersn sandersn deleted the fix-default-property-assigned-prototype branch September 30, 2020 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prototype assignment doesn't work on default-assigned constructor functions
3 participants