Giter VIP home page Giter VIP logo

Comments (5)

caridy avatar caridy commented on May 17, 2024

no, there is not need to look ahead because function means function declaration with or without a name, in which case the first one will fail, while the second one will pass.

IIRC the implementation in esprima does a lookahead but just to determine whether the function has a name or not.

The same applies to all other variants.

from ecmascript-more-export-from.

spket avatar spket commented on May 17, 2024

Then maybe it should made clear in Spec, for example like:

export default [lookahead ! {function, class, from}] AssignmentExpression[In] ;

from ecmascript-more-export-from.

caridy avatar caridy commented on May 17, 2024

no, the spec is clear on that regards. the fact that we do so in esprima is just an implementation detail to reuse the function declaration parser, but in the spec a function without a name is very well defined. You can find a lot of discussion around that topic in esdiscuss and espree repo.

from ecmascript-more-export-from.

spket avatar spket commented on May 17, 2024

It's not about function declaration...

export IdentifierName from module

is conflict with

export Declaration

when IdentifierName is function/class/let/const, and conflict with

export VariableStatement

when IdentifierName is var

and why use esprima as example? I just check it's source code, it does not even support additional export from statements in ES 7?

from ecmascript-more-export-from.

leebyron avatar leebyron commented on May 17, 2024

Look ahead restrictions in grammars are necessary to remove ambiguity, but there is no ambiguity here. Your first example is unambiguously an export-from and your second example is unambiguously an exported function.

Parser implementations need to look ahead to know what paths to take. In an LR(1) grammar, rules are designed to only require a single token look ahead in order to know which path to take, which is maybe what you were referring to here. However JavaScript is not an LR(1) grammar as there are already other cases in the language where a further look ahead is required. In this case, after lexing "function" and two paths are possible, a look ahead of two tokens is necessary.

from ecmascript-more-export-from.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.