Skip to content

Commit a5b9461

Browse files
committed
Adding support for objectRestSpread within props
1 parent e4c0312 commit a5b9461

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

__tests__/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const parser = require('babylon');
44

55
function parse(code) {
66
return parser.parse(code, {
7-
plugins: ['jsx', 'functionBind', 'estree'],
7+
plugins: ['jsx', 'functionBind', 'estree', 'objectRestSpread'],
88
});
99
}
1010

__tests__/src/getPropValue-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ describe('getPropValue', () => {
768768

769769
assert.deepEqual(expected, actual);
770770
});
771+
772+
it('should evaluate to a correct representation of the object, ignore spread properties', () => {
773+
const prop = extractProp('<div foo={{bar: "baz", ...{baz: "bar", foo: {...{bar: "meh"}}}}} />');
774+
775+
const expected = { bar: 'baz', baz: 'bar', foo: { bar: 'meh' } };
776+
const actual = getPropValue(prop);
777+
778+
assert.deepEqual(expected, actual);
779+
});
771780
});
772781

773782
describe('New expression', () => {

src/values/expressions/ObjectExpression.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import getValue from './index';
99
export default function extractValueFromObjectExpression(value) {
1010
return value.properties.reduce((obj, property) => {
1111
const object = Object.assign({}, obj);
12-
object[getValue(property.key)] = getValue(property.value);
12+
if (property.type === 'SpreadProperty') {
13+
if (property.argument.type === 'ObjectExpression') {
14+
return Object.assign(object, extractValueFromObjectExpression(property.argument));
15+
}
16+
} else {
17+
object[getValue(property.key)] = getValue(property.value);
18+
}
1319
return object;
1420
}, {});
1521
}

0 commit comments

Comments
 (0)