From d3c2bbb756d92cacb5522ec091cba018a6f170ca Mon Sep 17 00:00:00 2001 From: Colby McHenry Date: Fri, 9 Oct 2026 22:23:04 -0500 Subject: [PATCH] fix(react,vue): a tag imported from a package renders no project namesake A JSX tag the file imports from a package (antd's ` + + ); +} +` + ); + await index(); + expect(renders('Settings')).toEqual([]); + }); + + it('renders nothing for a default import from a package subpath, or a package import under another name', async () => { + // mantis/berry: `import Typography from '@mui/material/Typography'` beside + // the theme's own `Typography` override; a router link renamed on import. + write( + 'package.json', + JSON.stringify({ dependencies: { react: '^18.0.0', '@mui/material': '^5.0.0', 'react-router-dom': '^6.0.0' } }) + ); + write( + 'src/themes/overrides/Typography.js', + 'export default function Typography(theme) {\n return { MuiTypography: { styleOverrides: {} } };\n}\n' + ); + write('src/components/RouterLink.tsx', 'export function RouterLink() {\n return ;\n}\n'); + write( + 'src/pages/Login.tsx', + `import Typography from '@mui/material/Typography'; +import { Link as RouterLink } from 'react-router-dom'; + +export function Login() { + return ( + + Sign up + + ); +} +` + ); + await index(); + expect(renders('Login')).toEqual([]); + }); + + it('keeps a tag imported through an alias that reads like a package, or through a bare specifier no package.json declares', async () => { + write('package.json', JSON.stringify({ dependencies: { react: '^18.0.0', antd: '^5.0.0' } })); + write( + 'tsconfig.json', + JSON.stringify({ compilerOptions: { baseUrl: '.', paths: { 'components/*': ['src/components/*'] } } }) + ); + write('src/components/Modal/index.tsx', 'export default function Modal() {\n return
;\n}\n'); + write('src/layouts/Header.tsx', 'export default function Header() {\n return
;\n}\n'); + write( + 'src/container/Alerts.tsx', + `import Modal from 'components/Modal'; + +export function Alerts() { + return ; +} +` + ); + write( + 'src/container/Confirm.tsx', + `import { Modal } from 'antd'; + +export function Confirm() { + return ; +} +` + ); + // No alias maps `layouts/*` and no package.json declares `layouts`: the + // resolver can't follow it, which does not make it a package. + write( + 'src/App.tsx', + `import Header from 'layouts/Header'; + +export function App() { + return
; +} +` + ); + await index(); + expect(renders('Alerts')).toEqual(['Modal src/components/Modal/index.tsx:1']); + expect(renders('Confirm')).toEqual([]); + expect(renders('App')).toEqual(['Header src/layouts/Header.tsx:1']); + }); + + it('keeps a tag imported from a workspace package of the repository', async () => { + write('package.json', JSON.stringify({ private: true, workspaces: ['packages/*', 'apps/*'] })); + write('packages/ui/package.json', JSON.stringify({ name: '@acme/ui', version: '1.0.0' })); + write('packages/ui/index.tsx', 'export function Button() {\n return