-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
ast: directive-prologue #8219
Comments
function f() {
'use strict';
} Are you saying that the AST for this function's body should look like this?
If so, in my opinion, I don't think we need to do that in order to remain compliant with the spec. My reading of the passage you linked to is that:
But what it doesn't say is how the Directive Prologue needs to be stored internally in the engine. All it says is:
So I think we are compliant. OK, we're storing directives as Sorry if I've completely misinterpreted what you're saying and have got confused! |
I agree that oxc isn't actually breaking with the spec here. The relevant part of the spec is this:
This isn't really directly relevant to parsers, only for engines themselves. And since oxc does expose this data, everything is technically fine and correct. The only question is whether this is a good API or not. First, from an engine point of view I need to add a conditional path for this (though that's not too bad, really) and it's a fairly obscure thing to discover. From an AST transformer point of view, the same obscurity might become a real source of bugs: Any transformer should remember to check and copy the directives (at least a use-strict directive) during their transform separately from the normal AST work. If they forget it, the code they produce may end up deoptimised or even subject to sloppy-mode related security vulnerabilities. From a memory point of view I wonder if this makes sense either: You need a whole extra Vec for the directives. If the directives were at the beginning of the body, you could replace the Vec with a single u8 that tells how many directives there are at the beginning. |
This is a good point. Most functions have no directives, so we are using 32 bytes in every There are also other convoluted ways to save space e.g. store directives in a Note: The fastest way to determine whether some code is strict mode or not is to check the |
TLDR: Personally, I prefer it as it is now. If we agree that it's spec-compliant, then the question (as you say) is what's the best API. Currently we represent directives as a type called |
Changing the AST shape is too interruptive at this point. Nova can workaround this limitation with an additional code path. Close as not planned :-( |
https://tc39.es/ecma262/#directive-prologue
Oxc AST does not conformance to this definition.
Oxc produces
it should be at least
The text was updated successfully, but these errors were encountered: