Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
226 additions
and
0 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
11 changes: 11 additions & 0 deletions
11
...bel-plugin-proposal-private-methods/test/fixtures/private-method-loose/assignment/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,11 @@ | ||
class Foo { | ||
constructor() { | ||
this.publicField = this.#privateMethod(); | ||
} | ||
|
||
#privateMethod() { | ||
return 42; | ||
} | ||
} | ||
|
||
expect((new Foo).publicField).toEqual(42); |
9 changes: 9 additions & 0 deletions
9
...el-plugin-proposal-private-methods/test/fixtures/private-method-loose/assignment/input.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,9 @@ | ||
class Foo { | ||
constructor() { | ||
this.publicField = this.#privateMethod(); | ||
} | ||
|
||
#privateMethod() { | ||
return 42; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...l-plugin-proposal-private-methods/test/fixtures/private-method-loose/assignment/output.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,16 @@ | ||
var Foo = function Foo() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _privateMethod, { | ||
writable: false, | ||
value: _privateMethod2 | ||
}); | ||
this.publicField = babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod](); | ||
}; | ||
|
||
var _privateMethod = babelHelpers.classPrivateFieldLooseKey("privateMethod"); | ||
|
||
var _privateMethod2 = function _privateMethod2() { | ||
return 42; | ||
}; |
41 changes: 41 additions & 0 deletions
41
.../babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/context/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 @@ | ||
class Foo { | ||
constructor(status) { | ||
this.status = status; | ||
expect(() => this.#getStatus = null).toThrow(TypeError); | ||
} | ||
|
||
#getStatus() { | ||
return this.status; | ||
} | ||
|
||
getCurrentStatus() { | ||
return this.#getStatus(); | ||
} | ||
|
||
setCurrentStatus(newStatus) { | ||
this.status = newStatus; | ||
} | ||
|
||
getFakeStatus(fakeStatus) { | ||
const getStatus = this.#getStatus; | ||
return function () { | ||
return getStatus.call({ status: fakeStatus }); | ||
}; | ||
} | ||
|
||
getFakeStatusFunc() { | ||
return { | ||
status: 'fake-status', | ||
getFakeStatus: this.#getStatus, | ||
}; | ||
} | ||
} | ||
|
||
const f = new Foo('inactive'); | ||
expect(f.getCurrentStatus()).toBe('inactive'); | ||
|
||
f.setCurrentStatus('new-status'); | ||
expect(f.getCurrentStatus()).toBe('new-status'); | ||
|
||
expect(f.getFakeStatus('fake')()).toBe('fake'); | ||
expect(f.getFakeStatusFunc().getFakeStatus()).toBe('fake-status'); |
31 changes: 31 additions & 0 deletions
31
...babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/context/input.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,31 @@ | ||
class Foo { | ||
constructor(status) { | ||
this.status = status; | ||
} | ||
|
||
#getStatus() { | ||
return this.status; | ||
} | ||
|
||
getCurrentStatus() { | ||
return this.#getStatus(); | ||
} | ||
|
||
setCurrentStatus(newStatus) { | ||
this.status = newStatus; | ||
} | ||
|
||
getFakeStatus(fakeStatus) { | ||
const fakeGetStatus = this.#getStatus; | ||
return function() { | ||
return fakeGetStatus.call({ status: fakeStatus }); | ||
}; | ||
} | ||
|
||
getFakeStatusFunc() { | ||
return { | ||
status: 'fake-status', | ||
getFakeStatus: this.#getStatus, | ||
}; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...abel-plugin-proposal-private-methods/test/fixtures/private-method-loose/context/output.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,52 @@ | ||
var Foo = | ||
/*#__PURE__*/ | ||
function () { | ||
"use strict"; | ||
|
||
function Foo(status) { | ||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _getStatus, { | ||
writable: false, | ||
value: _getStatus2 | ||
}); | ||
this.status = status; | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "getCurrentStatus", | ||
value: function getCurrentStatus() { | ||
return babelHelpers.classPrivateFieldLooseBase(this, _getStatus)[_getStatus](); | ||
} | ||
}, { | ||
key: "setCurrentStatus", | ||
value: function setCurrentStatus(newStatus) { | ||
this.status = newStatus; | ||
} | ||
}, { | ||
key: "getFakeStatus", | ||
value: function getFakeStatus(fakeStatus) { | ||
var fakeGetStatus = babelHelpers.classPrivateFieldLooseBase(this, _getStatus)[_getStatus]; | ||
|
||
return function () { | ||
return fakeGetStatus.call({ | ||
status: fakeStatus | ||
}); | ||
}; | ||
} | ||
}, { | ||
key: "getFakeStatusFunc", | ||
value: function getFakeStatusFunc() { | ||
return { | ||
status: 'fake-status', | ||
getFakeStatus: babelHelpers.classPrivateFieldLooseBase(this, _getStatus)[_getStatus] | ||
}; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _getStatus = babelHelpers.classPrivateFieldLooseKey("getStatus"); | ||
|
||
var _getStatus2 = function _getStatus2() { | ||
return this.status; | ||
}; |
13 changes: 13 additions & 0 deletions
13
...el-plugin-proposal-private-methods/test/fixtures/private-method-loose/exfiltrated/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,13 @@ | ||
let exfiltrated; | ||
class Foo { | ||
#privateMethod() {} | ||
|
||
constructor() { | ||
if (exfiltrated === undefined) { | ||
exfiltrated = this.#privateMethod; | ||
} | ||
expect(exfiltrated).toStrictEqual(this.#privateMethod); | ||
} | ||
} | ||
|
||
new Foo(); |
10 changes: 10 additions & 0 deletions
10
...l-plugin-proposal-private-methods/test/fixtures/private-method-loose/exfiltrated/input.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,10 @@ | ||
let exfiltrated; | ||
class Foo { | ||
#privateMethod() {} | ||
|
||
constructor() { | ||
if (exfiltrated === undefined) { | ||
exfiltrated = this.#privateMethod; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...-plugin-proposal-private-methods/test/fixtures/private-method-loose/exfiltrated/output.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,19 @@ | ||
var exfiltrated; | ||
|
||
var Foo = function Foo() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _privateMethod, { | ||
writable: false, | ||
value: _privateMethod2 | ||
}); | ||
|
||
if (exfiltrated === undefined) { | ||
exfiltrated = babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod]; | ||
} | ||
}; | ||
|
||
var _privateMethod = babelHelpers.classPrivateFieldLooseKey("privateMethod"); | ||
|
||
var _privateMethod2 = function _privateMethod2() {}; |