Skip to content

Commit

Permalink
Skip JSX tagging for export statements with source (#5057)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 12, 2022
1 parent 8d2d0c3 commit baf88ee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-icons-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Skip JSX tagging for export statements with source
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-jsx/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from "react"

export { ListExportTestComponent } from './ListExportTestComponent'

const ListExport = () => {
const [example] = useState('Example')
return <h2 id="default_list_export">{example}</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useState } from "react"

export const ListExportTestComponent = () => {
const [example] = useState('Example')
return <h2 id="list_export_test_component">{example}</h2>
}
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,6 +12,7 @@ import NamedFunctionDefaultExport from '../components/defaultExport/NamedFunctio
<ListAsDefaultExport />
<ListExport />
<RenamedListExport />
<ListExportTestComponent />

<ConstDeclarationExport />
<LetDeclarationExport />
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/react-jsx-export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('react-jsx-export', () => {
'default_list_export',
'renamed_list_export',
'list_as_default_export',
'list_export_test_component',
];

const reactInvalidHookWarning =
Expand Down

0 comments on commit baf88ee

Please sign in to comment.