From 585cdd5bcd25289fcbbca264e295db86f2afddc9 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 8 Oct 2024 05:42:43 +0000 Subject: [PATCH] chore(codegen): add more tests for comments from esbuild (#6357) Copy from https://github.com/rolldown-rs/rolldown/blob/main/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js --- .../tests/integration/pure_comments.rs | 62 +++++++++ .../integration/snapshots/pure_comments.snap | 120 ++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/crates/oxc_codegen/tests/integration/pure_comments.rs b/crates/oxc_codegen/tests/integration/pure_comments.rs index 31ba7452a7daf..5ceb65abec09c 100644 --- a/crates/oxc_codegen/tests/integration/pure_comments.rs +++ b/crates/oxc_codegen/tests/integration/pure_comments.rs @@ -133,6 +133,68 @@ const defineSSRCustomElement = () => { const Component = // #__PURE__ React.forwardRef((props, ref) => {}); ", + // Copy from + " + function bar() {} + let bare = foo(bar); + + let at_yes = /* @__PURE__ */ foo(bar); + let at_no = /* @__PURE__ */ foo(bar()); + let new_at_yes = /* @__PURE__ */ new foo(bar); + let new_at_no = /* @__PURE__ */ new foo(bar()); + + let nospace_at_yes = /*@__PURE__*/ foo(bar); + let nospace_at_no = /*@__PURE__*/ foo(bar()); + let nospace_new_at_yes = /*@__PURE__*/ new foo(bar); + let nospace_new_at_no = /*@__PURE__*/ new foo(bar()); + + let num_yes = /* #__PURE__ */ foo(bar); + let num_no = /* #__PURE__ */ foo(bar()); + let new_num_yes = /* #__PURE__ */ new foo(bar); + let new_num_no = /* #__PURE__ */ new foo(bar()); + + let nospace_num_yes = /*#__PURE__*/ foo(bar); + let nospace_num_no = /*#__PURE__*/ foo(bar()); + let nospace_new_num_yes = /*#__PURE__*/ new foo(bar); + let nospace_new_num_no = /*#__PURE__*/ new foo(bar()); + + let dot_yes = /* @__PURE__ */ foo(sideEffect()).dot(bar); + let dot_no = /* @__PURE__ */ foo(sideEffect()).dot(bar()); + let new_dot_yes = /* @__PURE__ */ new foo(sideEffect()).dot(bar); + let new_dot_no = /* @__PURE__ */ new foo(sideEffect()).dot(bar()); + + let nested_yes = [1, /* @__PURE__ */ foo(bar), 2]; + let nested_no = [1, /* @__PURE__ */ foo(bar()), 2]; + let new_nested_yes = [1, /* @__PURE__ */ new foo(bar), 2]; + let new_nested_no = [1, /* @__PURE__ */ new foo(bar()), 2]; + + let single_at_yes = // @__PURE__ + foo(bar); + let single_at_no = // @__PURE__ + foo(bar()); + let new_single_at_yes = // @__PURE__ + new foo(bar); + let new_single_at_no = // @__PURE__ + new foo(bar()); + + let single_num_yes = // #__PURE__ + foo(bar); + let single_num_no = // #__PURE__ + foo(bar()); + let new_single_num_yes = // #__PURE__ + new foo(bar); + let new_single_num_no = // #__PURE__ + new foo(bar()); + + let bad_no = /* __PURE__ */ foo(bar); + let new_bad_no = /* __PURE__ */ new foo(bar); + + let parens_no = (/* @__PURE__ */ foo)(bar); + let new_parens_no = new (/* @__PURE__ */ foo)(bar); + + let exp_no = /* @__PURE__ */ foo() ** foo(); + let new_exp_no = /* @__PURE__ */ new foo() ** foo(); + ", ]; snapshot("pure_comments", &cases); diff --git a/crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap b/crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap index 74c8521bb1420..b653834f5bc41 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap @@ -277,3 +277,123 @@ const defineSSRCustomElement = () => { ---------- const Component = /* #__PURE__*/ React.forwardRef((props, ref) => {}); + +########## 21 + + function bar() {} + let bare = foo(bar); + + let at_yes = /* @__PURE__ */ foo(bar); + let at_no = /* @__PURE__ */ foo(bar()); + let new_at_yes = /* @__PURE__ */ new foo(bar); + let new_at_no = /* @__PURE__ */ new foo(bar()); + + let nospace_at_yes = /*@__PURE__*/ foo(bar); + let nospace_at_no = /*@__PURE__*/ foo(bar()); + let nospace_new_at_yes = /*@__PURE__*/ new foo(bar); + let nospace_new_at_no = /*@__PURE__*/ new foo(bar()); + + let num_yes = /* #__PURE__ */ foo(bar); + let num_no = /* #__PURE__ */ foo(bar()); + let new_num_yes = /* #__PURE__ */ new foo(bar); + let new_num_no = /* #__PURE__ */ new foo(bar()); + + let nospace_num_yes = /*#__PURE__*/ foo(bar); + let nospace_num_no = /*#__PURE__*/ foo(bar()); + let nospace_new_num_yes = /*#__PURE__*/ new foo(bar); + let nospace_new_num_no = /*#__PURE__*/ new foo(bar()); + + let dot_yes = /* @__PURE__ */ foo(sideEffect()).dot(bar); + let dot_no = /* @__PURE__ */ foo(sideEffect()).dot(bar()); + let new_dot_yes = /* @__PURE__ */ new foo(sideEffect()).dot(bar); + let new_dot_no = /* @__PURE__ */ new foo(sideEffect()).dot(bar()); + + let nested_yes = [1, /* @__PURE__ */ foo(bar), 2]; + let nested_no = [1, /* @__PURE__ */ foo(bar()), 2]; + let new_nested_yes = [1, /* @__PURE__ */ new foo(bar), 2]; + let new_nested_no = [1, /* @__PURE__ */ new foo(bar()), 2]; + + let single_at_yes = // @__PURE__ + foo(bar); + let single_at_no = // @__PURE__ + foo(bar()); + let new_single_at_yes = // @__PURE__ + new foo(bar); + let new_single_at_no = // @__PURE__ + new foo(bar()); + + let single_num_yes = // #__PURE__ + foo(bar); + let single_num_no = // #__PURE__ + foo(bar()); + let new_single_num_yes = // #__PURE__ + new foo(bar); + let new_single_num_no = // #__PURE__ + new foo(bar()); + + let bad_no = /* __PURE__ */ foo(bar); + let new_bad_no = /* __PURE__ */ new foo(bar); + + let parens_no = (/* @__PURE__ */ foo)(bar); + let new_parens_no = new (/* @__PURE__ */ foo)(bar); + + let exp_no = /* @__PURE__ */ foo() ** foo(); + let new_exp_no = /* @__PURE__ */ new foo() ** foo(); + +---------- +function bar() {} +let bare = foo(bar); +let at_yes = /* @__PURE__ */ foo(bar); +let at_no = /* @__PURE__ */ foo(bar()); +let new_at_yes = /* @__PURE__ */ new foo(bar); +let new_at_no = /* @__PURE__ */ new foo(bar()); +let nospace_at_yes = /*@__PURE__*/ foo(bar); +let nospace_at_no = /*@__PURE__*/ foo(bar()); +let nospace_new_at_yes = /*@__PURE__*/ new foo(bar); +let nospace_new_at_no = /*@__PURE__*/ new foo(bar()); +let num_yes = /* #__PURE__ */ foo(bar); +let num_no = /* #__PURE__ */ foo(bar()); +let new_num_yes = /* #__PURE__ */ new foo(bar); +let new_num_no = /* #__PURE__ */ new foo(bar()); +let nospace_num_yes = /*#__PURE__*/ foo(bar); +let nospace_num_no = /*#__PURE__*/ foo(bar()); +let nospace_new_num_yes = /*#__PURE__*/ new foo(bar); +let nospace_new_num_no = /*#__PURE__*/ new foo(bar()); +let dot_yes = /* @__PURE__ */ foo(sideEffect()).dot(bar); +let dot_no = /* @__PURE__ */ foo(sideEffect()).dot(bar()); +let new_dot_yes = /* @__PURE__ */ new foo(sideEffect()).dot(bar); +let new_dot_no = /* @__PURE__ */ new foo(sideEffect()).dot(bar()); +let nested_yes = [ + 1, + /* @__PURE__ */ foo(bar), + 2 +]; +let nested_no = [ + 1, + /* @__PURE__ */ foo(bar()), + 2 +]; +let new_nested_yes = [ + 1, + /* @__PURE__ */ new foo(bar), + 2 +]; +let new_nested_no = [ + 1, + /* @__PURE__ */ new foo(bar()), + 2 +]; +let single_at_yes = /* @__PURE__*/ foo(bar); +let single_at_no = /* @__PURE__*/ foo(bar()); +let new_single_at_yes = /* @__PURE__*/ new foo(bar); +let new_single_at_no = /* @__PURE__*/ new foo(bar()); +let single_num_yes = /* #__PURE__*/ foo(bar); +let single_num_no = /* #__PURE__*/ foo(bar()); +let new_single_num_yes = /* #__PURE__*/ new foo(bar); +let new_single_num_no = /* #__PURE__*/ new foo(bar()); +let bad_no = foo(bar); +let new_bad_no = new foo(bar); +let parens_no = foo(bar); +let new_parens_no = new foo(bar); +let exp_no = /* @__PURE__ */ foo() ** foo(); +let new_exp_no = /* @__PURE__ */ new foo() ** foo();