Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix evaluation order with object spread (#11412)
* Fix object spread runtime semantics * limit this deoptimization * optimize empty objects * declare variables
- Loading branch information
Showing
12 changed files
with
144 additions
and
1 deletion.
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
4 changes: 4 additions & 0 deletions
4
.../babel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/assignment/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,3 +1,7 @@ | ||
var x; | ||
var y; | ||
var z; | ||
|
||
z = { x, ...y }; | ||
|
||
z = { x, w: { ...y } }; |
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
7 changes: 7 additions & 0 deletions
7
.../babel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/expression/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,3 +1,10 @@ | ||
var a; | ||
var b; | ||
var c; | ||
var d; | ||
var x; | ||
var y; | ||
|
||
({ x, ...y, a, ...b, c }); | ||
|
||
({ ...Object.prototype }); | ||
|
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: 4 additions & 0 deletions
4
...ugin-proposal-object-rest-spread/test/fixtures/object-spread/loose-mode-builtins/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,3 +1,7 @@ | ||
var x; | ||
var y; | ||
var z; | ||
|
||
z = { x, ...y }; | ||
|
||
z = { x, w: { ...y } }; |
3 changes: 3 additions & 0 deletions
3
...gin-proposal-object-rest-spread/test/fixtures/object-spread/loose-mode-builtins/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,3 +1,6 @@ | ||
var x; | ||
var y; | ||
var z; | ||
z = Object.assign({ | ||
x | ||
}, y); | ||
|
4 changes: 4 additions & 0 deletions
4
.../babel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/loose-mode/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,3 +1,7 @@ | ||
var x; | ||
var y; | ||
var z; | ||
|
||
z = { x, ...y }; | ||
|
||
z = { x, w: { ...y } }; | ||
|
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: 4 additions & 0 deletions
4
.../babel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/side-effect/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,4 @@ | ||
var k = { a: 1, b: 2 }; | ||
var o = { a: 3, ...k, b: k.a++ }; | ||
|
||
expect(o).toEqual({a: 1, b: 1}); |
16 changes: 16 additions & 0 deletions
16
...babel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/side-effect/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,16 @@ | ||
var k = { a: 1, b: 2 }; | ||
var o = { a: 3, ...k, b: k.a++ }; | ||
|
||
var pureA = {}; | ||
var pureB = {}; | ||
var pureC = {}; | ||
var pureD = {}; | ||
var pureE = {}; | ||
|
||
function impureFunc() { | ||
console.log('hello') | ||
} | ||
|
||
var output = { ...pureA, get foo() {}, get bar() {}, ...pureB, ...pureC, ...impureFunc(), ...pureD, pureD } | ||
|
||
var simpleOutput = { ...pureA, test: '1', ...pureB, } |
39 changes: 39 additions & 0 deletions
39
...abel-plugin-proposal-object-rest-spread/test/fixtures/object-spread/side-effect/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,39 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
|
||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
|
||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
|
||
var k = { | ||
a: 1, | ||
b: 2 | ||
}; | ||
|
||
var o = _objectSpread(_objectSpread({ | ||
a: 3 | ||
}, k), {}, { | ||
b: k.a++ | ||
}); | ||
|
||
var pureA = {}; | ||
var pureB = {}; | ||
var pureC = {}; | ||
var pureD = {}; | ||
var pureE = {}; | ||
|
||
function impureFunc() { | ||
console.log('hello'); | ||
} | ||
|
||
var output = _objectSpread(_objectSpread(_objectSpread({}, pureA), {}, { | ||
get foo() {}, | ||
|
||
get bar() {} | ||
|
||
}, pureB, {}, pureC, {}), impureFunc(), {}, pureD, { | ||
pureD | ||
}); | ||
|
||
var simpleOutput = _objectSpread({}, pureA, { | ||
test: '1' | ||
}, pureB); |