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

let-var renaming can break things #124

Closed
chocolateboy opened this issue Nov 3, 2014 · 5 comments
Closed

let-var renaming can break things #124

chocolateboy opened this issue Nov 3, 2014 · 5 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@chocolateboy
Copy link
Contributor

Is it possible to turn off the name -> _name renaming used for let vars?

This works in Firefox (and Traceur) but doesn't work with 6to5:

function foo (n) {
    let bar = n;
    eval('console.log(bar)');
}

foo(42);

6to5 produces:

"use strict";
function foo (n) {
    var _bar = n;
    eval('console.log(bar)');
}

foo(42);

Function parameters are affected as well in some circumstances, which could break Function.toString hacks (e.g. DI in AngularJS):

let n = 42;

function square(n) {
    return n * n;
}

6to5:

"use strict";
var _n = 42;

function square(_n) {
    return _n * _n;
}
@sebmck
Copy link
Contributor

sebmck commented Nov 3, 2014

The let scoping transformer is definently very funky at the moment and needs a rewrite.

@chocolateboy
Copy link
Contributor Author

Another test case for the rewrite:

let n = 42;

function add(n, _n) {
    return n + _n;
}

6to5:

"use strict";
var _n = 42;

function add(_n, _n) {
    return _n + _n;
}

6to5-node:

function add(_n, _n) {
                 ^^
SyntaxError: Strict mode function may not have duplicate parameter names

P.S. This isn't a dealbreaker for me at the moment, and I'm loving the quick fixes/responses!

@sebmck
Copy link
Contributor

sebmck commented Nov 3, 2014

Yeah, generateUid which we use to generate unique ids needs to check if there are any variables with the same name. I'm currently rewriting the let scoping transformer as it's long over due and there are a variety of issues with it.

Thanks for the feedback!

@sebmck
Copy link
Contributor

sebmck commented Nov 6, 2014

Fixed when 287cbbb is merged.

@sebmck sebmck closed this as completed Nov 6, 2014
@sebmck
Copy link
Contributor

sebmck commented Nov 9, 2014

Fixed as of 1.11.0

@chocolateboy chocolateboy mentioned this issue Nov 14, 2014
ramasilveyra pushed a commit to ramasilveyra/babel that referenced this issue Sep 30, 2017
JacopKane pushed a commit to JacopKane/babel that referenced this issue Jan 11, 2018
* fix: arrow return type on next line is valid

babel/babel-eslint#348

* fix: arrow on line after return type annotation is invalid

* lint
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants