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
V8intrinsic syntax plugin #10148
V8intrinsic syntax plugin #10148
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11486/ |
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 was thinking that maybe we can remove this.state.V8IntrinsicStart
and put all the parsing logic in a single method: we can overwrite parseExprAtom
and add something like this:
- If eat %%,
i. Parse an identifier
ii. Set that identifier'stype
toV8IntrinsicIdentifier
iii. If the upcoming token isn't(
, throw an error - Else, return
super.parseExprAtom
.
This is similar to what we do for super()
and import()
.
packages/babel-parser/test/fixtures/v8intrinsic/expression/await-expression/input.js
Show resolved
Hide resolved
I agree, actually my first attack is on rewriting
Great observation! The |
Thanks for your work on this!
That's correct. Here's how V8 implements parsing support based on the flag. |
packages/babel-parser/test/fixtures/v8intrinsic/_errors/not-in-call-expression/input.js
Outdated
Show resolved
Hide resolved
The implementation of V8 parsing However as I have rewritten the plugin and now it closely follow the way how V8 parse. I have added this |
I've talked to Nicolo offline a bit. Here we add
|
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.
Awesome!
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.
👍
@nicolo-ribaudo: Is this waiting for a release, or can it be merged? |
We just released v7.5 so this is waiting for the next minor, but if it is urgent we could do it earlier than the usual time between two minor releases. |
096c337
to
6bba3c9
Compare
3c4fd6c
to
e16be2e
Compare
5c75a05
to
a0dcb31
Compare
@@ -19,3 +23,12 @@ defineType("Placeholder", { | |||
}, | |||
}, | |||
}); | |||
|
|||
defineType("V8IntrinsicIdentifier", { |
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 just realized that we should add this to the allowed callee
s of CallExpression
3333b03
to
67d6c2a
Compare
Implement V8 Intrinsic Syntax Extension. Here we check the execution branch inside the parseSubscript to make sure the V8IntrinsicIdentifier is immediately followed by a call expression.
Authored a new syntax plugin
v8intrinsic
to support V8 CallRuntime syntaxThe original implementation in V8 parser
peek()
twice to check whether amodulo
token is immediately followed by an identifier and aparenL
token.As in Babel
lookahead()
does not support multiple steps, here we implicitly track the execution branch insideparseSubscript
to see ifparseCallExpressionArguments
is immediately called in the first round ofparseExprSubscripts
. If so we conclude that the modulo token is a valid V8Intrinsic marker.It is also interesting to note that a V8Intrinsic call inside a new expression does not raise a SyntaxError in V8. i.e.
@mathiasbynens I don't think there are any V8 intrinsics supposed to work with new expression, aren't there?
If so, it should be reasonable to prevent v8intrisic from new expression, as is the behavior of this plugin. Otherwise we still need to take care on the new expression.
Action Items
v8intrinsic
to babel-parser typings after updated ParsePlugin type definition #10259 gets merged.