Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed computed keys for class expression (#10029)
* test case for insertBefore for jsx * fix unshiftContainer and insertBefore * use path.scope.push * add test making sure computedKeys var declaration at the right block * add comment * nit [skip ci]
- Loading branch information
1 parent
a596da2
commit b4c9cb0
Showing
21 changed files
with
185 additions
and
50 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
27 changes: 11 additions & 16 deletions
27
...ages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/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
4 changes: 3 additions & 1 deletion
4
...l-plugin-proposal-class-properties/test/fixtures/public-loose/instance-computed/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,5 +1,7 @@ | ||
function test(x) { | ||
var _x = x; | ||
var _x; | ||
|
||
_x = x; | ||
|
||
var F = function F() { | ||
"use strict"; | ||
|
5 changes: 5 additions & 0 deletions
5
...abel-plugin-proposal-class-properties/test/fixtures/public/computed-without-block/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,5 @@ | ||
const createClass = (k) => class { [k()] = 2 }; | ||
|
||
const clazz = createClass(() => 'foo'); | ||
const instance = new clazz(); | ||
expect(instance.foo).toBe(2); |
1 change: 1 addition & 0 deletions
1
...bel-plugin-proposal-class-properties/test/fixtures/public/computed-without-block/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 @@ | ||
const createClass = (k) => class { [k()] = 2 }; |
18 changes: 18 additions & 0 deletions
18
...el-plugin-proposal-class-properties/test/fixtures/public/computed-without-block/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,18 @@ | ||
var createClass = k => { | ||
var _temp; | ||
|
||
var _k; | ||
|
||
return _temp = (_k = k(), | ||
/*#__PURE__*/ | ||
function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
babelHelpers.defineProperty(this, _k, 2); | ||
} | ||
|
||
return _class2; | ||
}()), _temp; | ||
}; |
27 changes: 11 additions & 16 deletions
27
packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/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
4 changes: 3 additions & 1 deletion
4
...s/babel-plugin-proposal-class-properties/test/fixtures/public/instance-computed/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,5 +1,7 @@ | ||
function test(x) { | ||
var _x = x; | ||
var _x; | ||
|
||
_x = x; | ||
|
||
var F = function F() { | ||
"use strict"; | ||
|
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
23 changes: 23 additions & 0 deletions
23
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/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,23 @@ | ||
const classes = []; | ||
for (let i = 0; i <= 10; ++i) { | ||
classes.push( | ||
class A { | ||
[i] = `computed field ${i}`; | ||
static foo = `static field ${i}`; | ||
#bar = `private field ${i}`; | ||
getBar() { | ||
return this.#bar; | ||
} | ||
} | ||
); | ||
} | ||
|
||
for(let i=0; i<= 10; ++i) { | ||
const clazz = classes[i]; | ||
expect(clazz.foo).toBe('static field ' + i); | ||
|
||
const instance = new clazz(); | ||
expect(Object.getOwnPropertyNames(instance)).toEqual([String(i)]) | ||
expect(instance[i]).toBe('computed field ' + i); | ||
expect(instance.getBar()).toBe('private field ' + i); | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/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,13 @@ | ||
const classes = []; | ||
for (let i = 0; i <= 10; ++i) { | ||
classes.push( | ||
class A { | ||
[i] = `computed field ${i}`; | ||
static foo = `static field ${i}`; | ||
#bar = `private field ${i}`; | ||
getBar() { | ||
return this.#bar; | ||
} | ||
} | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/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 @@ | ||
{ | ||
"plugins": ["external-helpers", "proposal-class-properties"] | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/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,23 @@ | ||
const classes = []; | ||
|
||
for (let i = 0; i <= 10; ++i) { | ||
var _class, _temp, _bar; | ||
|
||
let _i; | ||
|
||
classes.push((_temp = (_i = i, _class = class A { | ||
constructor() { | ||
babelHelpers.defineProperty(this, _i, `computed field ${i}`); | ||
|
||
_bar.set(this, { | ||
writable: true, | ||
value: `private field ${i}` | ||
}); | ||
} | ||
|
||
getBar() { | ||
return babelHelpers.classPrivateFieldGet(this, _bar); | ||
} | ||
|
||
}), _bar = new WeakMap(), babelHelpers.defineProperty(_class, "foo", `static field ${i}`), _temp)); | ||
} |
4 changes: 3 additions & 1 deletion
4
...n-proposal-class-properties/test/fixtures/static-property-tdz/decorator-interop/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
4 changes: 3 additions & 1 deletion
4
...-plugin-proposal-class-properties/test/fixtures/static-property-tdz/edgest-case/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
4 changes: 3 additions & 1 deletion
4
...abel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/general/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
4 changes: 3 additions & 1 deletion
4
.../babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/loose/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
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