Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"multiple parameters named <value>" when destructuring params in args with duplicate default values #5332

Open
hibachrach opened this issue Aug 17, 2020 · 2 comments

Comments

@hibachrach
Copy link

Bug report

Input Code

baz = ({ foo: _foo = false, bar: _bar = false } = {}) ->

Expected Behavior

var baz;

baz = function(arg) {
  var _bar, _foo, ref, ref1, ref2;
  ref = arg != null ? arg : {}, _foo = (ref1 = ref.foo) != null ? ref1 : false, _bar = (ref2 = ref.bar) != null ? ref2 : false;
};

Current Behavior

Error on line 1: multiple parameters named false

Context

This often comes up with constructor params where you have several named params which all default to false

Environment

This occurs with v1.12.7 but not whatever v2.x.x version is on the main (non-v2) website

  • CoffeeScript version: v1.12.7
  • Node.js version: v12.14.1
@ljluestc
Copy link

ljluestc commented Sep 9, 2023

This appears to be a bug in that specific version of CoffeeScript. To resolve this issue, you can either upgrade to a newer version of CoffeeScript or modify your code to work around the problem.

Here's your code with a slight modification to avoid the issue:

baz = ({ foo: _foo, bar: _bar } = {}) ->
  _foo ?= false
  _bar ?= false

In this modified code, we use the ?= operator to assign a default value to _foo and _bar if they are undefined or null. This should work as expected and avoid the error you encountered in CoffeeScript v1.12.7.

@Inve1951
Copy link
Contributor

fyi v1 website is still up: v1/#try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants