Repository navigation
fix(replace-reactdom-render): skip comments when reading call arguments - #22
devagrawal09 wants to merge 1 commit into
Conversation
…ts (#21) Comment nodes are children of the call's arguments node, so a comment inside render(...) was treated as the first argument and every argument shifted: createRoot got the element, root.render got the comment (which swallowed the closing paren), and the container became a stray call. Filter comment nodes out of the argument list for both render and unmountComponentAtNode, and keep comments that precede the element inside the generated root.render(...) call.
|
/codex-review |
| const originalCol = startLine.length - startLine.trimStart().length; | ||
| return " ".repeat(desiredCol) + reindentText(node.text(), originalCol, desiredCol); | ||
| }; | ||
| const body = [...leadingComments, element].map(reindentNode).join("\n"); |
There was a problem hiding this comment.
[MEDIUM] Preserve line breaks between leading comments and the element
Joining every comment and the element with a newline changes directive targets. For example, a // @ts-expect-error immediately above /* rationale */ build("bad") correctly suppresses an argument type error before transformation. This code moves the block comment onto its own line, separating the directive from the expression; TypeScript then reports both an unused directive and the original type error. Preserve the original line relationships and add a mixed line/block comment fixture.
| const argList = args.children().filter((child) => | ||
| child.kind() !== "(" && child.kind() !== ")" && child.kind() !== "," | ||
| ); | ||
| const argList = callArguments(args); |
There was a problem hiding this comment.
[MEDIUM] Preserve suppression directives before the unmount container
The unmount path now skips leading comments when selecting the container but discards them when generating createRoot(...). A call with // @ts-expect-error before a container typed Element | undefined type-checks before transformation, while the generated createRoot(container) fails because the suppression is gone. Preserve these directives next to the container expression in the new call and add a directive fixture; the current ordinary-comment fixture does not catch this failure.
Codex ReviewAll 16 fixtures and the transform type check pass. Additional checks reproduced two comment-directive edge cases that produce TypeScript errors. Findings
|
Fixes #21.
A comment inside
render(...)orunmountComponentAtNode(...)was read as an argument, so every argument shifted by one and the output didn't parse.callArguments()helper skips comment nodes; both call sites use it.root.render(...)call, which then spans several lines so a//comment can't swallow the closing).tests/comment-inside-render(the issue's input) andtests/comment-inside-unmount. Both fail without the fix.Not handled: a comment after the element (
<App />, // note) is still dropped; the output stays valid.