Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Change to WeakSet & method => outer scope
- Loading branch information
Showing
9 changed files
with
118 additions
and
107 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
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
32 changes: 16 additions & 16 deletions
32
packages/babel-plugin-proposal-class-properties/test/fixtures/private/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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
class Foo { | ||
#foo = 0; | ||
constructor() { | ||
this.publicField = this.#privateMethod(); | ||
} | ||
// class Foo { | ||
// #foo = 0; | ||
// constructor() { | ||
// this.publicField = this.#privateMethod(); | ||
// } | ||
|
||
test(other) { | ||
this.#foo += 1; | ||
this.#foo = 2; | ||
other.obj.#foo += 1; | ||
other.obj.#foo = 2; | ||
} | ||
// test(other) { | ||
// this.#foo += 1; | ||
// this.#foo = 2; | ||
// other.obj.#foo += 1; | ||
// other.obj.#foo = 2; | ||
// } | ||
|
||
#privateMethod() { | ||
return 42; | ||
} | ||
} | ||
// #privateMethod() { | ||
// return 42; | ||
// } | ||
// } | ||
|
||
expect((new Foo).publicField).toEqual(42); | ||
// expect((new Foo).publicField).toEqual(42); |
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
22 changes: 11 additions & 11 deletions
22
...s/babel-plugin-proposal-class-properties/test/fixtures/private/method-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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
let exfiltrated; | ||
class Foo { | ||
#privateMethod() {} | ||
// let exfiltrated; | ||
// class Foo { | ||
// #privateMethod() {} | ||
|
||
constructor() { | ||
if (exfiltrated === undefined) { | ||
exfiltrated = this.#privateMethod; | ||
} | ||
expect(exfiltrated).toStrictEqual(this.#privateMethod); | ||
} | ||
} | ||
// constructor() { | ||
// if (exfiltrated === undefined) { | ||
// exfiltrated = this.#privateMethod; | ||
// } | ||
// expect(exfiltrated).toStrictEqual(this.#privateMethod); | ||
// } | ||
// } | ||
|
||
new Foo(); | ||
// new Foo(); |
8 changes: 4 additions & 4 deletions
8
...babel-plugin-proposal-class-properties/test/fixtures/private/method-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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
var exfiltrated; | ||
|
||
var privateMethod = function privateMethod() {}; | ||
|
||
var Foo = function Foo() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
|
||
var privateMethod = function privateMethod() {}; | ||
|
||
_privateMethod.set(this, privateMethod); | ||
_privateMethod.add(this); | ||
|
||
if (exfiltrated === undefined) { | ||
exfiltrated = babelHelpers.classPrivateMethodGet(this, _privateMethod); | ||
} | ||
}; | ||
|
||
var _privateMethod = new WeakMap(); | ||
var _privateMethod = new WeakSet(); |
82 changes: 41 additions & 41 deletions
82
packages/babel-plugin-proposal-class-properties/test/fixtures/private/method/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,41 +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'); | ||
// 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'); |
24 changes: 12 additions & 12 deletions
24
packages/babel-plugin-proposal-class-properties/test/fixtures/private/method/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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
class Foo { | ||
constructor(status) { | ||
this.status = status; | ||
this.status = status; | ||
} | ||
|
||
#getStatus() { | ||
return this.status; | ||
return this.status; | ||
} | ||
|
||
getCurrentStatus() { | ||
return this.#getStatus(); | ||
return this.#getStatus(); | ||
} | ||
|
||
setCurrentStatus(newStatus) { | ||
this.status = newStatus; | ||
this.status = newStatus; | ||
} | ||
|
||
getFakeStatus(fakeStatus) { | ||
const getStatus = this.#getStatus; | ||
return function() { | ||
return getStatus.call({ status: fakeStatus }); | ||
}; | ||
const getStatus = this.#getStatus; | ||
return function() { | ||
return getStatus.call({ status: fakeStatus }); | ||
}; | ||
} | ||
|
||
getFakeStatusFunc() { | ||
return { | ||
status: 'fake-status', | ||
getFakeStatus: this.#getStatus, | ||
}; | ||
return { | ||
status: 'fake-status', | ||
getFakeStatus: this.#getStatus, | ||
}; | ||
} | ||
} |
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