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-transform-es2015-function-name should not create function names with reserved words. (T7235) #4198

Closed
babel-bot opened this issue Mar 22, 2016 · 7 comments · Fixed by #4954
Labels
area: upstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Milestone

Comments

@babel-bot
Copy link
Collaborator

Issue originally made by @Hypercubed

Bug information

  • Babel version: 6.6.5
  • Node version: 4.2.3
  • npm version: 3.5.2

Options

babel-plugin-transform-es2015-function-name via babel-preset-es2015 via babel-preset-es2015-rollup

Input code

Input:

export const test = {
  await: a => 2 * a
}

Output:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var test = exports.test = {
  await: function await(a) {
    return 2 * a;
  }
};

Description

await is a reserved word (when found in module code). It is valid in the input as an object property but invalid in the output as the function name.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @Hypercubed

Some discussion here: rollup/rollup#564

@babel-bot
Copy link
Collaborator Author

Comment originally made by @Hypercubed

Is it possible to confirm this is a bug or not? Currently, I'm using the following to avoid generating an invalid function name:

export const test = {
  [`await`]: a => 2 * a
}

This also works:

export const test = {
  await: function _(a) { return 2 * a; }
}

@babel-bot
Copy link
Collaborator Author

Comment originally made by @loganfsmyth

We could probably debate either way on for the code output, but it'd probably be better to err on the side of compatibility, so we should update out reserved word logic to avoid this.

On the other side, Babylon appears to parse await as an identifier, even with sourceType: 'module' which is definitely a bug, but would probably count as a breaking change so we'd have to wait for a major version bump to do that.

@danez
Copy link
Member

danez commented Sep 20, 2016

I filled estools/esutils#24 to fix this.

@sateffen
Copy link

sateffen commented Feb 8, 2017

bump - Still not merged, even though the merge-requests looks good. This is an anoying bug when using babel with d3.

@hzoo
Copy link
Member

hzoo commented Mar 17, 2017

We should just land #4954 or do it ourselves then?

@hzoo hzoo added this to the Babel 7 milestone Mar 17, 2017
@hzoo
Copy link
Member

hzoo commented Mar 19, 2017

#4952 landed in master, need to release

@hzoo hzoo closed this as completed Mar 19, 2017
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: upstream i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants