Skip to content

Commit

Permalink
[New] add SequenceExpression
Browse files Browse the repository at this point in the history
Fixes #95.
  • Loading branch information
rinter17 authored and ljharb committed Aug 27, 2020
1 parent 217a0b5 commit 9546e53
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions __tests__/src/getPropValue-flowparser-test.js
Expand Up @@ -828,6 +828,21 @@ describe('getPropValue', () => {
});
});

describe('Sequence array expression', () => {
it('should evaluate to correct representation of the the array in props', () => {
const prop = extractProp('<div foo={[{"type":"Literal","start":821,"end":827}]} />');

const expected = [{
type: 'Literal',
start: 821,
end: 827,
}];
const actual = getPropValue(prop);

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

describe('Array expression', () => {
it('should evaluate to correct representation of the the array in props', () => {
const prop = extractProp('<div foo={["bar", 42, null]} />');
Expand Down
13 changes: 13 additions & 0 deletions src/values/expressions/SequenceExpression.js
@@ -0,0 +1,13 @@
/**
* Extractor function for a SequenceExpression type value node.
* A Sequence expression is an object with an attribute named
* expressions which contains an array of different types
* of expression objects.
*
* @returns - An array of the extracted elements.
*/
export default function extractValueFromSequenceExpression(value) {
// eslint-disable-next-line global-require
const getValue = require('.').default;
return value.expressions.map((element) => getValue(element));
}
3 changes: 3 additions & 0 deletions src/values/expressions/index.js
Expand Up @@ -21,6 +21,7 @@ import ArrayExpression from './ArrayExpression';
import BindExpression from './BindExpression';
import SpreadElement from './SpreadElement';
import TypeCastExpression from './TypeCastExpression';
import SequenceExpression from './SequenceExpression';

// Composition map of types to their extractor functions.
const TYPES = {
Expand Down Expand Up @@ -48,6 +49,7 @@ const TYPES = {
BindExpression,
SpreadElement,
TypeCastExpression,
SequenceExpression,
};

const noop = () => null;
Expand Down Expand Up @@ -138,6 +140,7 @@ const LITERAL_TYPES = {
TSNonNullExpression: noop,
TSAsExpression: noop,
TypeCastExpression: noop,
SequenceExpression: noop,
};

/**
Expand Down

0 comments on commit 9546e53

Please sign in to comment.