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

babel-plugin-minify-constant-folding fails on var split = ''.split; #997

Open
hqjs opened this issue Nov 7, 2020 · 1 comment
Open

babel-plugin-minify-constant-folding fails on var split = ''.split; #997

hqjs opened this issue Nov 7, 2020 · 1 comment

Comments

@hqjs
Copy link

hqjs commented Nov 7, 2020

babel-plugin-minify-constant-folding fails on expression

var split = ''.split;
split.call('', '');

To Reproduce

Minimal code to reproduce the bug

var split = ''.split;
split.call('', '');

Stack Trace

Error: /node_modules/core-js/internals/indexed-object.js: don't know how to turn this value into a node
      at Object.valueToNode (/Users/yuri/web/hq/node_modules/@babel/types/lib/converters/valueToNode.js:87:9)
      at PluginPass.Expression (/Users/yuri/web/hq/node_modules/babel-plugin-minify-constant-folding/lib/index.js:195:26)
      at PluginPass.newFn (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/visitors.js:220:17)
      at newFn (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/visitors.js:179:21)
      at NodePath._call (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/path/context.js:55:20)
      at NodePath.call (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/path/context.js:42:17)
      at NodePath.visit (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/path/context.js:90:31)
      at TraversalContext.visitQueue (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/context.js:112:16)
      at TraversalContext.visitSingle (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/context.js:84:19)
      at TraversalContext.visit (/Users/yuri/web/hq/node_modules/@babel/traverse/lib/context.js:140:19)

Configuration

How are you using babel-minify?

babel-preset-minify trough babel API

babel-minify version: 0.5.1

babel version : 7.12.1

babel-minify-config:

{
  builtIns: false,
  deadcode: false,
  // evaluate: false, // Switching babel-plugin-minify-constant-folding off solves the problem
  mangle: false,
}
@sgtcoolguy
Copy link

Note that this exact code is found in core-js: https://github.com/zloirock/core-js/blob/cdb246f043ad0b8f3a3b35747b9e531e4b0936f5/packages/core-js/internals/indexed-object.js#L4

As a result it makes it's way into many npm packages that ship a transpiled/bundled main JS file/entry point (i.e. mocha.js).

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

2 participants