From fcdfcc77a6af8d0ee8019bb31aa491354fea82d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 18 May 2020 23:47:24 +0200 Subject: [PATCH] revert: Revert all changes --- __tests__/src/getProp-parser-test.js | 39 +++------------------------- src/getProp.js | 25 +++++++----------- 2 files changed, 13 insertions(+), 51 deletions(-) diff --git a/__tests__/src/getProp-parser-test.js b/__tests__/src/getProp-parser-test.js index 8c1d623..fc2339b 100644 --- a/__tests__/src/getProp-parser-test.js +++ b/__tests__/src/getProp-parser-test.js @@ -61,7 +61,7 @@ function actualTest(parserName, test) { assert.deepStrictEqual( adjustLocations(sourceResult, offset), - stripStartAndEnd(targetResult), + targetResult, ); } @@ -69,41 +69,6 @@ function stripConstructors(value) { return JSON.parse(JSON.stringify(value)); } -function stripStartAndEnd({ name, value: { expression, ...value }, ...node }) { - return { - ...stripNodeStartAndEnd(node), - name: stripNodeStartAndEnd(name), - value: { - ...stripNodeStartAndEnd(value), - ...(expression - ? { expression: stripNodeStartAndEndRecursively(expression) } - : {} - ), - }, - }; -} - -function stripNodeStartAndEnd(node) { - if (!node.loc) { - return node; - } - - const { start, end, ...nodeWithoutStartAndEnd } = node; - return nodeWithoutStartAndEnd; -} - -function stripNodeStartAndEndRecursively(node) { - if (Array.isArray(node)) { - return node.map(stripNodeStartAndEndRecursively); - } - - if (Boolean(node) && typeof node === 'object') { - return stripNodeStartAndEnd(mapValues(node, stripNodeStartAndEndRecursively)); - } - - return node; -} - function adjustLocations(node, { keyOffset, valueOffset }) { const hasExpression = !!node.value.expression; return { @@ -135,6 +100,8 @@ function adjustNodeLocations(node, { startOffset, endOffset }) { const [start, end] = node.range || []; return { ...node, + ...(node.start !== undefined ? { start: node.start + startOffset } : {}), + ...(node.end !== undefined ? { end: node.end + endOffset } : {}), loc: { ...node.loc, start: { diff --git a/src/getProp.js b/src/getProp.js index e254dbc..b34f635 100644 --- a/src/getProp.js +++ b/src/getProp.js @@ -42,27 +42,22 @@ function propertyToJSXAttribute(node) { type: 'JSXAttribute', name: { type: 'JSXIdentifier', name: key.name, ...getBaseProps(key) }, value: value.type === 'Literal' - ? stripStartAndEndFromValue(value) - : { type: 'JSXExpressionContainer', expression: stripExpressionStartAndEnd(value), ...getBaseProps(value) }, + ? value + : { type: 'JSXExpressionContainer', expression: value, ...getBaseProps(value) }, ...getBaseProps(node), }; } -function stripStartAndEndFromValue({ end, start, ...value }) { - return value; -} - -function stripExpressionStartAndEnd({ expressions, quasis, ...expression }) { - return { - ...stripStartAndEndFromValue(expression), - ...(expressions ? { expressions: expressions.map(stripStartAndEndFromValue) } : {}), - ...(quasis ? { quasis: quasis.map(stripStartAndEndFromValue) } : {}), - }; -} - -function getBaseProps({ loc, range }) { +function getBaseProps({ + start, + end, + loc, + range, +}) { return { loc: getBaseLocation(loc), + ...(start !== undefined ? { start } : {}), + ...(end !== undefined ? { end } : {}), ...(range !== undefined ? { range } : {}), }; }