Skip to content

Commit

Permalink
[#73] Account for SpreadElement AST Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebeach committed Mar 17, 2019
1 parent 525da04 commit f04df70
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions __tests__/src/getPropValue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,15 @@ describe('getPropValue', () => {

assert.deepEqual(expected, actual);
});

it('should evaluate to a correct representation of an array with spread elements', () => {
const prop = extractProp('<div foo={[...this.props.params, bar]} />');

const expected = [undefined, 'bar'];
const actual = getPropValue(prop);

assert.deepEqual(expected, actual);
});
});

it('should return an empty array provided an empty array in props', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/values/expressions/SpreadElement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Extractor function for a SpreadElement type value node.
* We can't statically evaluate an array spread, so just return
* undefined.
*
* @param - value - AST Value object with type `SpreadElement`
* @returns - An prototypeless object.
*/
export default function extractValueFromSpreadElement() {
return undefined;
}
3 changes: 3 additions & 0 deletions src/values/expressions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import NewExpression from './NewExpression';
import UpdateExpression from './UpdateExpression';
import ArrayExpression from './ArrayExpression';
import BindExpression from './BindExpression';
import SpreadElement from './SpreadElement';

// Composition map of types to their extractor functions.
const TYPES = {
Expand All @@ -38,6 +39,7 @@ const TYPES = {
UpdateExpression,
ArrayExpression,
BindExpression,
SpreadElement,
};

const noop = () => null;
Expand Down Expand Up @@ -79,6 +81,7 @@ const LITERAL_TYPES = Object.assign({}, TYPES, {
return extractedVal.filter(val => val !== null);
},
BindExpression: noop,
SpreadElement: noop,
});

const errorMessage = expression =>
Expand Down

0 comments on commit f04df70

Please sign in to comment.