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

Mangler using wrong variable name in some cases #369

Closed
loganfsmyth opened this issue Jan 10, 2017 · 5 comments
Closed

Mangler using wrong variable name in some cases #369

loganfsmyth opened this issue Jan 10, 2017 · 5 comments
Labels
bug Confirmed bug

Comments

@loganfsmyth
Copy link
Member

Tested out the mangler on our codebase and got the following:

function decodeMessage(message){
    let namespace;
    let name;
    let value = null;

    [, namespace, name, value] = message.split(',') || [];
    console.log(name);
}

converts to

function decodeMessage(a) {
    let b;
    let c;
    let d = null;

    [ , b , d , d ] = a.split(',') || [];
    console.log(c);
}

notice the third item in the destructured array is d instead of c for some reason.

I see there are a few mangler bugs filed, but I don't know if this is one of them. Sorry if it is a duplicate.

@boopathi
Copy link
Member

Related #326

@filmic
Copy link

filmic commented Jan 13, 2017

Similar issue with broken array destructuring:

function currentData(id) {
	let [alpha, beta, gamma] = id.split('_');
	[alpha, beta, gamma] = _.map([alpha, beta, gamma], idPart => {
		return parseInt(idPart, 10);
	});
}

is converted to:

function currentData(a){let[b,c,d]=a.split('_');[b,d,d]=_.map([b,c,d],e=>{return parseInt(e,10)})}

REPL LINK

@kangax kangax added the bug Confirmed bug label Jan 17, 2017
@keithamus
Copy link
Member

keithamus commented Jan 24, 2017

I also have a similar issue, but this is with destructuring in function arguments. Was unsure if I should file a new issue or put it in this one.

Given (repl):

const Main = ({ thing: Thing = 'div' }) => <Thing />;
<Main thing={'span'} />

Actual (formatted)

const Main=({thing:a='div'})=>React.createElement(Thing,null); // ReferenceError Thing is not defined
React.createElement(Main,{thing:'span'});

Expected (formatted)

const Main=({thing:A='div'})=>React.createElement(A,null);
React.createElement(Main,{thing:'span'});

@xtuc
Copy link
Member

xtuc commented Jan 24, 2017

@keithamus I think this is correct because you shoud write that:

const Main = ({ Thing: ThingInterface = 'div' }) => <Thing />;
<Main thing={'span'} />

The thing variable must be in uppercase. You are 'using' the type insteand of the variable.

@keithamus
Copy link
Member

keithamus commented Jan 24, 2017

You're right @xtuc, I've updated my expected to reflect that. The salient point, however, is that the name is mangled but this is not reflected into the rest of the function. It either needs to mangle both or mangle neither; currently it mangles one.

boopathi added a commit that referenced this issue Jan 25, 2017
The issue was renaming an already renamed path. Maybe something quircky about bindings of destructuring assingments in babel.

+ (Fix #326)
+ (Fix #369)
kangax pushed a commit that referenced this issue Jan 30, 2017
The issue was renaming an already renamed path. Maybe something quircky about bindings of destructuring assingments in babel.

+ (Fix #326)
+ (Fix #369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

6 participants