Skip to content

Commit

Permalink
revert: Revert all changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed May 25, 2020
1 parent 34b99ee commit fcdfcc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
39 changes: 3 additions & 36 deletions __tests__/src/getProp-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,14 @@ function actualTest(parserName, test) {

assert.deepStrictEqual(
adjustLocations(sourceResult, offset),
stripStartAndEnd(targetResult),
targetResult,
);
}

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 {
Expand Down Expand Up @@ -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: {
Expand Down
25 changes: 10 additions & 15 deletions src/getProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } : {}),
};
}
Expand Down

0 comments on commit fcdfcc7

Please sign in to comment.