Huáng Jùnliàng 178d43ff17
Tokenize keywords-like identifier as new tokens (#13769)
* refactor: add more identifier token helpers

* refactor: explode tt.name into multiple tokens

* fix: disallow escape in interface keyword

* refactor: simplify isMaybeDefaultImport

* review comments

* refactor: avoid string comparison
2021-09-23 10:54:44 -04:00

33 lines
1.2 KiB
JavaScript

import type Parser from "../parser";
import { tokenIsIdentifier, 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.next(); // eat '%'
if (tokenIsIdentifier(this.state.type)) {
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);
}
};