Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

export default function has null id, but spec says id must not be null #502

Closed
ghost opened this issue May 2, 2017 · 5 comments
Closed
Labels

Comments

@ghost
Copy link

ghost commented May 2, 2017

Input Code

export default function() {}

Babylon Use

const babylon = require("babylon");
const src = "export default function() {}";
const ast = babylon.parse(src, { sourceType: "module" });
console.log(JSON.stringify(ast.program.body[0], undefined, 2));

Expected Behavior

Either:

  • This should be parsed as a FunctionExpression.
  • FunctionDeclaration may have a null id.

Current Behavior

Spec declares that FunctionDeclaration must not have a null id.

But in the output:

"declaration": {
  "type": "FunctionDeclaration",
  ...
  "id": null,
  ...
}

Your Environment

software version
Babylon 7.0.0-beta.8
node 7.9.0
npm 4.2.0
Operating System Linux Mint 18

Related: #257

@hzoo
Copy link
Member

hzoo commented May 2, 2017

Hey @andy-ms! 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.

@loganfsmyth
Copy link
Member

Definitely a spec bug. FunctionDeclarations are allowed to not have an ID, but only when nested in an ExportDefaultDeclaration.

@loganfsmyth
Copy link
Member

Parsing as a FunctionExpression would change the hoisting behavior and potentially break circular dependencies.

@hzoo
Copy link
Member

hzoo commented May 2, 2017

I believe I just didn't change the spec in babylon or estree either. estree/estree#98 (comment)

@hzoo
Copy link
Member

hzoo commented May 18, 2017

#503

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants