Skip to content
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

Add Javascript declarations to index constraint check error reporting #15586

Merged
merged 2 commits into from
May 4, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented May 4, 2017

Now Javascript-style declarations like this.foo = "bar" are handled
correctly and errors will be reported on the declaration correctly. Previously the code would check the computed property name case and crash because Javascript-style declarations have no name property.

Fixes #15525

Now Javascript-style declarations like `this.foo = "bar"` are handled
correctly.
@@ -20233,7 +20233,10 @@ namespace ts {
// perform property check if property or indexer is declared in 'type'
// this allows to rule out cases when both property and indexer are inherited from the base class
let errorNode: Node;
if (propDeclaration && (propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol)) {
if (propDeclaration &&
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty ||
Copy link
Contributor

Choose a reason for hiding this comment

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

consider moving this to the end of the check

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually needs to come first because JS-style assignments should not hit the computed property check. It won't be very expensive because most declarations are not in javascript files and even there, most declarations are not JS-style assignment declarations.

@mhegazy
Copy link
Contributor

mhegazy commented May 4, 2017

@sandersn, Please port this to release-2.3

@sandersn
Copy link
Member Author

sandersn commented May 4, 2017

I'll look into normalising use of Declaration.name, because we have to special-case JS-style assignment declarations in a number of places right now.

@sandersn sandersn merged commit d2bdfbb into master May 4, 2017
@sandersn sandersn deleted the fix-index-constraint-check-for-js-class-exprs branch May 4, 2017 19:55
@sandersn
Copy link
Member Author

sandersn commented May 4, 2017

It's merged into 2.3 now.

if (propDeclaration && (propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol)) {
if (propDeclaration &&
(getSpecialPropertyAssignmentKind(propDeclaration as BinaryExpression) === SpecialPropertyAssignmentKind.ThisProperty ||
propDeclaration.name.kind === SyntaxKind.ComputedPropertyName ||

Choose a reason for hiding this comment

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

This may crash if propDeclaration.name is undefined.

see #15681

Copy link
Member Author

Choose a reason for hiding this comment

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

Will be fixed in #15594

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants