New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix evaluation order with object spread #11412
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
z = Object.assign({ | ||
z = Object.assign(Object.assign({ | ||
x | ||
}, y); | ||
}), y); | ||
z = { | ||
x, | ||
w: Object.assign({}, y) | ||
w: Object.assign(Object.assign({}), y) | ||
}; |
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}); |
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, } |
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 | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this output to be var output = { ...pureA, get foo() {}, get bar() {}, ...pureB, ...pureC, ...impureFunc(), ...pureD, pureD }
var output = _objectSpread(
_objectSpread(
{},
pureA,
{ get foo() {}, get bar() {} },
pureB,
{},
pureC,
{}
),
impureFunc(),
{},
pureD,
{ pureD }
); I think that it's a bug in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙆♂️ I'm gonna give it a try. |
||
|
||
var simpleOutput = _objectSpread({}, pureA, { | ||
test: '1' | ||
}, pureB); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
scope.isPure
is not working as intended. What's the difference betweenscope.isPure
andpath.isPure
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😵 My bad ,
scope.isPure
is working.