Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define class elements in the correct order (#12723)
* Define class elements in the correct order * Object.gOPDescriptors is not available on Node.js 6 * Handle numeric keys * Update test * Update fixtures
- Loading branch information
1 parent
20664a4
commit 60ef190
Showing
21 changed files
with
272 additions
and
103 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
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
21 changes: 21 additions & 0 deletions
21
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/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,21 @@ | ||
let x = 1; | ||
|
||
class A { | ||
get [x]() {} | ||
[(x = 3, 2)]() {} | ||
set [x](_) {} | ||
} | ||
|
||
expect(Object.getOwnPropertyDescriptors(A.prototype)).toMatchObject({ | ||
1: { | ||
get: expect.any(Function), | ||
set: undefined, | ||
}, | ||
2: { | ||
value: expect.any(Function), | ||
}, | ||
3: { | ||
get: undefined, | ||
set: expect.any(Function), | ||
} | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/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,5 @@ | ||
class A { | ||
get [x]() {} | ||
[(x = 2, 3)]() {} | ||
set [x](_) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ges/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/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,3 @@ | ||
{ | ||
"minNodeVersion": "8.0.0" | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/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,26 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
|
||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
|
||
let A = /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function A() { | ||
_classCallCheck(this, A); | ||
} | ||
|
||
_createClass(A, [{ | ||
key: x, | ||
get: function () {} | ||
}, { | ||
key: (x = 2, 3), | ||
value: function () {} | ||
}, { | ||
key: x, | ||
set: function (_) {} | ||
}]); | ||
|
||
return A; | ||
}(); |
12 changes: 12 additions & 0 deletions
12
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/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,12 @@ | ||
class A { | ||
get x() {} | ||
x() {} | ||
set x(_) {} | ||
} | ||
|
||
expect(Object.getOwnPropertyDescriptors(A.prototype)).toMatchObject({ | ||
x: { | ||
get: undefined, | ||
set: expect.any(Function), | ||
} | ||
}); |
Oops, something went wrong.