diff --git a/changelog.md b/changelog.md index c3760a6..201051f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # find-unused-exports changelog +## Next + +### Minor + +- Enable JSX syntax when parsing `.jsx` files with Babel, even when the project has no Babel config for JSX, via [#8](https://github.com/jaydenseric/find-unused-exports/pull/8). + ## 6.0.0 ### Major diff --git a/scanModuleCode.mjs b/scanModuleCode.mjs index 06a0d7b..977e48f 100644 --- a/scanModuleCode.mjs +++ b/scanModuleCode.mjs @@ -52,20 +52,19 @@ export default async function scanModuleCode(code, path) { ["decorators", { decoratorsBeforeExport: false }], ]; - if ( - path && + if (path) { // Path is a TypeScript module. - (path.endsWith(".mts") || + if ( + path.endsWith(".mts") || path.endsWith(".cts") || path.endsWith(".ts") || - path.endsWith(".tsx")) - ) { - // Allow parsing code containing TypeScript syntax. - plugins.push("typescript"); - - if (path.endsWith(".tsx")) - // Allow parsing code containing JSX syntax. - plugins.push("jsx"); + path.endsWith(".tsx") + ) + // Allow parsing code containing TypeScript syntax. + plugins.push("typescript"); + + // Allow parsing code containing JSX syntax. + if (path.endsWith(".tsx") || path.endsWith(".jsx")) plugins.push("jsx"); } const ast = await babel.parseAsync(code, { diff --git a/scanModuleCode.test.mjs b/scanModuleCode.test.mjs index 6cd8be2..373bbd5 100644 --- a/scanModuleCode.test.mjs +++ b/scanModuleCode.test.mjs @@ -58,6 +58,13 @@ describe("Function `scanModuleCode`.", { concurrency: true }, () => { }, ); }); + + it("`.jsx` file, JavaScript and JSX syntax.", async () => { + deepStrictEqual(await scanModuleCode("const a =
;", "a.jsx"), { + imports: {}, + exports: new Set(), + }); + }); }); it("No imports or exports.", async () => {