mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/transforms): Do not add PURE
comment to BytePos(0)
(#8207)
**Related issue:** - https://github.com/vercel/next.js/pull/57904 (CI failed)
This commit is contained in:
parent
aefa70159a
commit
c061356b63
@ -243,9 +243,9 @@ where
|
||||
fn visit_mut_expr(&mut self, n: &mut Expr) {
|
||||
match n {
|
||||
Expr::Class(e) => {
|
||||
let class = self.fold_class(e.ident.take(), e.class.take());
|
||||
if let Expr::Call(call) = &class {
|
||||
self.add_pure_comments(call.span.lo)
|
||||
let mut class = self.fold_class(e.ident.take(), e.class.take());
|
||||
if let Expr::Call(call) = &mut class {
|
||||
self.add_pure_comments(&mut call.span.lo)
|
||||
}
|
||||
*n = class;
|
||||
n.visit_mut_children_with(self)
|
||||
@ -359,9 +359,13 @@ impl<C> Classes<C>
|
||||
where
|
||||
C: Comments,
|
||||
{
|
||||
fn add_pure_comments(&mut self, start: BytePos) {
|
||||
fn add_pure_comments(&mut self, start: &mut BytePos) {
|
||||
if start.is_dummy() {
|
||||
*start = Span::dummy_with_cmt().lo;
|
||||
}
|
||||
|
||||
if let Some(comments) = &self.comments {
|
||||
comments.add_pure_comment(start);
|
||||
comments.add_pure_comment(*start);
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,12 +379,12 @@ where
|
||||
|
||||
// let VarDecl take every comments except pure
|
||||
if let Expr::Call(call) = &mut rhs {
|
||||
let span = Span {
|
||||
let mut span = Span {
|
||||
// after class
|
||||
lo: span.hi + BytePos(5),
|
||||
..span
|
||||
};
|
||||
self.add_pure_comments(span.lo);
|
||||
self.add_pure_comments(&mut span.lo);
|
||||
call.span = span;
|
||||
}
|
||||
|
||||
|
@ -436,11 +436,15 @@ where
|
||||
}
|
||||
|
||||
fn jsx_frag_to_expr(&mut self, el: JSXFragment) -> Expr {
|
||||
let span = el.span();
|
||||
let mut span = el.span();
|
||||
|
||||
let use_jsxs = count_children(&el.children) > 1;
|
||||
|
||||
if let Some(comments) = &self.comments {
|
||||
if span.lo.is_dummy() {
|
||||
span.lo = Span::dummy_with_cmt().lo;
|
||||
}
|
||||
|
||||
comments.add_pure_comment(span.lo);
|
||||
}
|
||||
|
||||
@ -543,13 +547,17 @@ where
|
||||
/// <div></div> => React.createElement('div', null);
|
||||
fn jsx_elem_to_expr(&mut self, el: JSXElement) -> Expr {
|
||||
let top_level_node = self.top_level_node;
|
||||
let span = el.span();
|
||||
let mut span = el.span();
|
||||
let use_create_element = should_use_create_element(&el.opening.attrs);
|
||||
self.top_level_node = false;
|
||||
|
||||
let name = self.jsx_name(el.opening.name);
|
||||
|
||||
if let Some(comments) = &self.comments {
|
||||
if span.lo.is_dummy() {
|
||||
span.lo = Span::dummy_with_cmt().lo;
|
||||
}
|
||||
|
||||
comments.add_pure_comment(span.lo);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use swc_atoms::JsWord;
|
||||
use swc_common::{collections::AHashMap, comments::Comments};
|
||||
use swc_common::{collections::AHashMap, comments::Comments, Span};
|
||||
use swc_ecma_ast::*;
|
||||
use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith};
|
||||
|
||||
@ -108,6 +108,10 @@ where
|
||||
|
||||
if is_react_call {
|
||||
if let Some(comments) = &self.comments {
|
||||
if call.span.lo.is_dummy() {
|
||||
call.span.lo = Span::dummy_with_cmt().lo;
|
||||
}
|
||||
|
||||
comments.add_pure_comment(call.span.lo);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user