Skip to content
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

Account for SequenceExpression in the utils #101

Merged
merged 1 commit into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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