-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
v8intrinsic.ts
36 lines (33 loc) 路 1.38 KB
/
v8intrinsic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type Parser from "../parser";
import { tokenIsIdentifier, tt } from "../tokenizer/types";
import type * as N from "../types";
import type { ExpressionErrors } from "../parser/util";
export default (superClass: typeof Parser) =>
class V8IntrinsicMixin extends superClass implements Parser {
parseV8Intrinsic(): N.Expression {
if (this.match(tt.modulo)) {
const v8IntrinsicStartLoc = this.state.startLoc;
// let the `loc` of Identifier starts from `%`
const node = this.startNode<N.Identifier>();
this.next(); // eat '%'
if (tokenIsIdentifier(this.state.type)) {
const name = this.parseIdentifierName(this.state.start);
const identifier = this.createIdentifier(node, name);
// @ts-expect-error: avoid mutating AST types
identifier.type = "V8IntrinsicIdentifier";
if (this.match(tt.parenL)) {
return identifier;
}
}
this.unexpected(v8IntrinsicStartLoc);
}
}
/* ============================================================ *
* parser/expression.js *
* ============================================================ */
parseExprAtom(refExpressionErrors?: ExpressionErrors | null): N.Expression {
return (
this.parseV8Intrinsic() || super.parseExprAtom(refExpressionErrors)
);
}
};