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 decorator initProto usage in derived classes #16170
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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
185 changes: 165 additions & 20 deletions
185
...tors/test/fixtures/2021-12-misc--to-es2015/initProto-existing-derived-constructor/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 |
---|---|---|
@@ -1,28 +1,173 @@ | ||
let self, a, initCalled; | ||
{ | ||
let self, a, initCalled; | ||
|
||
function deco(_, context) { | ||
context.addInitializer(() => { | ||
initCalled = true; | ||
}) | ||
} | ||
function deco(_, context) { | ||
context.addInitializer(() => { | ||
initCalled = true; | ||
}); | ||
} | ||
|
||
class B { | ||
constructor(s) { | ||
a = s; | ||
class B { | ||
constructor(s) { | ||
a = s; | ||
} | ||
} | ||
} | ||
|
||
class A extends B { | ||
constructor() { | ||
let a = 2; | ||
self = super(a); | ||
class A extends B { | ||
constructor() { | ||
let a = 2; | ||
self = super(a); | ||
} | ||
|
||
@deco | ||
method() {} | ||
} | ||
|
||
@deco | ||
method() {} | ||
let instance = new A(); | ||
expect(self).toBe(instance); | ||
expect(a).toBe(2); | ||
expect(initCalled).toBe(true); | ||
} | ||
|
||
let instance = new A(); | ||
expect(self).toBe(instance); | ||
expect(a).toBe(2); | ||
expect(initCalled).toBe(true); | ||
{ | ||
const dec = (fn) => { | ||
return function () { | ||
return fn.call(this) + 100; | ||
}; | ||
}; | ||
|
||
class B { | ||
constructor(v) { | ||
this.a = v; | ||
} | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
{ | ||
("super() nested within another constructor should not be transformed"); | ||
let log = []; | ||
class A extends B { | ||
constructor() { | ||
log.push(super(3).method()); | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(4).method()); | ||
} | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("103,4"); | ||
} | ||
|
||
{ | ||
("super() not in decorated derived constructor should not be transformed: computed key"); | ||
let log = []; | ||
new (class Dummy extends B { | ||
constructor() { | ||
let key; | ||
class A extends B { | ||
constructor() { | ||
log.push(super(6).method()); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
|
||
[((key = super(5).method()), log.push(key), key)]; | ||
} | ||
|
||
new A(); | ||
} | ||
})(); | ||
|
||
expect(log + "").toBe("5,106"); | ||
} | ||
|
||
{ | ||
("super() in decorator expression within decorated derived constructor should be transformed: decorator expression"); | ||
let log = []; | ||
const noop = () => (fn) => fn; | ||
new (class extends B { | ||
constructor() { | ||
class A extends B { | ||
constructor() { | ||
log.push(super(8).method()); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
|
||
@noop(log.push(super(7).method())) noop() {} | ||
} | ||
|
||
new A(); | ||
} | ||
})(); | ||
|
||
expect(log + "").toBe("7,108"); | ||
} | ||
|
||
{ | ||
("super() within decorated derived constructor should be transformed: computed key"); | ||
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 test will fail if we skip the whole |
||
let log = []; | ||
class A extends B { | ||
constructor() { | ||
let key; | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(10).method()); | ||
} | ||
[((key = super(9).method()), log.push(key), key)]; | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("109,10"); | ||
} | ||
|
||
{ | ||
("super() within decorated derived constructor should be transformed: decorator expression"); | ||
let log = []; | ||
const noop = () => (fn) => fn; | ||
class A extends B { | ||
constructor() { | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(12).method()); | ||
} | ||
@noop(log.push(super(11).method())) noop() {} | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("111,12"); | ||
} | ||
} |
173 changes: 173 additions & 0 deletions
173
...osal-decorators/test/fixtures/2021-12-misc/initProto-existing-derived-constructor/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,173 @@ | ||
{ | ||
let self, a, initCalled; | ||
|
||
function deco(_, context) { | ||
context.addInitializer(() => { | ||
initCalled = true; | ||
}); | ||
} | ||
|
||
class B { | ||
constructor(s) { | ||
a = s; | ||
} | ||
} | ||
|
||
class A extends B { | ||
constructor() { | ||
let a = 2; | ||
self = super(a); | ||
} | ||
|
||
@deco | ||
method() {} | ||
} | ||
|
||
let instance = new A(); | ||
expect(self).toBe(instance); | ||
expect(a).toBe(2); | ||
expect(initCalled).toBe(true); | ||
} | ||
|
||
{ | ||
const dec = (fn) => { | ||
return function () { | ||
return fn.call(this) + 100; | ||
}; | ||
}; | ||
|
||
class B { | ||
constructor(v) { | ||
this.a = v; | ||
} | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
{ | ||
("super() nested within another constructor should not be transformed"); | ||
let log = []; | ||
class A extends B { | ||
constructor() { | ||
log.push(super(3).method()); | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(4).method()); | ||
} | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("103,4"); | ||
} | ||
|
||
{ | ||
("super() not in decorated derived constructor should not be transformed: computed key"); | ||
let log = []; | ||
new (class Dummy extends B { | ||
constructor() { | ||
let key; | ||
class A extends B { | ||
constructor() { | ||
log.push(super(6).method()); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
|
||
[((key = super(5).method()), log.push(key), key)]; | ||
} | ||
|
||
new A(); | ||
} | ||
})(); | ||
|
||
expect(log + "").toBe("5,106"); | ||
} | ||
|
||
{ | ||
("super() in decorator expression within decorated derived constructor should be transformed: decorator expression"); | ||
let log = []; | ||
const noop = () => (fn) => fn; | ||
new (class extends B { | ||
constructor() { | ||
class A extends B { | ||
constructor() { | ||
log.push(super(8).method()); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
|
||
@noop(log.push(super(7).method())) noop() {} | ||
} | ||
|
||
new A(); | ||
} | ||
})(); | ||
|
||
expect(log + "").toBe("7,108"); | ||
} | ||
|
||
{ | ||
("super() within decorated derived constructor should be transformed: computed key"); | ||
let log = []; | ||
class A extends B { | ||
constructor() { | ||
let key; | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(10).method()); | ||
} | ||
[((key = super(9).method()), log.push(key), key)]; | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("109,10"); | ||
} | ||
|
||
{ | ||
("super() within decorated derived constructor should be transformed: decorator expression"); | ||
let log = []; | ||
const noop = () => (fn) => fn; | ||
class A extends B { | ||
constructor() { | ||
new (class Dummy extends B { | ||
constructor() { | ||
log.push(super(12).method()); | ||
} | ||
@noop(log.push(super(11).method())) noop() {} | ||
})(); | ||
} | ||
|
||
@dec | ||
method() { | ||
return this.a; | ||
} | ||
} | ||
|
||
new A(); | ||
|
||
expect(log + "").toBe("111,12"); | ||
} | ||
} |
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.
Can we skip
ClassExpression
?