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
Ensure non-static decorators are applied when a class is instantiated. #15059
Merged
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.
Jump to
Jump to file
Failed to load files.
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
67 changes: 67 additions & 0 deletions
67
...decorators/test/fixtures/2022-03-ordering--to-es2015/accessor-initializers-fields/exec.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,67 @@ | ||
var log = []; | ||
|
||
function push(x) { | ||
log.push(x); | ||
return x; | ||
} | ||
|
||
function logClassDecoratorRun(a, b, c) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return el; | ||
}; | ||
} | ||
|
||
function logAccessorDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return { | ||
init: () => push(d), | ||
}; | ||
}; | ||
} | ||
|
||
function logFieldDecoratorRun(a, b) { | ||
push(a); | ||
return function (el) { push(b); return el; }; | ||
} | ||
|
||
@logClassDecoratorRun(0, 19, 21) | ||
@logClassDecoratorRun(1, 18, 20) | ||
class A { | ||
@logAccessorDecoratorRun(2, 11, 23, 27) | ||
@logAccessorDecoratorRun(3, 10, 22, 26) | ||
accessor a; | ||
|
||
@logFieldDecoratorRun(4, 15) | ||
@logFieldDecoratorRun(5, 14) | ||
b; | ||
|
||
@logFieldDecoratorRun(6, 17) | ||
@logFieldDecoratorRun(7, 16) | ||
#c; | ||
|
||
@logAccessorDecoratorRun(8, 13, 25, 29) | ||
@logAccessorDecoratorRun(9, 12, 24, 28) | ||
accessor #d; | ||
|
||
constructor() { | ||
this.a = this.#d = null; | ||
} | ||
} | ||
|
||
var nums = Array.from({ length: 22 }, (_, i) => i); | ||
expect(log).toEqual(nums); | ||
|
||
new A(); | ||
|
||
var nums = Array.from({ length: 30 }, (_, i) => i); | ||
expect(log).toEqual(nums); |
75 changes: 75 additions & 0 deletions
75
...decorators/test/fixtures/2022-03-ordering--to-es2015/accessor-method-initializers/exec.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,75 @@ | ||
var log = []; | ||
|
||
function push(x) { | ||
log.push(x); | ||
return x; | ||
} | ||
|
||
function logClassDecoratorRun(a, b, c) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return el; | ||
}; | ||
} | ||
|
||
function logAccessorDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return { | ||
init: () => push(d), | ||
}; | ||
}; | ||
} | ||
|
||
function logMethodDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return () => (el(), push(d)) | ||
}; | ||
} | ||
|
||
@logClassDecoratorRun(0, 19, 21) | ||
@logClassDecoratorRun(1, 18, 20) | ||
class A { | ||
@logAccessorDecoratorRun(2, 11, 23, 31) | ||
@logAccessorDecoratorRun(3, 10, 22, 30) | ||
accessor a; | ||
|
||
@logMethodDecoratorRun(4, 13, 25, 35) | ||
@logMethodDecoratorRun(5, 12, 24, 34) | ||
b() {}; | ||
|
||
@logMethodDecoratorRun(6, 15, 27, 37) | ||
@logMethodDecoratorRun(7, 14, 26, 36) | ||
#c() {}; | ||
|
||
@logAccessorDecoratorRun(8, 17, 29, 33) | ||
@logAccessorDecoratorRun(9, 16, 28, 32) | ||
accessor #d; | ||
|
||
constructor() { | ||
this.b(); | ||
this.#c(); | ||
this.a = this.#d = null; | ||
} | ||
} | ||
|
||
var nums = Array.from({ length: 22 }, (_, i) => i); | ||
expect(log).toEqual(nums); | ||
|
||
new A(); | ||
|
||
var nums = Array.from({ length: 38 }, (_, i) => i); | ||
expect(log).toEqual(nums); |
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
77 changes: 77 additions & 0 deletions
77
...ors/test/fixtures/2022-03-ordering--to-es2015/accessor-static-method-initializers/exec.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,77 @@ | ||
var log = []; | ||
|
||
function push(x) { | ||
log.push(x); | ||
return x; | ||
} | ||
|
||
function logClassDecoratorRun(a, b, c) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return el; | ||
}; | ||
} | ||
|
||
function logAccessorDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return { | ||
init: () => push(d), | ||
}; | ||
}; | ||
} | ||
|
||
function logMethodDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return () => (el(), push(d)) | ||
}; | ||
} | ||
|
||
@logClassDecoratorRun(0, 19, 29) | ||
@logClassDecoratorRun(1, 18, 28) | ||
class A { | ||
static { | ||
A.b(), A.#c(); | ||
} | ||
|
||
@logAccessorDecoratorRun(2, 15, 31, 35) | ||
@logAccessorDecoratorRun(3, 14, 30, 34) | ||
accessor a; | ||
|
||
@logMethodDecoratorRun(4, 11, 21, 25) | ||
@logMethodDecoratorRun(5, 10, 20, 24) | ||
static b() {}; | ||
|
||
@logMethodDecoratorRun(6, 13, 23, 27) | ||
@logMethodDecoratorRun(7, 12, 22, 26) | ||
static #c() {}; | ||
|
||
@logAccessorDecoratorRun(8, 17, 33, 37) | ||
@logAccessorDecoratorRun(9, 16, 32, 36) | ||
accessor #d; | ||
|
||
constructor() { | ||
this.a = this.#d = null; | ||
} | ||
} | ||
|
||
var nums = Array.from({ length: 30 }, (_, i) => i); | ||
expect(log).toEqual(nums); | ||
|
||
new A(); | ||
|
||
var nums = Array.from({ length: 38 }, (_, i) => i); | ||
expect(log).toEqual(nums); |
31 changes: 0 additions & 31 deletions
31
...l-plugin-proposal-decorators/test/fixtures/2022-03-ordering--to-es2015/decorators/exec.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
74 changes: 74 additions & 0 deletions
74
...ors/test/fixtures/2022-03-ordering--to-es2015/static-accessor-method-initializers/exec.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,74 @@ | ||
var log = []; | ||
|
||
function push(x) { | ||
log.push(x); | ||
return x; | ||
} | ||
|
||
function logClassDecoratorRun(a, b, c) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return el; | ||
}; | ||
} | ||
|
||
function logAccessorDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return { | ||
init: () => push(d), | ||
}; | ||
}; | ||
} | ||
|
||
function logMethodDecoratorRun(a, b, c, d) { | ||
push(a); | ||
return function (el, { addInitializer }) { | ||
push(b); | ||
addInitializer(function () { | ||
push(c); | ||
}); | ||
return () => (el(), push(d)) | ||
}; | ||
} | ||
|
||
@logClassDecoratorRun(0, 19, 29) | ||
@logClassDecoratorRun(1, 18, 28) | ||
class A { | ||
@logMethodDecoratorRun(2, 15, 31, 35) | ||
@logMethodDecoratorRun(3, 14, 30, 34) | ||
a() {} | ||
|
||
@logAccessorDecoratorRun(4, 11, 21, 25) | ||
@logAccessorDecoratorRun(5, 10, 20, 24) | ||
static accessor b; | ||
|
||
@logAccessorDecoratorRun(6, 13, 23, 27) | ||
@logAccessorDecoratorRun(7, 12, 22, 26) | ||
static accessor #c; | ||
|
||
@logMethodDecoratorRun(8, 17, 33, 37) | ||
@logMethodDecoratorRun(9, 16, 32, 36) | ||
#d() {} | ||
|
||
constructor() { | ||
this.a(); | ||
this.#d(); | ||
} | ||
} | ||
|
||
var nums = Array.from({ length: 30 }, (_, i) => i); | ||
expect(log).toEqual(nums); | ||
|
||
new A(); | ||
|
||
var nums = Array.from({ length: 38 }, (_, i) => i); | ||
expect(log).toEqual(nums); |
Oops, something went wrong.
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 test here becomes more stringent: we assert that certain log must be printed before the class is instantiated.