From baf88ee9e5e692a94981d7a696fbdcb4cd8ab2a6 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 12 Oct 2022 20:25:54 +0800 Subject: [PATCH] Skip JSX tagging for export statements with source (#5057) --- .changeset/serious-icons-dream.md | 5 +++++ packages/astro/src/vite-plugin-jsx/tag.ts | 2 +- .../react-jsx-export/src/components/ListExportTest.jsx | 2 ++ .../src/components/ListExportTestComponent.jsx | 6 ++++++ .../test/fixtures/react-jsx-export/src/pages/index.astro | 3 ++- packages/astro/test/react-jsx-export.test.js | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/serious-icons-dream.md create mode 100644 packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTestComponent.jsx diff --git a/.changeset/serious-icons-dream.md b/.changeset/serious-icons-dream.md new file mode 100644 index 000000000..968f8a4b4 --- /dev/null +++ b/.changeset/serious-icons-dream.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Skip JSX tagging for export statements with source diff --git a/packages/astro/src/vite-plugin-jsx/tag.ts b/packages/astro/src/vite-plugin-jsx/tag.ts index 23e9e41a5..b6ba7c302 100644 --- a/packages/astro/src/vite-plugin-jsx/tag.ts +++ b/packages/astro/src/vite-plugin-jsx/tag.ts @@ -104,7 +104,7 @@ export default function tagExportsWithRenderer({ addTag(property.key.name); } }); - } else if (t.isExportNamedDeclaration(node)) { + } else if (t.isExportNamedDeclaration(node) && !node.source) { node.specifiers.forEach((specifier) => { if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) { addTag(specifier.local.name); diff --git a/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTest.jsx b/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTest.jsx index e695821d1..812e2648e 100644 --- a/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTest.jsx +++ b/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTest.jsx @@ -1,5 +1,7 @@ import { useState } from "react" +export { ListExportTestComponent } from './ListExportTestComponent' + const ListExport = () => { const [example] = useState('Example') return

{example}

diff --git a/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTestComponent.jsx b/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTestComponent.jsx new file mode 100644 index 000000000..c2b32eb20 --- /dev/null +++ b/packages/astro/test/fixtures/react-jsx-export/src/components/ListExportTestComponent.jsx @@ -0,0 +1,6 @@ +import { useState } from "react" + +export const ListExportTestComponent = () => { + const [example] = useState('Example') + return

{example}

+} diff --git a/packages/astro/test/fixtures/react-jsx-export/src/pages/index.astro b/packages/astro/test/fixtures/react-jsx-export/src/pages/index.astro index 92a3833a4..8414987e3 100644 --- a/packages/astro/test/fixtures/react-jsx-export/src/pages/index.astro +++ b/packages/astro/test/fixtures/react-jsx-export/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import ListAsDefaultExport, {ListExport, RenamedListExport} from '../components/ListExportTest' +import ListAsDefaultExport, {ListExport, RenamedListExport, ListExportTestComponent} from '../components/ListExportTest' import {ConstDeclarationExport, LetDeclarationExport, FunctionDeclarationExport} from '../components/DeclarationExportTest' import AnonymousArrowDefaultExport from '../components/defaultExport/AnonymousArrowDefaultExport' import AnonymousFunctionDefaultExport from '../components/defaultExport/AnonymousFunctionDefaultExport' @@ -12,6 +12,7 @@ import NamedFunctionDefaultExport from '../components/defaultExport/NamedFunctio + diff --git a/packages/astro/test/react-jsx-export.test.js b/packages/astro/test/react-jsx-export.test.js index 4a5b951b2..b43f53c5f 100644 --- a/packages/astro/test/react-jsx-export.test.js +++ b/packages/astro/test/react-jsx-export.test.js @@ -17,6 +17,7 @@ describe('react-jsx-export', () => { 'default_list_export', 'renamed_list_export', 'list_as_default_export', + 'list_export_test_component', ]; const reactInvalidHookWarning =