after insertAfter,always have a empty line
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
i am trying to edit ast, then `print` it into js file,but, there is something confuse me。
after `insertAfter` something, there is a empty line,that i do not want this。
```
let hasImport = false;
traverse(parsedCode, {
ImportDeclaration(element) {
if (
element.getSibling(element.key + 1).node.type !== 'ImportDeclaration'
&& element.node.type === 'ImportDeclaration'
&& !hasImport
) {
element.insertAfter([
t.importDeclaration([
t.ImportDefaultSpecifier(t.identifier(moduleName)),
],
t.stringLiteral(modulePath)),
]);
hasImport = true;
}
},
JSXElement(element) {
const { node: { openingElement } } = element;
if (openingElement.name.name === 'Redirect') {
element.insertAfter(
[t.jSXText('\n'),
t.jSXElement(
t.jSXOpeningElement(
t.jSXIdentifier('Route'),
[
t.jSXAttribute(t.jSXIdentifier('path'), t.stringLiteral(routePath)),
t.jSXAttribute(t.jSXIdentifier('component'), t.jSXExpressionContainer(t.jSXIdentifier(moduleName))),
],
true,
),
null,
[],
true,
)],
);
}
},
});
```

Thanks! for anyone who can help
@benjamn
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the reported AST edit with insertAfter and print, using the JavaScript example in the issue. Compare the generated file with the expected formatting and trace the relevant insertAfter or printer entry point; done means the inserted import or JSX element no longer produces an unwanted empty line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100