Skip to content

parameter spread on import results in usage of undeclared variable #6647

Closed

Description

@jeysal

Bug Report

In the current 7.0.0-beta.5, a combination of parameter spread and an imported variable causes usage of an undeclared variable as the first argument to apply due to a missing variable name substitution

Input Code

import abc from 'abc';
const arr = [1, 2, 3];
abc.xyz(...arr);

Babel Configuration (.babelrc, package.json, cli command)

Used REPL. Also tested locally with:

npx babel --preset=env index.js
{
  "presets": [
    [
      "env or @babel/preset-env, depending on beta version",
      {
        "useBuiltIns": "usage",
        "targets": {
          "browsers": ["> 2%"]
        }
      }
    ]
  ],
  "plugins": []
}

Expected Behavior

Something equivalent to this output from 6.26.0 (value of the default import passed as first argument to apply)
https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=JYWwDg9gTgLgBAQwEYGM4DMoRHA5MlXAbgCgUIA7AZ3gSijgF44BtARgBo4AmLgZgC6pAgDoAHgE8AXgAoR8ulACUpIA&debug=false&circleciRepo=&evaluate=false&lineWrap=true&presets=es2015%2Creact%2Cstage-2&targets=&version=6.26.0

Current Behavior

Variable name not substituted => undeclared variable passed as first argument to apply => error
https://babeljs.io/repl/build/5552#?babili=false&browsers=&build=&builtIns=false&code_lz=JYWwDg9gTgLgBAQwEYGM4DMoRHA5MlXAbgCgUIA7AZ3gSijgF44BtARgBo4AmLgZgC6pAgDoAHgE8AXgAoR8ulACUpIA&debug=false&circleciRepo=&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&version=7.0.0-beta.5

Your Environment

In addition to the REPL, I've tested this with the CLI.
7.0.0-beta.1 still works: _abc2.default.xyz.apply(_abc2.default, arr);
7.0.0-beta.2 is broken: _abc.default.xyz.apply(abc, arr);

Activity

  1. babel-bot commented on Oct 31, 2017

    @babel-bot
    Collaborator

    Hey @jeysal! 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
    community that typically always has someone willing to help. You can sign-up here
    for an invite.

  2. hzoo commented on Nov 1, 2017

    @hzoo
    Member

    Minimal repro link (even in loose mode)

    import a from 'a';
    a.preview(...c);
    var _a = _interopRequireDefault(require("a"));
    _a.default.preview.apply(a, c); // a instead of `_a.default`

    This is caused by PR #6230, here's the repl link for build 4885

  3. added
    outdated
    on May 4, 2018
  4. locked as resolved and limited conversation to collaborators on May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.x: regressionHas PRoutdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions