Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: push
newClass
only when class is decorated (#14334)
- Loading branch information
Showing
10 changed files
with
208 additions
and
117 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
...sal-decorators/test/fixtures/2021-12-methods--to-es2015/private-with-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,41 @@ | ||
function dec(fn, context) { | ||
context.addInitializer((instance) => { | ||
instance[context.name + 'Context'] = context; | ||
}); | ||
|
||
return function () { | ||
return fn.call(this) + 1; | ||
} | ||
} | ||
|
||
class Foo { | ||
value = 1; | ||
|
||
@dec | ||
#a() { | ||
return this.value; | ||
} | ||
|
||
callA() { | ||
return this.#a(); | ||
} | ||
} | ||
|
||
let foo = new Foo(); | ||
|
||
const aContext = foo['#aContext']; | ||
|
||
// First call gets the method, second call calls the method with correct `this` | ||
expect(aContext.access.get.call(foo).call(foo)).toBe(2); | ||
expect(foo.callA()).toBe(2); | ||
foo.value = 123; | ||
expect(aContext.access.get.call(foo).call(foo)).toBe(124); | ||
expect(foo.callA()).toBe(124); | ||
|
||
expect(aContext.name).toBe('#a'); | ||
expect(aContext.kind).toBe('method'); | ||
expect(aContext.isStatic).toBe(false); | ||
expect(aContext.isPrivate).toBe(true); | ||
expect(typeof aContext.addInitializer).toBe('function'); | ||
expect(typeof aContext.setMetadata).toBe('function'); | ||
expect(typeof aContext.getMetadata).toBe('function'); |
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
50 changes: 50 additions & 0 deletions
50
...osal-decorators/test/fixtures/2021-12-methods--to-es2015/public-with-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,50 @@ | ||
function dec(fn, context) { | ||
context.addInitializer((instance) => { | ||
instance[context.name + 'Context'] = context; | ||
}); | ||
|
||
return function () { | ||
return fn.call(this) + 1; | ||
} | ||
} | ||
|
||
class Foo { | ||
value = 1; | ||
|
||
@dec | ||
a() { | ||
return this.value; | ||
} | ||
|
||
@dec | ||
['b']() { | ||
return this.value; | ||
} | ||
} | ||
|
||
let foo = new Foo(); | ||
|
||
const aContext = foo['aContext']; | ||
const bContext = foo['bContext']; | ||
|
||
expect(foo.a()).toBe(2); | ||
expect(foo.b()).toBe(2); | ||
foo.value = 123; | ||
expect(foo.a()).toBe(124); | ||
expect(foo.b()).toBe(124); | ||
|
||
expect(aContext.name).toBe('a'); | ||
expect(aContext.kind).toBe('method'); | ||
expect(aContext.isStatic).toBe(false); | ||
expect(aContext.isPrivate).toBe(false); | ||
expect(typeof aContext.addInitializer).toBe('function'); | ||
expect(typeof aContext.setMetadata).toBe('function'); | ||
expect(typeof aContext.getMetadata).toBe('function'); | ||
|
||
expect(bContext.name).toBe('b'); | ||
expect(bContext.kind).toBe('method'); | ||
expect(bContext.isStatic).toBe(false); | ||
expect(bContext.isPrivate).toBe(false); | ||
expect(typeof bContext.addInitializer).toBe('function'); | ||
expect(typeof bContext.setMetadata).toBe('function'); | ||
expect(typeof bContext.getMetadata).toBe('function'); |
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
39 changes: 39 additions & 0 deletions
39
...orators/test/fixtures/2021-12-methods--to-es2015/static-private-with-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,39 @@ | ||
function dec(fn, context) { | ||
context.addInitializer((instance) => { | ||
instance[context.name + 'Context'] = context; | ||
}); | ||
|
||
return function () { | ||
return fn.call(this) + 1; | ||
} | ||
} | ||
|
||
class Foo { | ||
static value = 1; | ||
|
||
@dec | ||
static #a() { | ||
return this.value; | ||
} | ||
|
||
static callA() { | ||
return this.#a(); | ||
} | ||
} | ||
|
||
const aContext = Foo['#aContext']; | ||
|
||
// First call gets the method, second call calls the method with correct `this` | ||
expect(aContext.access.get.call(Foo).call(Foo)).toBe(2); | ||
expect(Foo.callA()).toBe(2); | ||
Foo.value = 123; | ||
expect(aContext.access.get.call(Foo).call(Foo)).toBe(124); | ||
expect(Foo.callA()).toBe(124); | ||
|
||
expect(aContext.name).toBe('#a'); | ||
expect(aContext.kind).toBe('method'); | ||
expect(aContext.isStatic).toBe(true); | ||
expect(aContext.isPrivate).toBe(true); | ||
expect(typeof aContext.addInitializer).toBe('function'); | ||
expect(typeof aContext.setMetadata).toBe('function'); | ||
expect(typeof aContext.getMetadata).toBe('function'); |
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
48 changes: 48 additions & 0 deletions
48
...corators/test/fixtures/2021-12-methods--to-es2015/static-public-with-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,48 @@ | ||
function dec(fn, context) { | ||
context.addInitializer((instance) => { | ||
instance[context.name + 'Context'] = context; | ||
}); | ||
|
||
return function () { | ||
return fn.call(this) + 1; | ||
} | ||
} | ||
|
||
class Foo { | ||
static value = 1; | ||
|
||
@dec | ||
static a() { | ||
return this.value; | ||
} | ||
|
||
@dec | ||
static ['b']() { | ||
return this.value; | ||
} | ||
} | ||
|
||
const aContext = Foo['aContext']; | ||
const bContext = Foo['bContext']; | ||
|
||
expect(Foo.a()).toBe(2); | ||
expect(Foo.b()).toBe(2); | ||
Foo.value = 123; | ||
expect(Foo.a()).toBe(124); | ||
expect(Foo.b()).toBe(124); | ||
|
||
expect(aContext.name).toBe('a'); | ||
expect(aContext.kind).toBe('method'); | ||
expect(aContext.isStatic).toBe(true); | ||
expect(aContext.isPrivate).toBe(false); | ||
expect(typeof aContext.addInitializer).toBe('function'); | ||
expect(typeof aContext.setMetadata).toBe('function'); | ||
expect(typeof aContext.getMetadata).toBe('function'); | ||
|
||
expect(bContext.name).toBe('b'); | ||
expect(bContext.kind).toBe('method'); | ||
expect(bContext.isStatic).toBe(true); | ||
expect(bContext.isPrivate).toBe(false); | ||
expect(typeof bContext.addInitializer).toBe('function'); | ||
expect(typeof bContext.setMetadata).toBe('function'); | ||
expect(typeof bContext.getMetadata).toBe('function'); |
Oops, something went wrong.