Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: v8intrinsic syntax plugin 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. * feat: disable combining placeholders and v8intrisic per #10104 (comment) * test: add more error cases * refactor: parse v8 intrinsic in parseExprAtom This approach is identical to V8鈥檚 implementation. Move the test cases as the behaviour changes. * fix: plugin-name typo * test: add yield-expression test case * feat: require startsExpr on modulo for v8intrinsic * perf: skip eof and braceR check as they must return false * Print V8IntrinsicIdentifier * feat: add v8intrinsic to parser typings * Add generated type helpers * fix: incorrect type definition * fix: allow V8IntrinsicIdentifier to be callee
- Loading branch information
1 parent
b02e35c
commit da0af5f
Showing
38 changed files
with
961 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/misc/V8IntrinsicIdentifier/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%DebugPrint(foo); |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/misc/V8IntrinsicIdentifier/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["v8intrinsic"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/misc/V8IntrinsicIdentifier/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%DebugPrint(foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type Parser from "../parser"; | ||
import { types as tt } from "../tokenizer/types"; | ||
import * as N from "../types"; | ||
|
||
export default (superClass: Class<Parser>): Class<Parser> => | ||
class extends superClass { | ||
parseV8Intrinsic(): N.Expression { | ||
if (this.match(tt.modulo)) { | ||
const v8IntrinsicStart = this.state.start; | ||
// let the `loc` of Identifier starts from `%` | ||
const node = this.startNode(); | ||
this.eat(tt.modulo); | ||
if (this.match(tt.name)) { | ||
const name = this.parseIdentifierName(this.state.start); | ||
const identifier = this.createIdentifier(node, name); | ||
identifier.type = "V8IntrinsicIdentifier"; | ||
if (this.match(tt.parenL)) { | ||
return identifier; | ||
} | ||
} | ||
this.unexpected(v8IntrinsicStart); | ||
} | ||
} | ||
|
||
/* ============================================================ * | ||
* parser/expression.js * | ||
* ============================================================ */ | ||
|
||
parseExprAtom(): N.Expression { | ||
return this.parseV8Intrinsic() || super.parseExprAtom(...arguments); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-bind-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::%DebugPrint(null) |
6 changes: 6 additions & 0 deletions
6
packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-bind-expression/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"v8intrinsic" | ||
], | ||
"throws": "Unexpected token (1:0)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-member-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a.%DebugPrint(); |
6 changes: 6 additions & 0 deletions
6
packages/babel-parser/test/fixtures/v8intrinsic/_errors/in-member-expression/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"v8intrinsic" | ||
], | ||
"throws": "Unexpected token (1:2)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/_errors/no-plugin/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%DebugPrint(foo) |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/v8intrinsic/_errors/no-plugin/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": [], | ||
"throws": "Unexpected token (1:0)" | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/babel-parser/test/fixtures/v8intrinsic/_errors/not-in-call-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const i = %DebugPrint; | ||
i(foo); |
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/v8intrinsic/_errors/not-in-call-expression/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["v8intrinsic"], | ||
"throws": "Unexpected token (1:10)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/_errors/optional-call-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%DebugPrint?.(null) |
7 changes: 7 additions & 0 deletions
7
...ages/babel-parser/test/fixtures/v8intrinsic/_errors/optional-call-expression/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
"optionalChaining", | ||
"v8intrinsic" | ||
], | ||
"throws": "Unexpected token (1:0)" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/expression/await-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
async () => { await %StringParseInt("42", 10) } |
191 changes: 191 additions & 0 deletions
191
packages/babel-parser/test/fixtures/v8intrinsic/expression/await-expression/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 47 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 47 | ||
} | ||
}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start": 0, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 47 | ||
} | ||
}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start": 0, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 47 | ||
} | ||
}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start": 12, | ||
"end": 47, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 12 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 47 | ||
} | ||
}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start": 14, | ||
"end": 45, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 14 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 45 | ||
} | ||
}, | ||
"expression": { | ||
"type": "AwaitExpression", | ||
"start": 14, | ||
"end": 45, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 14 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 45 | ||
} | ||
}, | ||
"argument": { | ||
"type": "CallExpression", | ||
"start": 20, | ||
"end": 45, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 45 | ||
} | ||
}, | ||
"callee": { | ||
"type": "V8IntrinsicIdentifier", | ||
"start": 20, | ||
"end": 35, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 20 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 35 | ||
}, | ||
"identifierName": "StringParseInt" | ||
}, | ||
"name": "StringParseInt" | ||
}, | ||
"arguments": [ | ||
{ | ||
"type": "StringLiteral", | ||
"start": 36, | ||
"end": 40, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 36 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 40 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": "42", | ||
"raw": "\"42\"" | ||
}, | ||
"value": "42" | ||
}, | ||
{ | ||
"type": "NumericLiteral", | ||
"start": 42, | ||
"end": 44, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 42 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 44 | ||
} | ||
}, | ||
"extra": { | ||
"rawValue": 10, | ||
"raw": "10" | ||
}, | ||
"value": 10 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/v8intrinsic/expression/call-expression/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%DebugPrint(foo) |
Oops, something went wrong.