Skip to content

Commit f04df70

Browse files
committed
[#73] Account for SpreadElement AST Nodes
1 parent 525da04 commit f04df70

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

__tests__/src/getPropValue-test.js

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

809809
assert.deepEqual(expected, actual);
810810
});
811+
812+
it('should evaluate to a correct representation of an array with spread elements', () => {
813+
const prop = extractProp('<div foo={[...this.props.params, bar]} />');
814+
815+
const expected = [undefined, 'bar'];
816+
const actual = getPropValue(prop);
817+
818+
assert.deepEqual(expected, actual);
819+
});
811820
});
812821

813822
it('should return an empty array provided an empty array in props', () => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Extractor function for a SpreadElement type value node.
3+
* We can't statically evaluate an array spread, so just return
4+
* undefined.
5+
*
6+
* @param - value - AST Value object with type `SpreadElement`
7+
* @returns - An prototypeless object.
8+
*/
9+
export default function extractValueFromSpreadElement() {
10+
return undefined;
11+
}

src/values/expressions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import NewExpression from './NewExpression';
1616
import UpdateExpression from './UpdateExpression';
1717
import ArrayExpression from './ArrayExpression';
1818
import BindExpression from './BindExpression';
19+
import SpreadElement from './SpreadElement';
1920

2021
// Composition map of types to their extractor functions.
2122
const TYPES = {
@@ -38,6 +39,7 @@ const TYPES = {
3839
UpdateExpression,
3940
ArrayExpression,
4041
BindExpression,
42+
SpreadElement,
4143
};
4244

4345
const noop = () => null;
@@ -79,6 +81,7 @@ const LITERAL_TYPES = Object.assign({}, TYPES, {
7981
return extractedVal.filter(val => val !== null);
8082
},
8183
BindExpression: noop,
84+
SpreadElement: noop,
8285
});
8386

8487
const errorMessage = expression =>

0 commit comments

Comments
 (0)