mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(codegen): converts line comment to block comment if it is a PURE comment (#6356)
The last part of fixing https://github.com/rolldown/rolldown/pull/2375/files#r1789011257 In the following case, the pure comment was written by `//` ```ts const Component = // #__PURE__ React.forwardRef((props, ref) => {}); ``` The printed code looks like this ```ts const Component = // #__PURE__ React.forwardRef((props, ref) => {}); ``` As you can see, it is broken because the code also commented, so we need to replace `//` with `/* */`
This commit is contained in:
parent
1380d8b5dc
commit
84b2d072e8
3 changed files with 19 additions and 1 deletions
|
|
@ -140,7 +140,13 @@ impl<'a> Codegen<'a> {
|
|||
if !Self::is_annotation_comment(&comment, source_text) {
|
||||
continue;
|
||||
}
|
||||
self.print_str(comment.real_span().source_text(source_text));
|
||||
if comment.is_line() {
|
||||
self.print_str("/*");
|
||||
self.print_str(comment.span.source_text(source_text));
|
||||
self.print_str("*/");
|
||||
} else {
|
||||
self.print_str(comment.real_span().source_text(source_text));
|
||||
}
|
||||
self.print_hard_space();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ const defineSSRCustomElement = () => {
|
|||
return /* @__PURE__ */ /* @__NO_SIDE_EFFECTS__ */ /* #__NO_SIDE_EFFECTS__ */ defineCustomElement(options, extraOptions, hydrate);
|
||||
};
|
||||
",
|
||||
"
|
||||
const Component = // #__PURE__
|
||||
React.forwardRef((props, ref) => {});
|
||||
",
|
||||
];
|
||||
|
||||
snapshot("pure_comments", &cases);
|
||||
|
|
|
|||
|
|
@ -269,3 +269,11 @@ const defineSSRCustomElement = () => {
|
|||
const defineSSRCustomElement = () => {
|
||||
return /* @__PURE__ */ /* @__NO_SIDE_EFFECTS__ */ /* #__NO_SIDE_EFFECTS__ */ defineCustomElement(options, extraOptions, hydrate);
|
||||
};
|
||||
|
||||
########## 20
|
||||
|
||||
const Component = // #__PURE__
|
||||
React.forwardRef((props, ref) => {});
|
||||
|
||||
----------
|
||||
const Component = /* #__PURE__*/ React.forwardRef((props, ref) => {});
|
||||
|
|
|
|||
Loading…
Reference in a new issue