import { Project } from "ts-morph";
const data = `
import MyClass from 'MyClass';
export default function MyJsComponent(props){
return (
<MyClass>{props.name}</MyClass>
);
};
function MyOtherComponent(props){
return (
<OtherComponent>{props.name}</OtherComponent>
);
};
`;
const project = new Project({
useInMemoryFileSystem: true,
compilerOptions: {
jsx: ts.JsxEmit.ReactJSX
}
});
const sourceFile = project.createSourceFile("/test.jsx", data);
expect(sourceFile.getImportStringLiterals().map(literal => literal.getLiteralValue())).toEqual(['MyClass']); //fails
expect(sourceFile.getEmitOutput().getOutputFiles()?.[0]?.getText?.() || '').to.not.equal(''); //fails
Expected behavior
I expect the first expect to return the valid imports. I expect the second expect to have the jsx compiled. The above works if I change the extension to tsx, but that messes up imports in a more full example (i have some imports by filename)
Describe the bug
ts-morph doesnt properly handle js/jsx files
Version: 23.0.0
To Reproduce
Expected behavior
I expect the first expect to return the valid imports. I expect the second expect to have the jsx compiled. The above works if I change the extension to tsx, but that messes up imports in a more full example (i have some imports by filename)