moroshko/react-scanner

Does not find component instances that are in JSX props of components imported from elsewhere

mihkeleidast opened this issue · 0 comments

Came across an edgecase, where if a component imported from the specified library is used as JSX inside of a prop of another component that is imported from elsewhere, it is not counted as a used instance.

Failing test (note that the expected report might not be 100% accurate, but it currently fails with "Actual: {}", which is definitely not correct):

Scan("props with jsx expressions", ({ getReport }) => {
  const report = getReport(
    "imported-from-in-prop-jsx.js",

    `
    import { Text } from "other-place";
    import { Box } from "basis";

    <Text foo={<Box foo={bar} />} />`,
    { importedFrom: "basis" }
  );

  assert.equal(report, {
    Box: {
      instances: [
        {
          props: {
            foo: "(JSXElement)",
          },
          propsSpread: false,
          location: {
            file: "imported-from-in-prop-jsx.js",
            start: {
              line: 4,
              column: 5,
            },
          },
        },
      ],
    },
  });
});