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

Minify throws TypeError when minifying if with return statement in it. #967

Closed
jackmaw opened this issue Nov 6, 2019 · 14 comments
Closed

Comments

@jackmaw
Copy link

jackmaw commented Nov 6, 2019

Describe the bug

Hi everyone, i'm using @babel/core 7.6.0 and babel-minify 0.5.1 and i got TypeError, trying minifying code provided below:

To Reproduce

Minimal code to reproduce the bug

function foo(bar) {
    if (bar) {
        return 'baz';
    }
}

Actual Output

TypeError: unknown: Cannot set property inList of [object Object] which has only a getter
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test-minify: `minify ./src/components/ActionsBox.js --outFile mActionBox.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test-minify script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

How are you using babel-minify

minify ./src/components/ActionsBox.js --outFile mActionBox.js

Also, can be reproduced in babljs.io: https://babeljs.io/repl/#?babili=true&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABMOcAUAjAhgJwJSIDeAUAJAzCKa4EmL2Kk4CmUIOS2AXgNzEOIAvsUFA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=babili&prettier=false&targets=&version=7.7.1&externalPlugins=

{
  plugins: [],
  presets: []
}

Possible solution

Error is somewhere in babel-plugin-minify-simplify, when i disable this plugin minifying works, but i cant do that for every dependency and i think that minifying should just work for that case.

@fabienrohrer
Copy link

I just run into the same issue after updating my build system, caused by this line:

https://github.com/babel/minify/blob/master/packages/babel-plugin-minify-simplify/src/index.js#L557

@fabienrohrer
Copy link

If I replace this problematic line, without understanding what I do, but it seems more logical regarding to the code, then it's working:

// path.get("body")[0].inList = false;
node.body[0].inList = false;

@GrimaceOfDespair
Copy link

This started happening to us since yesterday noon. Still digging into any library dependency update that might cause this.

@GrimaceOfDespair
Copy link

Current lead: @babel/parser was released yesterday:

https://www.npmjs.com/package/@babel/parser

image

@fabienrohrer
Copy link

This issue definitively started from this release 😁
I tried to downgrade the packages unsuccessfully.

@GrimaceOfDespair
Copy link

This issue definitively started from this release
I tried to downgrade the packages unsuccessfully.

Same here. Looking into subdependencies now.

Can't find a way to list node packages by release date :/

@jackmaw
Copy link
Author

jackmaw commented Nov 6, 2019

I got this problem after migration from 6.x to 7.x, it works when i use babel-minify, or babel-preset-minify with simplify=false option, also if I rewrite given code:

function foo(bar) {
    if (bar) {
        return "baz";
    }
}

into:

function foo(bar) {
    if (bar) return "baz";
}

or:

function foo(bar) {
    let baz = undefined;
    if (bar) {
        baz = "baz";
   };

  return baz
}

it minifies code without any error.

Also if i added some test into packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-5/

actual.js

function foo(bar) {
    if(bar) {
        return 'baz';
    }
}

expected.js

function foo() {
  if (bar) return 'baz';
}

then yarn test it also works.

It's is look's like the problem is not with the plugin itself, but something doesn't work if you transpile it with babel, then you try to minify it.

I'm running out of ideas right now:(

@fabienrohrer
Copy link

I'm running out of ideas right now:(

What about my patch mentioned above: #967 (comment)

@fabienrohrer
Copy link

I just applied it in my repo: cyberbotics/webots#1069

@feross
Copy link

feross commented Nov 6, 2019

The fix appears to be in this commit: babel/babel@0f94999 which hasn't made it into a @babel/core release yet.

@hzoo - Can you release a new @babel/core to unbreak babel-minify?

(Also, unrelated to this bug, but the latest version of @babel/core, 7.7.1, doesn't appear to have made it onto npm)

@GrimaceOfDespair
Copy link

Looks like we got a fix!

image

@fabienrohrer
Copy link

wow that's great! I'm checking it right now.

@fabienrohrer
Copy link

I confirm this is working :-)

@jackmaw
Copy link
Author

jackmaw commented Nov 7, 2019

All works, after update to babel-core 7.7.2. Thank you very much for fast fix, you're the best! Since that i'm closing this issue.

@jackmaw jackmaw closed this as completed Nov 7, 2019
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

4 participants