Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

HoistableDeclaration for export default function () {} #208

Closed
caridy opened this issue Feb 6, 2015 · 9 comments
Closed

HoistableDeclaration for export default function () {} #208

caridy opened this issue Feb 6, 2015 · 9 comments

Comments

@caridy
Copy link

caridy commented Feb 6, 2015

follow up from the discussion on jquery/esprima#311

after a quick look at the source, I don't see HoistableDeclaration.

I only see this:

    // export default ...;
    if (eat(_default)) {
      var expr = parseMaybeAssign();
      if (expr.id) {
        switch (expr.type) {
          case "FunctionExpression": expr.type = "FunctionDeclaration"; break;
          case "ClassExpression": expr.type = "ClassDeclaration"; break;
        }
      }

we are missing expr.type for HoistableDeclaration.

/cc @sebmck

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

Isn't HoistableDeclaration a FunctionDeclaration?

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

This is how the syntax is defined.

HoistableDeclaration[Yield, Default] :
FunctionDeclaration[?Yield,?Default]
GeneratorDeclaration[?Yield, ?Default]

And since there's no GeneratorDeclaration as it's just a generator property defined on a FunctionDeclaration it makes HoistableDeclaration equivalent, no?

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

Ah right, you mean for anonymous functions. Does this really necessitate the addition of another node type when FunctionExpression is behaviourally equivalent in this context and can be reused?

@michaelficarra
Copy link

It'd be really unfortunate to introduce a new node type for that.

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

@michaelficarra Agreed. Adds unnecessary complications for consumers.

@caridy
Copy link
Author

caridy commented Feb 6, 2015

no, it is not equivalent because FunctionExpression is not hoisted. I suspect that for the transpiler we can desugar this:

export default function () {}

to this:

function mod$default() {}
export {mod$default as default};

this is especially important if we are going do to any folding/bundling where the order of the definitions for the cycles is important.

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

@caridy Yeah sure, but I'm arguing about representing it differently using an already existing construct.

@sebmck
Copy link
Contributor

sebmck commented Feb 6, 2015

It'd be best to keep the discussion to jquery/esprima#311

@marijnh
Copy link
Member

marijnh commented Feb 17, 2015

Given that HoistableDeclaration does not exist as a node type, I can see no reason for this issue to stay open.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants