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

Allow adding import statement after existing imports #122

Closed
1 task done
bluwy opened this issue Aug 26, 2024 · 1 comment · Fixed by #124
Closed
1 task done

Allow adding import statement after existing imports #122

bluwy opened this issue Aug 26, 2024 · 1 comment · Fixed by #124
Labels
enhancement New feature or request pr welcome

Comments

@bluwy
Copy link
Contributor

bluwy commented Aug 26, 2024

Describe the feature

Currently imports added (with $add) prepends before any other import statements in the file. There's also a TODO to consider appending instead:

const declaration = imports.find(
(i) => i.from === value.from,
)?.$declaration;
if (declaration) {
// TODO: insert after the last import maybe?
declaration.specifiers.push(specifier as any);
} else {
root.body.unshift(
b.importDeclaration([specifier], b.stringLiteral(value.from)) as any,
);
}

It would be nice if we can add import statements after existing imports.


There's a comment at #45 (comment) that suggests adding $append and $prepend to all the nodes. Maybe we can apply the same idea for .imports only for now?


I'm trying to migrate Astro to use this, but I think this issue is the only blocker before it's ready: withastro/astro#11772. There's other new lines formatting difference, but I think it's not a big deal.

Additional information

  • Would you be willing to help implement this feature?
@bluwy bluwy added the enhancement New feature or request label Aug 26, 2024
@antfu
Copy link
Member

antfu commented Aug 26, 2024

Yeah sure! $append and $prepend sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants