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

0.4.2 breaks - passes invalid data to babel-helper-evaluate-path #845

Closed
swernerx opened this issue May 14, 2018 · 9 comments · Fixed by #846 or #848
Closed

0.4.2 breaks - passes invalid data to babel-helper-evaluate-path #845

swernerx opened this issue May 14, 2018 · 9 comments · Fixed by #846 or #848
Labels
bug Confirmed bug

Comments

@swernerx
Copy link

Describe the bug

To Reproduce

Minimal code to reproduce the bug

export class Component extends Other {
  constructor() {
    super()
    this.flag = true
  }

  main() {
    alert(this.foo)
  }
}

Actual Output

Nothing!

Expected Output

Output when disabling minify preset:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Component = void 0;

class Component extends Other {
  constructor() {
    super();
    this.flag = true;
  }

  main() {
    alert(this.foo);
  }

}

exports.Component = Component;

Stack Trace

If applicable,

TypeError: stmts.entries is not a function
    at compareBindingAndReference (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:252:32)
    at evaluateBasedOnControlFlow (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:213:27)
    at evaluateIdentifier (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:119:26)
    at evaluate (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:21:12)
    at PluginPass.Expression (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-plugin-minify-constant-folding/lib/index.js:165:21)
    at PluginPass.newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:286:17)
    at newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:243:21)
    at NodePath._call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:65:18)
    at NodePath.call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:100:12)

Configuration

How are you using babel-minify?

Directly from the CLI.

babel-minify version: 0.4.2
babel version : 7.0.0-beta.46
babel-minify-config: None

babelrc:

{
 "presets": [
   [ "@babel/env", { "targets": { "node": '6.9.0', "browsers": [] } } ],
   "minify"
  ]
}
@swernerx
Copy link
Author

swernerx commented May 14, 2018

Probably related: Adding preset-react:

.babelrc:

{
  "presets": [
    [ "@babel/env", { "targets": { "node": '6.9.0', "browsers": [] } } ],
    "@babel/react",
    "minify"
  ]
}

Code:

class MyComponent {
}

MyComponent.propTypes = {
  userName: 123
}

Exception:

TypeError: Cannot read property 'isIfStatement' of null
    at evaluateBasedOnControlFlow (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:199:32)
    at evaluateIdentifier (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:119:26)
    at evaluate (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:21:12)
    at PluginPass.Expression (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-plugin-minify-constant-folding/lib/index.js:165:21)
    at PluginPass.newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:286:17)
    at newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:243:21)
    at NodePath._call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:65:18)
    at NodePath.call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:100:12)
    at TraversalContext.visitQueue (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/context.js:144:16)

@swernerx
Copy link
Author

swernerx commented May 14, 2018

Both issues are new with the release of 0.4.2.

@swernerx
Copy link
Author

Using the CLI with the output of preset-env it also fails:

node_modules/.bin/babel-minify error-env.js
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Component = void 0;

class Component extends Other {
  constructor() {
    super();
    this.flag = true;
  }

  main() {
    alert(this.foo);
  }

}

exports.Component = Component;

Error Message:

TypeError: Cannot read property 'isIfStatement' of null

@swernerx
Copy link
Author

Can be reduced further by using this input code:

exports.Component = void 0;

class Component {
}

exports.Component = Component;

This produces the same error when using the CLI.

@swernerx
Copy link
Author

swernerx commented May 14, 2018

When using 0.4.1 for these packages it seems to work:

  • babel-minify
  • babel-helper-evaluate-path
  • babel-plugin-minify-constant-folding

Unfortunately because the patch update it still fails without the last two. NPM still "normalizes" to 0.4.2 in some deeper dependencies.

swernerx added a commit to sebastian-software/babel-preset-edge that referenced this issue May 14, 2018
@boopathi boopathi added the bug Confirmed bug label May 14, 2018
@boopathi
Copy link
Member

Thanks for reporting. I released another patch - 0.4.3 which addresses this issue.

@swernerx
Copy link
Author

Unfortunately this does not seem to be the case. Only one of the exceptions is gone. This one is still there:

TypeError: Cannot read property 'isIfStatement' of null

      at evaluateBasedOnControlFlow (node_modules/babel-helper-evaluate-path/lib/index.js:159:32)
      at evaluateIdentifier (node_modules/babel-helper-evaluate-path/lib/index.js:117:26)
      at evaluate (node_modules/babel-helper-evaluate-path/lib/index.js:19:12)
      at PluginPass.Expression (node_modules/babel-plugin-minify-constant-folding/lib/index.js:165:21)
      at PluginPass.newFn (node_modules/@babel/traverse/lib/visitors.js:274:17)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:237:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:65:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:40:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:100:12)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:142:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:102:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:182:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:106:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:107:18)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:142:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:102:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:182:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:106:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:107:18)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:142:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:102:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:182:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:106:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:107:18)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:142:16)
      at TraversalContext.visitMultiple (node_modules/@babel/traverse/lib/context.js:97:17)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:180:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:106:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:107:18)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:142:16)
      at TraversalContext.visitSingle (node_modules/@babel/traverse/lib/context.js:102:19)
      at TraversalContext.visit (node_modules/@babel/traverse/lib/context.js:182:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/@babel/traverse/lib/index.js:106:17)
      at traverse (node_modules/@babel/traverse/lib/index.js:76:12)
      at transformFile (node_modules/@babel/core/lib/transformation/index.js:116:29)
      at runSync (node_modules/@babel/core/lib/transformation/index.js:45:3)
      at runAsync (node_modules/@babel/core/lib/transformation/index.js:35:14)
      at node_modules/@babel/core/lib/transform-file.js:56:36
      at node_modules/graceful-fs/graceful-fs.js:78:16

Executed on all the new versions. Seems to be related to some different code though. Still investigating...

@swernerx
Copy link
Author

swernerx commented May 15, 2018

Code:

class MyComponent {
}

MyComponent.propTypes = {
}

.babelrc

"presets": [
  "babel-preset-minify",
  "@babel/react",
  "@babel/env"
]

Error:

npx babel z.js
TypeError: Cannot read property 'isIfStatement' of null
    at evaluateBasedOnControlFlow (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:159:32)
    at evaluateIdentifier (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:117:26)
    at evaluate (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-helper-evaluate-path/lib/index.js:19:12)
    at PluginPass.Expression (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/babel-plugin-minify-constant-folding/lib/index.js:165:21)
    at PluginPass.newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:274:17)
    at newFn (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/visitors.js:237:21)
    at NodePath._call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:65:20)
    at NodePath.call (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/path/context.js:100:12)
    at TraversalContext.visitQueue (/Users/swerner/Workspace/sebastian-software/babel-preset-edge/node_modules/@babel/traverse/lib/context.js:142:16)

When disabling "evaluate" it works:

["babel-preset-minify", {"evaluate":false}],

Output:

"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var MyComponent=function a(){_classCallCheck(this,a)};MyComponent.propTypes={};

swernerx added a commit to sebastian-software/babel-preset-edge that referenced this issue May 15, 2018
…r too risky/tricky to use here. See also: babel/minify#845 (comment)

Probably the bug is related to separately activating/disabling specific features of the minifier.
@vigneshshanmugam
Copy link
Member

@swernerx Forgot to handle the case for var bindings. Thanks for pointing out. Fixed properly with #848

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
3 participants