Skip to content

Commit

Permalink
#3149: @__NO_SIDE_EFFECTS__ on async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 11, 2023
1 parent eabcc87 commit 394941b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 160 deletions.
81 changes: 8 additions & 73 deletions internal/bundler_tests/bundler_dce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3761,10 +3761,6 @@ func TestNoSideEffectsComment(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ function y() {},
/* #__NO_SIDE_EFFECTS__ */ function*() {},
/* #__NO_SIDE_EFFECTS__ */ function* y() {},
])
//! These should not have "no side effects" (Rollup ignores "async" functions)
x([
/* #__NO_SIDE_EFFECTS__ */ async function() {},
/* #__NO_SIDE_EFFECTS__ */ async function y() {},
/* #__NO_SIDE_EFFECTS__ */ async function*() {},
Expand All @@ -3777,10 +3773,6 @@ func TestNoSideEffectsComment(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ y => y,
/* #__NO_SIDE_EFFECTS__ */ () => {},
/* #__NO_SIDE_EFFECTS__ */ (y) => (y),
])
//! These should not have "no side effects" (Rollup ignores "async" functions)
x([
/* #__NO_SIDE_EFFECTS__ */ async y => y,
/* #__NO_SIDE_EFFECTS__ */ async () => {},
/* #__NO_SIDE_EFFECTS__ */ async (y) => (y),
Expand All @@ -3793,8 +3785,6 @@ func TestNoSideEffectsComment(t *testing.T) {
function a() {}
// #__NO_SIDE_EFFECTS__
function* b() {}
//! These should not have "no side effects" (Rollup ignores "async" functions)
// #__NO_SIDE_EFFECTS__
async function c() {}
// #__NO_SIDE_EFFECTS__
Expand All @@ -3804,21 +3794,14 @@ func TestNoSideEffectsComment(t *testing.T) {
//! These should all have "no side effects"
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
//! These should not have "no side effects" (Rollup ignores "async" functions)
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
`,
"/stmt-local.js": `
//! Only "c0" and "c2" should have "no side effects" (Rollup only respects "const" and only for the first one)
/* #__NO_SIDE_EFFECTS__ */ var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ const c2 = () => {}, c3 = () => {}
Expand All @@ -3828,7 +3811,6 @@ func TestNoSideEffectsComment(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand All @@ -3839,14 +3821,8 @@ func TestNoSideEffectsComment(t *testing.T) {
//! These should all have "no side effects"
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
//! These should not have "no side effects" (Rollup ignores "async" functions)
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
}
`,
"/ns-export-local.ts": `
Expand All @@ -3855,7 +3831,6 @@ func TestNoSideEffectsComment(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand All @@ -3866,19 +3841,19 @@ func TestNoSideEffectsComment(t *testing.T) {
"/stmt-export-default-before-fn-name.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default function f() {}`,
"/stmt-export-default-before-gen-fn-anon.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default function*() {}`,
"/stmt-export-default-before-gen-fn-name.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default function* f() {}`,
"/stmt-export-default-before-async-fn-anon.js": `/*! This should not have "no side effects" (because "async") */ /* #__NO_SIDE_EFFECTS__ */ export default async function() {}`,
"/stmt-export-default-before-async-fn-name.js": `/*! This should not have "no side effects" (because "async") */ /* #__NO_SIDE_EFFECTS__ */ export default async function f() {}`,
"/stmt-export-default-before-async-gen-fn-anon.js": `/*! This should not have "no side effects" (because "async") */ /* #__NO_SIDE_EFFECTS__ */ export default async function*() {}`,
"/stmt-export-default-before-async-gen-fn-name.js": `/*! This should not have "no side effects" (because "async") */ /* #__NO_SIDE_EFFECTS__ */ export default async function* f() {}`,
"/stmt-export-default-before-async-fn-anon.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default async function() {}`,
"/stmt-export-default-before-async-fn-name.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default async function f() {}`,
"/stmt-export-default-before-async-gen-fn-anon.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default async function*() {}`,
"/stmt-export-default-before-async-gen-fn-name.js": `/*! This should have "no side effects" */ /* #__NO_SIDE_EFFECTS__ */ export default async function* f() {}`,

"/stmt-export-default-after-fn-anon.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ function() {}`,
"/stmt-export-default-after-fn-name.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ function f() {}`,
"/stmt-export-default-after-gen-fn-anon.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ function*() {}`,
"/stmt-export-default-after-gen-fn-name.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ function* f() {}`,
"/stmt-export-default-after-async-fn-anon.js": `/*! This should not have "no side effects" (because "async") */ export default /* @__NO_SIDE_EFFECTS__ */ async function() {}`,
"/stmt-export-default-after-async-fn-name.js": `/*! This should not have "no side effects" (because "async") */ export default /* @__NO_SIDE_EFFECTS__ */ async function f() {}`,
"/stmt-export-default-after-async-gen-fn-anon.js": `/*! This should not have "no side effects" (because "async") */ export default /* @__NO_SIDE_EFFECTS__ */ async function*() {}`,
"/stmt-export-default-after-async-gen-fn-name.js": `/*! This should not have "no side effects" (because "async") */ export default /* @__NO_SIDE_EFFECTS__ */ async function* f() {}`,
"/stmt-export-default-after-async-fn-anon.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ async function() {}`,
"/stmt-export-default-after-async-fn-name.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ async function f() {}`,
"/stmt-export-default-after-async-gen-fn-anon.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ async function*() {}`,
"/stmt-export-default-after-async-gen-fn-name.js": `/*! This should have "no side effects" */ export default /* @__NO_SIDE_EFFECTS__ */ async function* f() {}`,
},
entryPaths: []string{
"/expr-fn.js",
Expand Down Expand Up @@ -3925,9 +3900,6 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ function y() {},
/* #__NO_SIDE_EFFECTS__ */ function*() {},
/* #__NO_SIDE_EFFECTS__ */ function* y() {},
])
x([
/* #__NO_SIDE_EFFECTS__ */ async function() {},
/* #__NO_SIDE_EFFECTS__ */ async function y() {},
/* #__NO_SIDE_EFFECTS__ */ async function*() {},
Expand All @@ -3939,9 +3911,6 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ y => y,
/* #__NO_SIDE_EFFECTS__ */ () => {},
/* #__NO_SIDE_EFFECTS__ */ (y) => (y),
])
x([
/* #__NO_SIDE_EFFECTS__ */ async y => y,
/* #__NO_SIDE_EFFECTS__ */ async () => {},
/* #__NO_SIDE_EFFECTS__ */ async (y) => (y),
Expand All @@ -3953,7 +3922,6 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
function a() {}
// #__NO_SIDE_EFFECTS__
function* b() {}
// #__NO_SIDE_EFFECTS__
async function c() {}
// #__NO_SIDE_EFFECTS__
Expand All @@ -3962,19 +3930,13 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
"/stmt-export-fn.js": `
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
`,
"/stmt-local.js": `
/* #__NO_SIDE_EFFECTS__ */ var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ const c2 = () => {}, c3 = () => {}
Expand All @@ -3983,7 +3945,6 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand All @@ -3993,21 +3954,15 @@ func TestNoSideEffectsCommentIgnoreAnnotations(t *testing.T) {
namespace ns {
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
}
`,
"/ns-export-local.ts": `
namespace ns {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand Down Expand Up @@ -4078,9 +4033,6 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ function y() {},
/* #__NO_SIDE_EFFECTS__ */ function*() {},
/* #__NO_SIDE_EFFECTS__ */ function* y() {},
])
x([
/* #__NO_SIDE_EFFECTS__ */ async function() {},
/* #__NO_SIDE_EFFECTS__ */ async function y() {},
/* #__NO_SIDE_EFFECTS__ */ async function*() {},
Expand All @@ -4092,9 +4044,6 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ y => y,
/* #__NO_SIDE_EFFECTS__ */ () => {},
/* #__NO_SIDE_EFFECTS__ */ (y) => (y),
])
x([
/* #__NO_SIDE_EFFECTS__ */ async y => y,
/* #__NO_SIDE_EFFECTS__ */ async () => {},
/* #__NO_SIDE_EFFECTS__ */ async (y) => (y),
Expand All @@ -4106,7 +4055,6 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
function a() {}
// #__NO_SIDE_EFFECTS__
function* b() {}
// #__NO_SIDE_EFFECTS__
async function c() {}
// #__NO_SIDE_EFFECTS__
Expand All @@ -4115,19 +4063,13 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
"/stmt-export-fn.js": `
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
`,
"/stmt-local.js": `
/* #__NO_SIDE_EFFECTS__ */ var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ const c2 = () => {}, c3 = () => {}
Expand All @@ -4136,7 +4078,6 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand All @@ -4146,21 +4087,15 @@ func TestNoSideEffectsCommentMinifyWhitespace(t *testing.T) {
namespace ns {
/* @__NO_SIDE_EFFECTS__ */ export function a() {}
/* @__NO_SIDE_EFFECTS__ */ export function* b() {}
export /* #__NO_SIDE_EFFECTS__ */ function a2() {}
export /* #__NO_SIDE_EFFECTS__ */ function* b2() {}
/* @__NO_SIDE_EFFECTS__ */ export async function c() {}
/* @__NO_SIDE_EFFECTS__ */ export async function* d() {}
export /* #__NO_SIDE_EFFECTS__ */ async function c2() {}
export /* #__NO_SIDE_EFFECTS__ */ async function* d2() {}
}
`,
"/ns-export-local.ts": `
namespace ns {
/* #__NO_SIDE_EFFECTS__ */ export var v0 = function() {}, v1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export let l0 = function() {}, l1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export const c0 = function() {}, c1 = function() {}
/* #__NO_SIDE_EFFECTS__ */ export var v2 = () => {}, v3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export let l2 = () => {}, l3 = () => {}
/* #__NO_SIDE_EFFECTS__ */ export const c2 = () => {}, c3 = () => {}
Expand Down
Loading

0 comments on commit 394941b

Please sign in to comment.