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
Use Strict Directive needs to be preflighted #149
Comments
Should be an easy fix? What about using the mutual parser flag for this if in function body, and if on top level use a variable outside the loop. |
I didn't follow. When passing |
Give me 30 min to come up with a solution |
It's an octal so you simply add a mutual parser flag in the number scanner and other places where octals occur. Note You need to reset that flag for each time you do the token dispatch. Soon as you have the mutual parser flag, try something like this let seenOctal = false;
while (parser.token === Token.StringLiteral) {
expr = parseLiteral(parser, context);
// "use strict" must be the exact literal without escape sequences or line continuation.
if ( VALID STRICT MODE CODE {
if (seenOctal === 1) // TODO! Throw an error
context |= Context.Strict;
} else {
if (seenOctal === 0 && (parser.flags & Flags.Octals) === Flags.Octals) {
seenOctal = 1; // We seen it, but no strict mode yet
}
}
// .... Rest of the code
} Note This can be tweaked for performance Update I'm not even sure you would need the extra |
It's not just octal, there are many other failures in strict mode need to be handled. Browser might re-parse the whole function scope when strict mode is changed at middle of the function scope. |
I don't understand why ecma did not enforce directive to be only allowed at top of a function scope. |
Open an ticket in the ECMA specs repo |
Just noticed tenko did very well for this case. And I found out bit more in nodejs
You see, when There must be something explicit in ecma spec... BTW for reference, leading "use strict" is always in effect as we expected.
|
What about copy Tenko on that part? Not sure about the regex but.. |
I will try to decipher ecma spec first. That adjacency is weird. |
In my own language (I invented a language similar to TS, but faster), I'm skipping WS first, and then I do the directive scanning with tons of bitmasks. That way I can add a diagnostic (throw an error) with bitmasks fiddling, and the issue you mentioned before is non-existing. I'm not even using the scanner code. This because the entire code is structured as an optimized finite state machine. There is no concern of nested productions because I'm only validating strings (not even parsing them), aborting with everything else. And the validation will not happen unless a single or double quote has been seen (start of string literal). After I reset to "normal state" and do the normal parsing. |
The first case is due to In the second case, The third case confirmed In short, `"use strict" can appear in any location of the whole "A Directive Prologue", it can affect directives (string literal expression) before it. ECMA did enforce the location of directives. |
so, easy fix? |
I am not going to try, at least for now. |
For record, the disabled test262 tests. meriyah/test/test262-parser-tests/parser-tests.ts Lines 22 to 25 in a903f27
|
Found this issue while cleaning up test262 file, not sure if this is possible in meriyah.
It's not a serious bug in real world, as people always put use strict directive at beginning of a scope.
Meriyah rejects following code as per spec:
But failed to do so if the use strict directive is after the problematic code.
The text was updated successfully, but these errors were encountered: