Skip to content

Commit a916563

Browse files
authored
Support @__PURE__ when nested after new in constructor invocations (#5998)
1 parent bd2d98c commit a916563

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

rust/parse_ast/src/ast_nodes/new_expression.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use swc_common::Spanned;
12
use swc_ecma_ast::NewExpr;
23

34
use crate::convert_ast::annotations::AnnotationKind;
@@ -13,8 +14,9 @@ impl AstConverter<'_> {
1314
&TYPE_NEW_EXPRESSION,
1415
&new_expression.span,
1516
NEW_EXPRESSION_RESERVED_BYTES,
16-
false,
17+
true,
1718
);
19+
self.move_to_specific_index(new_expression.callee.span_lo().0 - 2);
1820
// annotations
1921
let annotations = self
2022
.index_converter

rust/parse_ast/src/convert_ast/converter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ impl<'a> AstConverter<'a> {
795795
}
796796
}
797797
}
798+
799+
pub(crate) fn move_to_specific_index(&mut self, index: u32) {
800+
self.index_converter.convert(index, false);
801+
}
798802
}
799803

800804
pub(crate) fn convert_annotation(buffer: &mut Vec<u8>, annotation: &ConvertedAnnotation) {

test/form/samples/pure-comment-scenarios-simple/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
(/*@__PURE__*/ p.x(1).y(2).z(3));
1818
[ /*@__PURE__*/ q() ];
1919
/*@__PURE__*/ new r();
20+
new /*@__PURE__*/ r();
2021
/*@__PURE__*/ (new s());
2122
(/*@__PURE__*/ new t());
2223
/*@__PURE__*/ new u(1)(2)(3);

0 commit comments

Comments
 (0)