Skip to content
New issue

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

export * doesn't work for deeply nested exports #109

Open
FredericEspiau opened this issue Dec 16, 2024 · 3 comments · May be fixed by #111
Open

export * doesn't work for deeply nested exports #109

FredericEspiau opened this issue Dec 16, 2024 · 3 comments · May be fixed by #111
Labels
bug Something isn't working

Comments

@FredericEspiau
Copy link
Contributor

Hey and thanks for all the hard work ! 💪

I have an issue where deeply nested * exports won't work

For example:

// app/main.ts
import { c } from './a';
// app/a/index.ts
export * from './b';
// app/a/b/index.ts
export * from './c';
// app/a/b/c/index.ts
export c = 'c';

I think this is due to this part:

tsr/lib/util/edit.ts

Lines 439 to 440 in 50b9261

const exported = parsed.exports.flatMap((v) =>
'name' in v ? v.name : [],

You look for names matching the export but only one level deep, so if c were in app/a/b/index.ts it would work, but it doesn't work for app/a/b/c/index.ts

@kazushisan kazushisan added the bug Something isn't working label Dec 17, 2024
@kazushisan
Copy link
Contributor

Thank you! If you're interested in working on a patch, please let me know!

@FredericEspiau
Copy link
Contributor Author

I'll give it a try if you an give me a few instructions to help me get started :)

@kazushisan
Copy link
Contributor

kazushisan commented Dec 17, 2024

Sure! Thanks for taking your time.

I think your assumption is correct. I'd say a possible solution is to extract the following logic into a separate function and recursively process the result until there's no { type: 'whole' } in the array.

tsr/lib/util/edit.ts

Lines 432 to 441 in 6ed047a

const parsed = parseFile({
file: item.file,
content: files.get(item.file) || '',
options,
destFiles: fileNames,
});
const exported = parsed.exports.flatMap((v) =>
'name' in v ? v.name : [],
);

image

@FredericEspiau FredericEspiau linked a pull request Dec 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants