We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React.lazy
const resolveDynamicImportPath = (path: string) => resolve(import.meta.dirname!) + path.replace('@src', '/src') + '.tsx' const projectCache = new Project({ useInMemoryFileSystem: true, }) export const getRouteMappings = (resolveDynamicImport: (path: string) => string) => (sourceFile: SourceFile): Record<string, string> => { const nodes = query( sourceFile.getText(), 'Identifier[name=routes] ~ ObjectLiteralExpression > PropertyAssignment' ).flatMap((x) => { const container = query(x, 'Identifier[name=component] ~ Identifier')[0] if (container === undefined) return [] const topDecl = sourceFile.getVariableDeclarationOrThrow(container?.getText()) // HACK: assumes all components are of format React.lazy(() => import('<path>/componentName')) const path = topDecl.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral) const resolvedPath = resolveDynamicImport(path.getLiteralText()) const resolvedText = Deno.readTextFileSync(resolvedPath) const srcfile = projectCache.createSourceFile(resolvedPath, resolvedText) // https://ts-morph.com/details/exports#getting-exported-declarations const uri = encodeVSCodeURI(srcfile.getExportedDeclarations().get('default')![0]) projectCache.removeSourceFile(srcfile) const name = query(x, 'PropertyAccessExpression Identifier[name=Route] ~ Identifier')[0]?.getText() return [[name, uri]] as const }) return Object.fromEntries(nodes) }
The text was updated successfully, but these errors were encountered:
scarf005
No branches or pull requests
Example implementation
The text was updated successfully, but these errors were encountered: