GithubHelp home page GithubHelp logo

What about directives? about proposal-binary-ast HOT 7 OPEN

tc39 avatar tc39 commented on May 23, 2024
What about directives?

from proposal-binary-ast.

Comments (7)

syg avatar syg commented on May 23, 2024 2

@ljharb The conservative option is as you say: to treat the presence of directives as an annotation, like the proposed solution for storing scope info. That is, the extra bit will be validated. If the bit for strict mode is set and no "use strict" shows up in the AST, an error is thrown.

AIUI @littledan is proposing a slightly more radical approach of treating the bit as the source of truth. I am fine with this personally given that directives already feel extra-linguistic, though it does deviate from the guiding principle of "encode as little extra semantic info as possible, just properties of the AST".

from proposal-binary-ast.

littledan avatar littledan commented on May 23, 2024 1

This is a source of complexity in V8's parser as well (except we track the potential errors all the time, to avoid backtracking ever). Could the AST pre-parse "use strict" and instead set a bit on the function and not represent the string directly anymore?

from proposal-binary-ast.

Yoric avatar Yoric commented on May 23, 2024 1

Ah, I realize that the Babel AST already specifies a field

   directives: [Directive]

where Directive is basically a string literal. So, since we're following Babel for the moment, let's use it as is.

from proposal-binary-ast.

fabiosantoscode avatar fabiosantoscode commented on May 23, 2024 1

Forcing strict mode and foregoing this discussion for now would also be a great thing. Whatever smashes the with statement.

from proposal-binary-ast.

syg avatar syg commented on May 23, 2024

@littledan Sounds like a good idea to me!

from proposal-binary-ast.

ljharb avatar ljharb commented on May 23, 2024

(the string should still show up in the AST tho, even if there's a precomputed bit, no?)

from proposal-binary-ast.

Yoric avatar Yoric commented on May 23, 2024

On a technical note, I'm not sure that a single bit is the most future-proof manner of handling this. After all, I seem to remember that at least V8 and SpiderMonkey have experimented with additional directives.

So I'd be tempted to add a property

   directive: string | null

to both Function and Program (our AST root).

from proposal-binary-ast.

Related Issues (20)

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.