Skip to content

Parameter's default value is removed when it's not supposed to #4516

@jindrahm

Description

@jindrahm

Rollup Version

2.75.0+

Operating System (or Browser)

macOS Monterey

Node Version (if applicable)

16.14.0

Link To Reproduction

https://replit.com/@jindrahm/ParamDefaultBug?v=1

Expected Behaviour

The following code should remain basically untouched after bundling by rollup.

const systemService = {restart};

function restart(options = {}) {
  if (options.countdown) {
    console.log('shows restart dialog with a countdown');
  } else {
    console.log('restarts immediately');
  }
}

systemService.restart();

Actual Behaviour

But it generates this code which throws an error because rollup removed the options param default value so it cannot access the countdown property of undefined.

const systemService = {restart};

function restart(options) {
    if (options.countdown) {
    console.log('shows restart dialog with a countdown');
  } else {
    console.log('restarts immediately');
  }
}

systemService.restart();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions