Skip to content

Commit

Permalink
Target opening element for removeJSXAttribute utility
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-b-rose committed Sep 13, 2023
1 parent fefebab commit 0889381
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type {API, FileInfo, Options} from 'jscodeshift';
import type {
API,
FileInfo,
Options,
ArrayExpression,
ASTPath,
} from 'jscodeshift';

import {POLARIS_MIGRATOR_COMMENT} from '../../utilities/constants';
import {
Expand Down Expand Up @@ -69,15 +75,12 @@ export default function transformer(
return true;
})
.find(j.ArrayExpression)
.replaceWith((nodePath) => {
.replaceWith((nodePath: ASTPath<ArrayExpression>) => {
const arrayOfBreadcrumbs = nodePath.node.elements;

if (arrayOfBreadcrumbs.length === 0) {
removeJSXAttributes(
j,
nodePath.parentPath.parentPath.parentPath.parentPath,
'breadcrumbs',
);
const element = j(nodePath).closest(j.JSXElement).paths()[0];
removeJSXAttributes(j, element, 'breadcrumbs');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion polaris-migrator/src/utilities/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function removeJSXAttributes(
element: ASTPath<JSXElement>,
attributeName: string,
) {
const jsxAttributes = element.value.attributes?.filter(
const jsxAttributes = element.value.openingElement?.attributes?.filter(
(attr) => attr.type === 'JSXAttribute' && attr.name.name === attributeName,
);

Expand Down

0 comments on commit 0889381

Please sign in to comment.