-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix constructor code when there is code between prologue statements and super call #48765
Merged
Merged
Changes from all commits
Commits
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 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
52 changes: 52 additions & 0 deletions
52
tests/baselines/reference/constructorWithSuperAndPrologue.es5.js
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,52 @@ | ||
//// [constructorWithSuperAndPrologue.es5.ts] | ||
// https://github.com/microsoft/TypeScript/issues/48761 | ||
"use strict"; | ||
|
||
class A { | ||
public constructor() { | ||
console.log("A") | ||
} | ||
} | ||
|
||
class B extends A { | ||
constructor() { | ||
"ngInject"; | ||
console.log("B") | ||
super(); | ||
} | ||
} | ||
|
||
|
||
//// [constructorWithSuperAndPrologue.es5.js] | ||
// https://github.com/microsoft/TypeScript/issues/48761 | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var A = /** @class */ (function () { | ||
function A() { | ||
console.log("A"); | ||
} | ||
return A; | ||
}()); | ||
var B = /** @class */ (function (_super) { | ||
__extends(B, _super); | ||
function B() { | ||
"ngInject"; | ||
console.log("B"); | ||
return _super.call(this) || this; | ||
} | ||
return B; | ||
}(A)); |
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/constructorWithSuperAndPrologue.es5.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,31 @@ | ||
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48761 | ||
"use strict"; | ||
|
||
class A { | ||
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13)) | ||
|
||
public constructor() { | ||
console.log("A") | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
} | ||
} | ||
|
||
class B extends A { | ||
>B : Symbol(B, Decl(constructorWithSuperAndPrologue.es5.ts, 7, 1)) | ||
>A : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13)) | ||
|
||
constructor() { | ||
"ngInject"; | ||
console.log("B") | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
|
||
super(); | ||
>super : Symbol(A, Decl(constructorWithSuperAndPrologue.es5.ts, 1, 13)) | ||
} | ||
} | ||
|
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/constructorWithSuperAndPrologue.es5.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,39 @@ | ||
=== tests/cases/compiler/constructorWithSuperAndPrologue.es5.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48761 | ||
"use strict"; | ||
>"use strict" : "use strict" | ||
|
||
class A { | ||
>A : A | ||
|
||
public constructor() { | ||
console.log("A") | ||
>console.log("A") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"A" : "A" | ||
} | ||
} | ||
|
||
class B extends A { | ||
>B : B | ||
>A : A | ||
|
||
constructor() { | ||
"ngInject"; | ||
>"ngInject" : "ngInject" | ||
|
||
console.log("B") | ||
>console.log("B") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"B" : "B" | ||
|
||
super(); | ||
>super() : void | ||
>super : typeof A | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
tests/cases/compiler/constructorWithSuperAndPrologue.es5.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,17 @@ | ||
// @target: es5 | ||
// https://github.com/microsoft/TypeScript/issues/48761 | ||
"use strict"; | ||
|
||
class A { | ||
public constructor() { | ||
console.log("A") | ||
} | ||
} | ||
|
||
class B extends A { | ||
constructor() { | ||
"ngInject"; | ||
console.log("B") | ||
super(); | ||
} | ||
} |
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.
The last argument is
count
and notend
, so I believe the fix is to substract the start position from here. Otherwise we're processing too many nodes (includingsuper()
)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.
Good catch!