-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add private named instance field transformation (#31)
Implements private instance fields on top of the class properties refactor. Signed-off-by: Joseph Watts <jwatts43@bloomberg.net> Signed-off-by: Max Heiber <max.heiber@gmail.com>
- Loading branch information
Showing
57 changed files
with
1,739 additions
and
112 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//// [privateNameDeclaration.ts] | ||
class A { | ||
#name: string; | ||
} | ||
|
||
|
||
//// [privateNameDeclaration.js] | ||
var _name; | ||
var A = /** @class */ (function () { | ||
function A() { | ||
_name.set(this, void 0); | ||
} | ||
return A; | ||
}()); | ||
_name = new WeakMap(); |
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,8 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameDeclaration.ts === | ||
class A { | ||
>A : Symbol(A, Decl(privateNameDeclaration.ts, 0, 0)) | ||
|
||
#name: string; | ||
>#name : Symbol(A.#name, Decl(privateNameDeclaration.ts, 0, 9)) | ||
} | ||
|
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,8 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameDeclaration.ts === | ||
class A { | ||
>A : A | ||
|
||
#name: string; | ||
>#name : string | ||
} | ||
|
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
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,20 @@ | ||
//// [privateNameFieldAccess.ts] | ||
class A { | ||
#myField = "hello world"; | ||
constructor() { | ||
console.log(this.#myField); | ||
} | ||
} | ||
|
||
|
||
//// [privateNameFieldAccess.js] | ||
var _classPrivateFieldGet = function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); }; | ||
var _myField; | ||
var A = /** @class */ (function () { | ||
function A() { | ||
_myField.set(this, "hello world"); | ||
console.log(_classPrivateFieldGet(this, _myField)); | ||
} | ||
return A; | ||
}()); | ||
_myField = new WeakMap(); |
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,17 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameFieldAccess.ts === | ||
class A { | ||
>A : Symbol(A, Decl(privateNameFieldAccess.ts, 0, 0)) | ||
|
||
#myField = "hello world"; | ||
>#myField : Symbol(A.#myField, Decl(privateNameFieldAccess.ts, 0, 9)) | ||
|
||
constructor() { | ||
console.log(this.#myField); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>this.#myField : Symbol(A.#myField, Decl(privateNameFieldAccess.ts, 0, 9)) | ||
>this : Symbol(A, Decl(privateNameFieldAccess.ts, 0, 0)) | ||
} | ||
} | ||
|
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 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/privateNameFieldAccess.ts === | ||
class A { | ||
>A : A | ||
|
||
#myField = "hello world"; | ||
>#myField : string | ||
>"hello world" : "hello world" | ||
|
||
constructor() { | ||
console.log(this.#myField); | ||
>console.log(this.#myField) : void | ||
>console.log : (message?: any, ...optionalParams: any[]) => void | ||
>console : Console | ||
>log : (message?: any, ...optionalParams: any[]) => void | ||
>this.#myField : string | ||
>this : this | ||
} | ||
} | ||
|
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,78 @@ | ||
//// [privateNameFieldAssignment.ts] | ||
class A { | ||
#field = 0; | ||
constructor() { | ||
this.#field = 1; | ||
this.#field += 2; | ||
this.#field -= 3; | ||
this.#field /= 4; | ||
this.#field *= 5; | ||
this.#field **= 6; | ||
this.#field %= 7; | ||
this.#field <<= 8; | ||
this.#field >>= 9; | ||
this.#field >>>= 10; | ||
this.#field &= 11; | ||
this.#field |= 12; | ||
this.#field ^= 13; | ||
A.getInstance().#field = 1; | ||
A.getInstance().#field += 2; | ||
A.getInstance().#field -= 3; | ||
A.getInstance().#field /= 4; | ||
A.getInstance().#field *= 5; | ||
A.getInstance().#field **= 6; | ||
A.getInstance().#field %= 7; | ||
A.getInstance().#field <<= 8; | ||
A.getInstance().#field >>= 9; | ||
A.getInstance().#field >>>= 10; | ||
A.getInstance().#field &= 11; | ||
A.getInstance().#field |= 12; | ||
A.getInstance().#field ^= 13; | ||
} | ||
static getInstance() { | ||
return new A(); | ||
} | ||
} | ||
|
||
|
||
//// [privateNameFieldAssignment.js] | ||
var _classPrivateFieldSet = function (receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; }; | ||
var _classPrivateFieldGet = function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); }; | ||
var _field; | ||
var A = /** @class */ (function () { | ||
function A() { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
_field.set(this, 0); | ||
_classPrivateFieldSet(this, _field, 1); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) + 2); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) - 3); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) / 4); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) * 5); | ||
_classPrivateFieldSet(this, _field, Math.pow(_classPrivateFieldGet(this, _field), 6)); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) % 7); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) << 8); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) >> 9); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) >>> 10); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) & 11); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) | 12); | ||
_classPrivateFieldSet(this, _field, _classPrivateFieldGet(this, _field) ^ 13); | ||
_classPrivateFieldSet(A.getInstance(), _field, 1); | ||
_classPrivateFieldSet(_a = A.getInstance(), _field, _classPrivateFieldGet(_a, _field) + 2); | ||
_classPrivateFieldSet(_b = A.getInstance(), _field, _classPrivateFieldGet(_b, _field) - 3); | ||
_classPrivateFieldSet(_c = A.getInstance(), _field, _classPrivateFieldGet(_c, _field) / 4); | ||
_classPrivateFieldSet(_d = A.getInstance(), _field, _classPrivateFieldGet(_d, _field) * 5); | ||
_classPrivateFieldSet(_e = A.getInstance(), _field, Math.pow(_classPrivateFieldGet(_e, _field), 6)); | ||
_classPrivateFieldSet(_f = A.getInstance(), _field, _classPrivateFieldGet(_f, _field) % 7); | ||
_classPrivateFieldSet(_g = A.getInstance(), _field, _classPrivateFieldGet(_g, _field) << 8); | ||
_classPrivateFieldSet(_h = A.getInstance(), _field, _classPrivateFieldGet(_h, _field) >> 9); | ||
_classPrivateFieldSet(_j = A.getInstance(), _field, _classPrivateFieldGet(_j, _field) >>> 10); | ||
_classPrivateFieldSet(_k = A.getInstance(), _field, _classPrivateFieldGet(_k, _field) & 11); | ||
_classPrivateFieldSet(_l = A.getInstance(), _field, _classPrivateFieldGet(_l, _field) | 12); | ||
_classPrivateFieldSet(_m = A.getInstance(), _field, _classPrivateFieldGet(_m, _field) ^ 13); | ||
} | ||
A.getInstance = function () { | ||
return new A(); | ||
}; | ||
return A; | ||
}()); | ||
_field = new WeakMap(); |
Oops, something went wrong.