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
Fix parser strictMode
option
#13548
Fix parser strictMode
option
#13548
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ffe9d58:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this option, but yeah let's at least make it behave correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update TypeScript definition file for this option.
Uh well, it was already defined as an optional |
Oh sorry I missed it |
Thanks for merging! |
The
strictMode
option toparse()
does not behave as described in the docs.The docs say:
The actual behavior is
strict = options.strictMode === false ? false : options.sourceType === "module";
Setting the option to
true
has no effect - contradicting what it says in docs.This PR fixes this so the option behaves as documented, while also preserving the current (undocumented) behavior of allowing
strictMode: false
to overridesourceType: 'module'
.I have opted to check for
true
andfalse
explicitly and ignore any other values for the option, rather than accepting other truthy/falsy values. This is intended to make this change less likely to cause unexpected breakage for incorrect configurations e.g.strictMode: "sloppy"
. But I think anyone who has explicitly saidstrictMode: true
clearly wants that!By the way, this option is useful in some cases. I ran into it because was trying to parse code that was being run in an
eval()
which is nested within strict mode code. So it should be parsed as strict mode, but not as a module as there's noimport
insideeval()
.