Skip JSX tagging for export statements with source (#5057)

This commit is contained in:
Bjorn Lu 2022-10-12 20:25:54 +08:00 committed by GitHub
parent 8d2d0c3c03
commit baf88ee9e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Skip JSX tagging for export statements with source

View file

@ -104,7 +104,7 @@ export default function tagExportsWithRenderer({
addTag(property.key.name); addTag(property.key.name);
} }
}); });
} else if (t.isExportNamedDeclaration(node)) { } else if (t.isExportNamedDeclaration(node) && !node.source) {
node.specifiers.forEach((specifier) => { node.specifiers.forEach((specifier) => {
if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) { if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) {
addTag(specifier.local.name); addTag(specifier.local.name);

View file

@ -1,5 +1,7 @@
import { useState } from "react" import { useState } from "react"
export { ListExportTestComponent } from './ListExportTestComponent'
const ListExport = () => { const ListExport = () => {
const [example] = useState('Example') const [example] = useState('Example')
return <h2 id="default_list_export">{example}</h2> return <h2 id="default_list_export">{example}</h2>

View file

@ -0,0 +1,6 @@
import { useState } from "react"
export const ListExportTestComponent = () => {
const [example] = useState('Example')
return <h2 id="list_export_test_component">{example}</h2>
}

View file

@ -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 {ConstDeclarationExport, LetDeclarationExport, FunctionDeclarationExport} from '../components/DeclarationExportTest'
import AnonymousArrowDefaultExport from '../components/defaultExport/AnonymousArrowDefaultExport' import AnonymousArrowDefaultExport from '../components/defaultExport/AnonymousArrowDefaultExport'
import AnonymousFunctionDefaultExport from '../components/defaultExport/AnonymousFunctionDefaultExport' import AnonymousFunctionDefaultExport from '../components/defaultExport/AnonymousFunctionDefaultExport'
@ -12,6 +12,7 @@ import NamedFunctionDefaultExport from '../components/defaultExport/NamedFunctio
<ListAsDefaultExport /> <ListAsDefaultExport />
<ListExport /> <ListExport />
<RenamedListExport /> <RenamedListExport />
<ListExportTestComponent />
<ConstDeclarationExport /> <ConstDeclarationExport />
<LetDeclarationExport /> <LetDeclarationExport />

View file

@ -17,6 +17,7 @@ describe('react-jsx-export', () => {
'default_list_export', 'default_list_export',
'renamed_list_export', 'renamed_list_export',
'list_as_default_export', 'list_as_default_export',
'list_export_test_component',
]; ];
const reactInvalidHookWarning = const reactInvalidHookWarning =