moroshko / react-scanner

Extract React components and props usage from code.
MIT License
563 stars 40 forks source link

Scanner does not find "default as" imports #39

Closed drewbrend closed 3 years ago

drewbrend commented 3 years ago

I am trying to switch from an old in-house built solution to react-scanner and found one case that ours worked with but react-scanner does not. We have some instances of this import syntax that get missed:

import { default as Header } from "my-design-system";

Here is a test that shows the issue, just add it to src/scan.test.js:


Scan("importedFrom default export as", ({ getReport }) => {
  const report = getReport(
    "imported-from-default-export.js",
    `
    import { default as Header } from "my-design-system";
    import Box from "other-module";

    <Box>
      <Header />
    </Box>
  `,
    { importedFrom: /my-design-system/ }
  );

  assert.equal(report, {
    Header: {
      instances: [
        {
          importInfo: {
            local: "Header",
            moduleName: "my-design-system",
            importType: "ImportDefaultSpecifier",
          },
          props: {},
          propsSpread: false,
          location: {
            file: "imported-from-default-export.js",
            start: {
              line: 6,
              column: 7,
            },
          },
        },
      ],
    },
  });
});