-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix decorator initProto usage in derived classes (#16170)
- Loading branch information
Showing
27 changed files
with
3,700 additions
and
222 deletions.
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"); | ||
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.