From 9546e53481270cc39d3688ca119311e373fe9607 Mon Sep 17 00:00:00 2001 From: rinter17 Date: Wed, 26 Aug 2020 20:42:59 -0500 Subject: [PATCH] [New] add `SequenceExpression` Fixes #95. --- __tests__/src/getPropValue-flowparser-test.js | 15 +++++++++++++++ src/values/expressions/SequenceExpression.js | 13 +++++++++++++ src/values/expressions/index.js | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 src/values/expressions/SequenceExpression.js diff --git a/__tests__/src/getPropValue-flowparser-test.js b/__tests__/src/getPropValue-flowparser-test.js index 81ae7f2..4c9a8d5 100644 --- a/__tests__/src/getPropValue-flowparser-test.js +++ b/__tests__/src/getPropValue-flowparser-test.js @@ -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('
'); + + 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('
'); diff --git a/src/values/expressions/SequenceExpression.js b/src/values/expressions/SequenceExpression.js new file mode 100644 index 0000000..129d992 --- /dev/null +++ b/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)); +} diff --git a/src/values/expressions/index.js b/src/values/expressions/index.js index fe255ee..ba3c954 100644 --- a/src/values/expressions/index.js +++ b/src/values/expressions/index.js @@ -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 = { @@ -48,6 +49,7 @@ const TYPES = { BindExpression, SpreadElement, TypeCastExpression, + SequenceExpression, }; const noop = () => null; @@ -138,6 +140,7 @@ const LITERAL_TYPES = { TSNonNullExpression: noop, TSAsExpression: noop, TypeCastExpression: noop, + SequenceExpression: noop, }; /**