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

Does not properly handle object destructuring #326

Closed
hatched opened this issue Dec 6, 2016 · 1 comment
Closed

Does not properly handle object destructuring #326

hatched opened this issue Dec 6, 2016 · 1 comment
Labels
bug Confirmed bug
Projects

Comments

@hatched
Copy link

hatched commented Dec 6, 2016

Using:

"babel-cli": "^6.18.0",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-preset-babili": "0.0.9",
Node 6.2.0
      const min = babel.transform(data, {
        presets: ['babel-preset-babili'],
        plugins: ['transform-react-jsx'],
        compact: true,
        comments: false
      });

The following code:

    if (parts.includes(PATH_DELIMETERS.get('user'))) {
      ({state, parts, error} = this._parseUser(parts, state));
      if (error !== null) {
        error = `cannot parse the User path: ${error}`;
        return {error, state};
      }
    }

gets converted to the following. You'll notice that both parts and error are j.

        if (j.includes(PATH_DELIMETERS.get('user')) && (( { state : h , parts : j , error : j } = this._parseUser(j, h)),
        null !== g))
            return g = `cannot parse the User path: ${g}`,
            {
                error: g,
                state: h
            };

Removing the object destructuring corrects the problem.

    if (parts.includes(PATH_DELIMETERS.get('user'))) {
      let parsed = this._parseUser(parts, state);
      state = parsed.state;
      parts = parsed.parts;
      error = parsed.error;
      if (error !== null) {
        error = `cannot parse the User path: ${error}`;
        return {error, state};
      }
    }
        if (j.includes(PATH_DELIMETERS.get('user'))) {
            let n = this._parseUser(j, h);
            if (h = n.state,
            j = n.parts,
            g = n.error,
            null !== g)
                return g = `cannot parse the User path: ${g}`,
                {
                    error: g,
                    state: h
                }
        }

This has also happened in other places in the script where there was destructuring.

@boopathi
Copy link
Member

boopathi commented Dec 6, 2016

Interesting. A mangler bug. I'll take a look.

Snippet reproducing the error -

function a() {
    let foo, bar, baz;
    ({foo, bar, baz} = {});
    return {foo, bar, baz};
}

output:

function a(){
  let b,c,d;
  return({ foo: d, bar: c, baz: d } = {}), { foo: b, bar: c, baz: d };
}

@boopathi boopathi added the bug Confirmed bug label Dec 6, 2016
boopathi added a commit that referenced this issue Dec 22, 2016
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)
@boopathi boopathi moved this from Mangler issues to Done in Mangler Jan 30, 2017
boopathi added a commit that referenced this issue Jan 31, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 2, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 3, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 3, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 12, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 16, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 16, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 16, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue Feb 17, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
vigneshshanmugam pushed a commit to vigneshshanmugam/babili that referenced this issue Mar 3, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - babel#326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue May 8, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue May 8, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue May 21, 2017
ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option
boopathi added a commit that referenced this issue May 22, 2017
* Reuse removed vars in mangler

ResetNext identifier only when reuse is true

Fix tests - add keepClassName

Reuse vars as default

I dont know why it works - #326

Extract tracker to a separate file, Add topLevel Option

* BFS traverse

* Fix scope tracking

* Fix tests

* Fix mangle blacklist tests

* Fix formatting

* Remove unnecessary preset tests

* Add JSDoc Comments and update Error messages

* Remove duplicate tests

* Fix Error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
No open projects
Development

No branches or pull requests

2 participants