Skip to content

Commit

Permalink
chore(codegen): add more tests for comments from esbuild (#6357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Oct 8, 2024
1 parent 84b2d07 commit 585cdd5
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 0 deletions.
62 changes: 62 additions & 0 deletions crates/oxc_codegen/tests/integration/pure_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,68 @@ const defineSSRCustomElement = () => {
const Component = // #__PURE__
React.forwardRef((props, ref) => {});
",
// Copy from <https://github.com/rolldown-rs/rolldown/blob/main/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js>
"
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);
Expand Down
120 changes: 120 additions & 0 deletions crates/oxc_codegen/tests/integration/snapshots/pure_comments.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 585cdd5

Please sign in to comment.