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

Transpilation bug: Warnings on multi-variable let declarations #2969

Closed
rivo opened this issue Jun 7, 2018 · 1 comment
Closed

Transpilation bug: Warnings on multi-variable let declarations #2969

rivo opened this issue Jun 7, 2018 · 1 comment
Assignees

Comments

@rivo
Copy link

rivo commented Jun 7, 2018

The following code:

{
  let x = 10,
      y = 20;
  console.log(y);
}

{
  let x = 30,
      y = 40;
  console.log(y);
}

gives the following warning:

JSC_CONSTANT_REASSIGNED_VALUE_ERROR: constant y assigned a value more than once.
Original definition at Input_0:4 at line 10 character 6
      y = 40;
      ^

(See for yourself on the Closure Compiler web app.)

This is the ES5 output which also appears to be incorrect (y from the first block should not be reused):

var x=10,y=20;console.log(y);var x$0=30;y=40;console.log(y);

The problem appears to be with declaring multiple variables with one let statement. If I give each variable its own let statement, it transpiles correctly without warnings:

{
  let x = 10;
  let y = 20;
  console.log(y);
}

{
  let x = 30;
  let y = 40;
  console.log(y);
}

Output:

var x=10,y=20;console.log(y);var x$0=30,y$1=40;console.log(y$1);

(There was some discussion about this already in this StackOverflow thread.)

@lauraharker
Copy link
Contributor

Thanks for the report!

I've submitted a fix internally, and it will be out in the next push to GitHub.

Yannic pushed a commit to Yannic/com_google_closure_compiler that referenced this issue Jul 16, 2018
Note: The Es6SplitVariableDeclarations pass normalizes multivariate declarations with at least one destructuring pattern. I didn't just add let/const declaration normalization to that pass because it doesn't handle declarations outside of a statement block. (e.g. in a for-loop header or label).

Fixes google#2969

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=200105402
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

2 participants