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

a variable named 'filter' can be incorrectly transformed by transform-runtime plugin #10205


Copy link

@bcutler-work bcutler-work commented Jul 11, 2019

Bug Report

Current Behavior
When @babel/plugin-transform-runtime has corejs set to 3, it can incorrectly transform property access using a variable called filter. (Note: NOT the property filter.)

Actual output:

import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
var filter = 'foo';
var bar = {
  foo: function () {
    return 'foo';

Input Code

var filter = 'foo';
var bar = { foo: function() { return 'foo';}};


Expected behavior/code

Expected output: (if corejs is set to false, this is the output, as expected)

var filter = 'foo';
var bar = {
  foo: function () {
    return 'foo';

Babel Configuration

module.exports = (api) => {
  return {
    'plugins': [
      ['@babel/plugin-transform-runtime', {
        'corejs': 3,
        'regenerator': true,
        'useESModules': true


  • Babel version(s): (@babel/cli 7.5.0) (@babel/core 7.5.4) (@babel/plugin-transform-runtime 7.5.0)
  • Node/npm version: Node 10.13/npm 6.4.1/yarn 1.15.2
  • OS: OSX 10.13.6
  • Monorepo: N/A
  • How you are using Babel: cli for this example, but it was manifesting the same way with webpack

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

Copy link

@babel-bot babel-bot commented Jul 11, 2019

Hey @bcutler-work! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
that typically always has someone willing to help. You can sign-up here
for an invite.

Copy link

@nicolo-ribaudo nicolo-ribaudo commented Jul 11, 2019

If anyone wants to fix this issue, it's a problem here:

exit(path) {
if (!injectCoreJS) return;
if (!path.isReferenced()) return;
const { node } = path;
const { object } = node;
const { name } = object;
if (!hasMapping(BuiltIns, name)) return;
if (path.scope.getBindingIdentifier(name)) return;

If the MemberExpression is computed (i.e. foo[bar]), we need to bail out. We do something similar in the MemberExpression enter visitor, where we handle foo[Symbol.iterator] and then return.

Before working on this issue, please leave a comment to let others know!

If you don't know how to clone Babel, follow these steps: (you need to have make and yarn available on your machine).

  1. Write a comment there to know other possible contributors that you are working on this bug.
  2. Fork the repo
  3. Run git clone<YOUR_USERNAME>/babel.git && cd babel
  4. Run yarn && make bootstrap
  5. Wait
  6. Run make watch (or make build whenever you change a file)
  7. Add a test (only input.js; output.js will be automatically generated)
  8. Update the code!
  9. yarn jest transform-runtime to run the tests
    • If some test outputs don't match but the new results are correct, you can delete the bad output.js files and run the tests again
  10. If it is working, run make test to run all the tests
  11. Run git push and open a PR!
Copy link

@sag1v sag1v commented Jul 12, 2019

Looks interesting, i would like to try 🙂

Copy link

@nicolo-ribaudo nicolo-ribaudo commented Jul 12, 2019

Thanks! If you need any help, you can ask in our slack channel (

@sag1v sag1v mentioned this issue Jul 12, 2019
@lock lock bot added the outdated label Oct 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.