Make optimizeImports
compatible with Svelte 5
#62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #61
Svelte 5 contains breaking changes. One of them is that
svelte/compiler
no longer exports thewalk
function.carbon-preprocess-svelte
useswalk
to walk the AST in order to re-write Carbon-related imports at compile time.The officially recommended approach is to import
walk
fromstreet-walker
directly. However, in my initial testing, I found that the latest major version ofestree-walker
is ESM-only (see Rich-Harris/estree-walker#26).My goals for this package include the following:
svelte
as a direct dependency. I want to avoid using a specific version ofsvelte
with this package. What I mean by this is that the package should use the parser from the Svelte version the user uses. For example, if a user is running Svelte 3/4, it should use theparse
from their exact Svelte version.As such, I've arrived at the following:
walk
fromestree-walker@2
(which is still CJS-compatible)From my testing, this approach works with Svelte 4 and Svelte 5.