-
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
Fixed multiple prologue directives with parameter properties #48687
Merged
jakebailey
merged 1 commit into
microsoft:main
from
JoshuaKGoldberg:fix-parameter-properties-and-prologue-directives
Apr 14, 2022
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
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 |
---|---|---|
|
@@ -1938,14 +1938,14 @@ namespace ts { | |
|
||
resumeLexicalEnvironment(); | ||
|
||
const indexAfterLastPrologueStatement = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor); | ||
const superStatementIndex = findSuperStatementIndex(body.statements, indexAfterLastPrologueStatement); | ||
const prologueStatementCount = factory.copyPrologue(body.statements, statements, /*ensureUseStrict*/ false, visitor); | ||
const superStatementIndex = findSuperStatementIndex(body.statements, prologueStatementCount); | ||
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. I'm nitpicking the variable name here. Both variable names are correct; |
||
|
||
// If there was a super call, visit existing statements up to and including it | ||
if (superStatementIndex >= 0) { | ||
addRange( | ||
statements, | ||
visitNodes(body.statements, visitor, isStatement, indexAfterLastPrologueStatement, superStatementIndex + 1 - indexAfterLastPrologueStatement), | ||
visitNodes(body.statements, visitor, isStatement, prologueStatementCount, superStatementIndex + 1 - prologueStatementCount), | ||
); | ||
} | ||
|
||
|
@@ -1967,13 +1967,17 @@ namespace ts { | |
if (superStatementIndex >= 0) { | ||
addRange(statements, parameterPropertyAssignments); | ||
} | ||
// Since there was no super() call, parameter properties are the first statements in the constructor | ||
// Since there was no super() call, parameter properties are the first statements in the constructor after any prologue statements | ||
else { | ||
statements = addRange(parameterPropertyAssignments, statements); | ||
statements = [ | ||
...statements.slice(0, prologueStatementCount), | ||
...parameterPropertyAssignments, | ||
...statements.slice(prologueStatementCount), | ||
]; | ||
} | ||
|
||
// Add remaining statements from the body, skipping the super() call if it was found | ||
addRange(statements, visitNodes(body.statements, visitor, isStatement, superStatementIndex + 1)); | ||
// Add remaining statements from the body, skipping the super() call if it was found and any (already added) prologue statements | ||
addRange(statements, visitNodes(body.statements, visitor, isStatement, superStatementIndex + 1 + prologueStatementCount)); | ||
|
||
// End the lexical environment. | ||
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); | ||
|
104 changes: 104 additions & 0 deletions
104
tests/baselines/reference/parameterPropertyInConstructorWithPrologues.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,104 @@ | ||
//// [parameterPropertyInConstructorWithPrologues.ts] | ||
// https://github.com/microsoft/TypeScript/issues/48671 | ||
|
||
class Foo1 { | ||
constructor(private A: string) { | ||
"ngInject1"; | ||
} | ||
} | ||
|
||
class Foo2 { | ||
constructor(private A: string, private B: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo3 { | ||
constructor(private A: string, private B: string, private C: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo4 { | ||
constructor(private A: string) { | ||
"ngInject1"; | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
class Foo5 { | ||
constructor(private A: string, private B: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
class Foo6 { | ||
constructor(private A: string, private B: string, private C: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
|
||
//// [parameterPropertyInConstructorWithPrologues.js] | ||
// https://github.com/microsoft/TypeScript/issues/48671 | ||
var Foo1 = /** @class */ (function () { | ||
function Foo1(A) { | ||
"ngInject1"; | ||
this.A = A; | ||
} | ||
return Foo1; | ||
}()); | ||
var Foo2 = /** @class */ (function () { | ||
function Foo2(A, B) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
this.A = A; | ||
this.B = B; | ||
} | ||
return Foo2; | ||
}()); | ||
var Foo3 = /** @class */ (function () { | ||
function Foo3(A, B, C) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
this.A = A; | ||
this.B = B; | ||
this.C = C; | ||
} | ||
return Foo3; | ||
}()); | ||
var Foo4 = /** @class */ (function () { | ||
function Foo4(A) { | ||
"ngInject1"; | ||
this.A = A; | ||
console.log("hi"); | ||
} | ||
return Foo4; | ||
}()); | ||
var Foo5 = /** @class */ (function () { | ||
function Foo5(A, B) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
this.A = A; | ||
this.B = B; | ||
console.log("hi"); | ||
} | ||
return Foo5; | ||
}()); | ||
var Foo6 = /** @class */ (function () { | ||
function Foo6(A, B, C) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
this.A = A; | ||
this.B = B; | ||
this.C = C; | ||
console.log("hi"); | ||
} | ||
return Foo6; | ||
}()); |
85 changes: 85 additions & 0 deletions
85
tests/baselines/reference/parameterPropertyInConstructorWithPrologues.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,85 @@ | ||
=== tests/cases/compiler/parameterPropertyInConstructorWithPrologues.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48671 | ||
|
||
class Foo1 { | ||
>Foo1 : Symbol(Foo1, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0)) | ||
|
||
constructor(private A: string) { | ||
>A : Symbol(Foo1.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 3, 14)) | ||
|
||
"ngInject1"; | ||
} | ||
} | ||
|
||
class Foo2 { | ||
>Foo2 : Symbol(Foo2, Decl(parameterPropertyInConstructorWithPrologues.ts, 6, 1)) | ||
|
||
constructor(private A: string, private B: string) { | ||
>A : Symbol(Foo2.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 14)) | ||
>B : Symbol(Foo2.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 32)) | ||
|
||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo3 { | ||
>Foo3 : Symbol(Foo3, Decl(parameterPropertyInConstructorWithPrologues.ts, 13, 1)) | ||
|
||
constructor(private A: string, private B: string, private C: string) { | ||
>A : Symbol(Foo3.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 14)) | ||
>B : Symbol(Foo3.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 32)) | ||
>C : Symbol(Foo3.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 51)) | ||
|
||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo4 { | ||
>Foo4 : Symbol(Foo4, Decl(parameterPropertyInConstructorWithPrologues.ts, 20, 1)) | ||
|
||
constructor(private A: string) { | ||
>A : Symbol(Foo4.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 23, 14)) | ||
|
||
"ngInject1"; | ||
console.log("hi"); | ||
>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 Foo5 { | ||
>Foo5 : Symbol(Foo5, Decl(parameterPropertyInConstructorWithPrologues.ts, 27, 1)) | ||
|
||
constructor(private A: string, private B: string) { | ||
>A : Symbol(Foo5.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 14)) | ||
>B : Symbol(Foo5.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 32)) | ||
|
||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
>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 Foo6 { | ||
>Foo6 : Symbol(Foo6, Decl(parameterPropertyInConstructorWithPrologues.ts, 35, 1)) | ||
|
||
constructor(private A: string, private B: string, private C: string) { | ||
>A : Symbol(Foo6.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 14)) | ||
>B : Symbol(Foo6.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 32)) | ||
>C : Symbol(Foo6.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 51)) | ||
|
||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
>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, --, --)) | ||
} | ||
} | ||
|
108 changes: 108 additions & 0 deletions
108
tests/baselines/reference/parameterPropertyInConstructorWithPrologues.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,108 @@ | ||
=== tests/cases/compiler/parameterPropertyInConstructorWithPrologues.ts === | ||
// https://github.com/microsoft/TypeScript/issues/48671 | ||
|
||
class Foo1 { | ||
>Foo1 : Foo1 | ||
|
||
constructor(private A: string) { | ||
>A : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
} | ||
} | ||
|
||
class Foo2 { | ||
>Foo2 : Foo2 | ||
|
||
constructor(private A: string, private B: string) { | ||
>A : string | ||
>B : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
|
||
"ngInject2"; | ||
>"ngInject2" : "ngInject2" | ||
} | ||
} | ||
|
||
class Foo3 { | ||
>Foo3 : Foo3 | ||
|
||
constructor(private A: string, private B: string, private C: string) { | ||
>A : string | ||
>B : string | ||
>C : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
|
||
"ngInject2"; | ||
>"ngInject2" : "ngInject2" | ||
} | ||
} | ||
|
||
class Foo4 { | ||
>Foo4 : Foo4 | ||
|
||
constructor(private A: string) { | ||
>A : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
|
||
console.log("hi"); | ||
>console.log("hi") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"hi" : "hi" | ||
} | ||
} | ||
|
||
class Foo5 { | ||
>Foo5 : Foo5 | ||
|
||
constructor(private A: string, private B: string) { | ||
>A : string | ||
>B : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
|
||
"ngInject2"; | ||
>"ngInject2" : "ngInject2" | ||
|
||
console.log("hi"); | ||
>console.log("hi") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"hi" : "hi" | ||
} | ||
} | ||
|
||
class Foo6 { | ||
>Foo6 : Foo6 | ||
|
||
constructor(private A: string, private B: string, private C: string) { | ||
>A : string | ||
>B : string | ||
>C : string | ||
|
||
"ngInject1"; | ||
>"ngInject1" : "ngInject1" | ||
|
||
"ngInject2"; | ||
>"ngInject2" : "ngInject2" | ||
|
||
console.log("hi"); | ||
>console.log("hi") : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>"hi" : "hi" | ||
} | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
tests/cases/compiler/parameterPropertyInConstructorWithPrologues.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,44 @@ | ||
// https://github.com/microsoft/TypeScript/issues/48671 | ||
|
||
class Foo1 { | ||
constructor(private A: string) { | ||
"ngInject1"; | ||
} | ||
} | ||
|
||
class Foo2 { | ||
constructor(private A: string, private B: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo3 { | ||
constructor(private A: string, private B: string, private C: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
} | ||
} | ||
|
||
class Foo4 { | ||
constructor(private A: string) { | ||
"ngInject1"; | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
class Foo5 { | ||
constructor(private A: string, private B: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
} | ||
} | ||
|
||
class Foo6 { | ||
constructor(private A: string, private B: string, private C: string) { | ||
"ngInject1"; | ||
"ngInject2"; | ||
console.log("hi"); | ||
} | ||
} |
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.
This change isn't necessary for the PR; I just had only noticed the check is unnecessary after #29374 was merged 😄