-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix class/constructor-function merge (#27366)
The check for prototype assignment on constructor functions assumes that the prototype property, if present, comes from an assignment declaration, such as: ```js SomeClass.prototype = { /* methods go here */ } ``` In this case, however, when class SomeClass and var SomeClass merge (because this is allowed), prototype is the synthetic property from class SomeClass, which has no valueDeclaration. The fix is to check that prototype has a valueDeclaration before checking whether the valueDeclaration is in fact a prototype-assignment declaration.
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/constructorFunctionMergeWithClass.symbols
This file contains 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,21 @@ | ||
=== tests/cases/conformance/salsa/file1.js === | ||
var SomeClass = function () { | ||
>SomeClass : Symbol(SomeClass, Decl(file1.js, 0, 3), Decl(file2.js, 0, 0), Decl(file2.js, 0, 19)) | ||
|
||
this.otherProp = 0; | ||
>otherProp : Symbol(SomeClass.otherProp, Decl(file1.js, 0, 29)) | ||
|
||
}; | ||
|
||
new SomeClass(); | ||
>SomeClass : Symbol(SomeClass, Decl(file1.js, 0, 3), Decl(file2.js, 0, 0), Decl(file2.js, 0, 19)) | ||
|
||
=== tests/cases/conformance/salsa/file2.js === | ||
class SomeClass { } | ||
>SomeClass : Symbol(SomeClass, Decl(file1.js, 0, 3), Decl(file2.js, 0, 0), Decl(file2.js, 0, 19)) | ||
|
||
SomeClass.prop = 0 | ||
>SomeClass.prop : Symbol(SomeClass.prop, Decl(file2.js, 0, 19)) | ||
>SomeClass : Symbol(SomeClass, Decl(file1.js, 0, 3), Decl(file2.js, 0, 0), Decl(file2.js, 0, 19)) | ||
>prop : Symbol(SomeClass.prop, Decl(file2.js, 0, 19)) | ||
|
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/constructorFunctionMergeWithClass.types
This file contains 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,29 @@ | ||
=== tests/cases/conformance/salsa/file1.js === | ||
var SomeClass = function () { | ||
>SomeClass : typeof SomeClass | ||
>function () { this.otherProp = 0;} : typeof SomeClass | ||
|
||
this.otherProp = 0; | ||
>this.otherProp = 0 : 0 | ||
>this.otherProp : any | ||
>this : any | ||
>otherProp : any | ||
>0 : 0 | ||
|
||
}; | ||
|
||
new SomeClass(); | ||
>new SomeClass() : SomeClass | ||
>SomeClass : typeof SomeClass | ||
|
||
=== tests/cases/conformance/salsa/file2.js === | ||
class SomeClass { } | ||
>SomeClass : SomeClass | ||
|
||
SomeClass.prop = 0 | ||
>SomeClass.prop = 0 : 0 | ||
>SomeClass.prop : number | ||
>SomeClass : typeof SomeClass | ||
>prop : number | ||
>0 : 0 | ||
|
14 changes: 14 additions & 0 deletions
14
tests/cases/conformance/salsa/constructorFunctionMergeWithClass.ts
This file contains 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,14 @@ | ||
// @allowJs: true | ||
// @noEmit: true | ||
// @checkJs: true | ||
|
||
// @Filename: file1.js | ||
var SomeClass = function () { | ||
this.otherProp = 0; | ||
}; | ||
|
||
new SomeClass(); | ||
|
||
// @Filename: file2.js | ||
class SomeClass { } | ||
SomeClass.prop = 0 |