Skip to content

Fix default property assigned prototype #40836

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 4 commits into from
Sep 30, 2020

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
@@ -24828,7 +24829,7 @@ namespace ts {
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