Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
destructuring private fields with array pattern / object patte… (#10017)
* destructuring private fields with array pattern / object pattern * wip: new test cases * destrucuring and rest for private properties * test case for loose private-loose * add transform-desturcturing for exec * update test case * remove getPrototypeOf imports from get and set * wip: destructure super assignment * throw "Destructuring to a super field is not supported yet." * fix tests and fix assignment pattern * remove CallExpression from AssignmentPattern
- Loading branch information
1 parent
7f47cb6
commit d3fe22f
Showing
88 changed files
with
970 additions
and
4 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
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
17 changes: 17 additions & 0 deletions
17
...oposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-1/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,17 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
this.#client = 1; | ||
;([this.x = this.#client, this.#client, this.y = this.#client] = props); | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo([undefined, 'bar']); | ||
expect(foo.getClient()).toBe('bar'); | ||
expect(foo.x).toBe(1); | ||
expect(foo.y).toBe('bar'); |
8 changes: 8 additions & 0 deletions
8
...posal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-1/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,8 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
this.#client = 1; | ||
([this.x = this.#client, this.#client, this.y = this.#client] = props); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...osal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-1/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,13 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
babelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = 1; | ||
[this.x = babelHelpers.classPrivateFieldLooseBase(this, _client)[_client], babelHelpers.classPrivateFieldLooseBase(this, _client)[_client], this.y = babelHelpers.classPrivateFieldLooseBase(this, _client)[_client]] = props; | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
15 changes: 15 additions & 0 deletions
15
...oposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-2/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,15 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
let x; | ||
;([x, ...this.#client] = props); | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo(['foo', 'bar', 'baz', 'quu']); | ||
expect(foo.getClient()).toEqual(['bar', 'baz', 'quu']); |
7 changes: 7 additions & 0 deletions
7
...posal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-2/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,7 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
([x, ...this.#client] = props); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...osal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-2/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,12 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
[x, ...babelHelpers.classPrivateFieldLooseBase(this, _client)[_client]] = props; | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
14 changes: 14 additions & 0 deletions
14
...oposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-3/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,14 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
([this.#client = 5] = props); | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo([]); | ||
expect(foo.getClient()).toEqual(5); |
7 changes: 7 additions & 0 deletions
7
...posal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-3/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,7 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
([this.#client = 5] = props); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...osal-class-properties/test/fixtures/private-loose/destructuring-array-pattern-3/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,12 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
[babelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = 5] = props; | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
14 changes: 14 additions & 0 deletions
14
...proposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern/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,14 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
;([this.#client] = props); | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo(['bar']); | ||
expect(foo.getClient()).toBe('bar'); |
7 changes: 7 additions & 0 deletions
7
...roposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern/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,7 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
([this.#client] = props); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...oposal-class-properties/test/fixtures/private-loose/destructuring-array-pattern/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,12 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
[babelHelpers.classPrivateFieldLooseBase(this, _client)[_client]] = props; | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
17 changes: 17 additions & 0 deletions
17
...posal-class-properties/test/fixtures/private-loose/destructuring-object-pattern-1/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,17 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
this.#client = 'foo'; | ||
;({ x: this.x = this.#client, y: this.#client, z: this.z = this.#client } = props) | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo({ y: 'bar' }); | ||
expect(foo.getClient()).toBe('bar'); | ||
expect(foo.x).toBe('foo'); | ||
expect(foo.z).toBe('bar'); |
8 changes: 8 additions & 0 deletions
8
...osal-class-properties/test/fixtures/private-loose/destructuring-object-pattern-1/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,8 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
this.#client = 'foo'; | ||
({ x: this.x = this.#client, y: this.#client, z: this.z = this.#client } = props) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...sal-class-properties/test/fixtures/private-loose/destructuring-object-pattern-1/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,17 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
babelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = 'foo'; | ||
({ | ||
x: this.x = babelHelpers.classPrivateFieldLooseBase(this, _client)[_client], | ||
y: babelHelpers.classPrivateFieldLooseBase(this, _client)[_client], | ||
z: this.z = babelHelpers.classPrivateFieldLooseBase(this, _client)[_client] | ||
} = props); | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
15 changes: 15 additions & 0 deletions
15
...-class-properties/test/fixtures/private-loose/destructuring-object-pattern-2-exec/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,15 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
let x; | ||
;({ x, ...this.#client } = props) | ||
} | ||
|
||
getClient() { | ||
return this.#client; | ||
} | ||
} | ||
|
||
const foo = new Foo({ x: 'foo', y: 'bar', z: 'baz' }); | ||
expect(foo.getClient()).toEqual({ y: 'bar', z: 'baz' }); |
15 changes: 15 additions & 0 deletions
15
...s-properties/test/fixtures/private-loose/destructuring-object-pattern-2-exec/options.json
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 @@ | ||
{ | ||
"plugins": [ | ||
"transform-destructuring", | ||
[ | ||
"external-helpers", | ||
{ | ||
"helperVersion": "7.4.4" | ||
} | ||
], | ||
"proposal-class-properties", | ||
"transform-classes", | ||
"transform-block-scoping", | ||
"syntax-class-properties" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
...osal-class-properties/test/fixtures/private-loose/destructuring-object-pattern-2/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,7 @@ | ||
class Foo { | ||
#client | ||
|
||
constructor(props) { | ||
({ x, ...this.#client } = props) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...sal-class-properties/test/fixtures/private-loose/destructuring-object-pattern-2/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,15 @@ | ||
var Foo = function Foo(props) { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _client, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
({ | ||
x, | ||
...babelHelpers.classPrivateFieldLooseBase(this, _client)[_client] | ||
} = props); | ||
}; | ||
|
||
var _client = babelHelpers.classPrivateFieldLooseKey("client"); |
Oops, something went wrong.