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.
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'stypetoV8IntrinsicIdentifier
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
|
|
@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
| }, | ||
| }); | ||
|
|
||
| defineType("V8IntrinsicIdentifier", { |
There was a problem hiding this comment.
I just realized that we should add this to the allowed callees 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.
This approach is identical to V8’s implementation. Move the test cases as the behaviour changes.
67d6c2a to
c1a3cbf
Compare
Authored a new syntax plugin
v8intrinsicto support V8 CallRuntime syntaxThe original implementation in V8 parser
peek()twice to check whether amodulotoken is immediately followed by an identifier and aparenLtoken.As in Babel
lookahead()does not support multiple steps, here we implicitly track the execution branch insideparseSubscriptto see ifparseCallExpressionArgumentsis 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
v8intrinsicto babel-parser typings after updated ParsePlugin type definition #10259 gets merged.