-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add Javascript declarations to index constraint check error reporting #15586
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
sandersn
merged 2 commits into
master
from
fix-index-constraint-check-for-js-class-exprs
May 4, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 || | ||
propDeclaration.name.kind === SyntaxKind.ComputedPropertyName || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may crash if propDeclaration.name is see #15681 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be fixed in #15594 |
||
prop.parent === containingType.symbol)) { | ||
errorNode = propDeclaration; | ||
} | ||
else if (indexDeclaration) { | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/checkIndexConstraintOfJavascriptClassExpression.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [weird.js] | ||
someFunction(function(BaseClass) { | ||
class Hello extends BaseClass { | ||
constructor() { | ||
this.foo = "bar"; | ||
} | ||
} | ||
}); | ||
|
||
|
||
//// [foo.js] | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
someFunction(function (BaseClass) { | ||
var Hello = (function (_super) { | ||
__extends(Hello, _super); | ||
function Hello() { | ||
var _this = this; | ||
_this.foo = "bar"; | ||
return _this; | ||
} | ||
return Hello; | ||
}(BaseClass)); | ||
}); |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/checkIndexConstraintOfJavascriptClassExpression.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
=== tests/cases/compiler/weird.js === | ||
someFunction(function(BaseClass) { | ||
>BaseClass : Symbol(BaseClass, Decl(weird.js, 0, 22)) | ||
|
||
class Hello extends BaseClass { | ||
>Hello : Symbol(Hello, Decl(weird.js, 0, 34)) | ||
>BaseClass : Symbol(BaseClass, Decl(weird.js, 0, 22)) | ||
|
||
constructor() { | ||
this.foo = "bar"; | ||
>this.foo : Symbol(Hello.foo, Decl(weird.js, 2, 17)) | ||
>this : Symbol(Hello, Decl(weird.js, 0, 34)) | ||
>foo : Symbol(Hello.foo, Decl(weird.js, 2, 17)) | ||
} | ||
} | ||
}); | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/checkIndexConstraintOfJavascriptClassExpression.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== tests/cases/compiler/weird.js === | ||
someFunction(function(BaseClass) { | ||
>someFunction(function(BaseClass) { class Hello extends BaseClass { constructor() { this.foo = "bar"; } }}) : any | ||
>someFunction : any | ||
>function(BaseClass) { class Hello extends BaseClass { constructor() { this.foo = "bar"; } }} : (BaseClass: any) => void | ||
>BaseClass : any | ||
|
||
class Hello extends BaseClass { | ||
>Hello : Hello | ||
>BaseClass : any | ||
|
||
constructor() { | ||
this.foo = "bar"; | ||
>this.foo = "bar" : "bar" | ||
>this.foo : string | ||
>this : this | ||
>foo : string | ||
>"bar" : "bar" | ||
} | ||
} | ||
}); | ||
|
10 changes: 10 additions & 0 deletions
10
tests/cases/compiler/checkIndexConstraintOfJavascriptClassExpression.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @Filename: weird.js | ||
// @allowJs: true | ||
// @out: foo.js | ||
someFunction(function(BaseClass) { | ||
class Hello extends BaseClass { | ||
constructor() { | ||
this.foo = "bar"; | ||
} | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.