Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and kdy1 committed Jul 6, 2024
1 parent 3543d36 commit 898f70e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ impl VisitMut for Remover {
if s.exprs.is_empty() {
*e = Expr::dummy();
} else if s.exprs.len() == 1 {
*e = *s.exprs.pop().unwrap();
// TODO: preserve PURE comment attached to original
// sequence expression.

// *e = *s.exprs.pop().unwrap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1843,3 +1843,48 @@ fn issue_6732_2() {
"var foo;",
);
}

fn test_with_comments(input: &str, expected: &str) {
swc_ecma_transforms_testing::Tester::run(|tester| {
let unresolved_mark = Mark::new();
let top_level_mark = Mark::new();
let tr = chain!(
resolver(unresolved_mark, top_level_mark, false),
paren_remover(None),
expr_simplifier(top_level_mark, Default::default()),
as_folder(super::Remover {
changed: false,
normal_block: Default::default(),
expr_ctx: ExprCtx {
unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
// This is hack
is_unresolved_ref_safe: true,
},
})
);

let actual = tester.apply_transform(tr, "input.js", Default::default(), input)?;
let comments = std::mem::take(&mut tester.comments);
let actual_src = tester.print(&actual, &comments);

if actual_src != expected {
println!(">>>>> Orig <<<<<\n{}", input);
println!(">>>>> Code <<<<<\n{}", actual_src);
panic!(
r#"assertion failed: `(left == right)`
{}"#,
::testing::diff(&actual_src, expected),
);
}

Ok(())
});
}

#[test]
fn test_seq() {
test_with_comments(
"const Test1 = /*#__PURE__*/ (0, forwardRef)(Foo);",
"const Test1 = /*#__PURE__*/ forwardRef(Foo);\n",
)
}

0 comments on commit 898f70e

Please sign in to comment.