Skip to content

export loses inferred anonymous function name #5630

Closed

Description

@srajko

Choose one: is this a bug report or feature request?

Bug

Input Code

export const f1 = function () {};
export const f2 = () => {};

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

--plugins transform-es2015-modules-commonjs

Expected Behavior

To preserve inferred names of anonymous functions, I would expect:

// ...
const f1 = function () {};
exports.f1 = f1;
const f2 = () => {};
exports.f2 = f2;
// f1.name === 'f1'
// f2.name === 'f2'

Current Behavior

// ...
const f1 = exports.f1 = function () {};
const f2 = exports.f2 = () => {};
// f1.name === ''
// f2.name === ''

Context

Especially for arrow functions (since there is no explicitly named alternative), it would be very helpful to preserve the inferred function name.

Your Environment

software version(s)
Babel 6.24.1
node 7.3.0
npm 3.8.9
Operating System Windows

Activity

  1. babel-bot commented on Apr 14, 2017

    @babel-bot
    Collaborator

    Hey @srajko! 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. reopened this on Apr 19, 2017
  3. xtuc commented on Apr 19, 2017

    @xtuc
    Member

    Seems related to #5620

    cc @Kovensky

  4. Jessidhia commented on May 3, 2017

    @Jessidhia
    Member

    Hm, 5620 is about the arrow transform itself. That is already handled correctly by non-spec mode, but 5620 would fix the spec mode transform.

    This bug is about losing the arrow function name when the arrow function is not transformed, only modules is. Probably can't be fixed without using getters (spec modules), or a hack using object wrapping ({f2: () => {}}.f2).

  5. added
    outdated
    on May 4, 2018
  6. 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

    outdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions