-
Notifications
You must be signed in to change notification settings - Fork 149
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
Preprocessing with Babel makes svelte components imports to be dropped #521
Comments
|
I don't think this is supported. Those flags there are mainly targeting Out of curiosity - have you ever considered appending some dummy runtime expressions to the end of the transformed content that would be stripped away after a transform does its job? That would allow referenced imports to be recognized by Babel/TS and potentially would avoid issues at consumer sites. I know that, especially with Babel, that wouldn't be completely safe (Babel plugins could do some weird things to the injected code) but in most setups this should work quite well.
That would definitely be appreciated.
More flexibility around the actual output. My "library packager" of choice (https://github.com/preconstruct/preconstruct/) only supports Babel right now. I imagine that people might end up with similar problems with other, modern, transpilers though - esbuild, SWC, etc. There is an increasing interest in using TypeScript just for typechecking and not for the actual transpilation of the sources. |
We actually did that for the TypeScript preprocessor in #392. It works, but it's somewhat hacky and brittle, and it requires two passes of the Svelte parser, so it's slower. Since preserveValueImports was introduced which handles exactly this use case ("hey TS, don't remove this even if it looks unused to you") I prefer that option since it's part of TS and more reliable. Consequently, I think that |
Oh, cool! I definitely can get behind the hacky argument :P I'm not exactly sure why this was requiring a double pass of a Svelte parser - but I trust your word on it.
To some extent - yet. The problem is that it requires you to structure your imports in a different way than usual, and it's even more aggressive that the restrictions of the I respect your decision and all though - it's good that we have a dedicated note in the docs now about |
I've seen related issues regarding TypeScript compiler but I couldn't find any related to Babel.
I've successfully worked around my issue but I wonder if this issue is known and if perhaps at least some note to the docs could be added about it.
Basically the problem is that the script and the template parts are preprocessed separately and thus when using
@babel/preset-typescript
the import like this gets dropped:Babel doesn't recognize that the
ChildComp
was actually referenced at the "runtime position" in the original source because that part of the source is not being given to it.The workaround that I've used is to use this preset-level option
onlyRemoveTypeImports: true
The text was updated successfully, but these errors were encountered: