Skip to content

Commit

Permalink
chore: do a case insensitive match on import path when checking if im…
Browse files Browse the repository at this point in the history
…port exists
  • Loading branch information
jerelmiller committed Feb 11, 2021
1 parent af39030 commit b00e189
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions codemods/utils/mdxast.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,30 @@ const findChild = (node, test) => {
return node.children.find((child, idx) => matches(child, idx, node));
};

const containsImport = (tree, node) =>
tree.children.some(
(child) => child.type === 'import' && child.value === node.value
);
const parseImport = (node) => {
const match = node.value.match(/import (\w+?) from ['"](.*?)['"]/);

return match ? { expression: match[1], path: match[2] } : null;
};

const containsImport = (tree, node) => {
return tree.children.some((child) => {
if (child.type !== 'import') {
return false;
}

if (child.value === node.value) {
return true;
}

const childImport = parseImport(child);
const nodeImport = parseImport(node);

// Git/macOS are case insensitive so `./images/Debian.png` is the same as
// `./images/debian.png.`
return childImport.path.toLowerCase() === nodeImport.path.toLowerCase();
});
};

module.exports = {
addAttribute,
Expand Down

0 comments on commit b00e189

Please sign in to comment.