refactor: extract tt.lt and tt.gt from tt.relation (#13892)
This commit is contained in:
@@ -727,18 +727,38 @@ export default class Tokenizer extends ParserErrors {
|
||||
}
|
||||
}
|
||||
|
||||
readToken_lt_gt(code: number): void {
|
||||
// '<>'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
let size = 1;
|
||||
readToken_lt(): void {
|
||||
// '<'
|
||||
const { pos } = this.state;
|
||||
const next = this.input.charCodeAt(pos + 1);
|
||||
|
||||
if (next === code) {
|
||||
size =
|
||||
code === charCodes.greaterThan &&
|
||||
this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan
|
||||
? 3
|
||||
: 2;
|
||||
if (this.input.charCodeAt(this.state.pos + size) === charCodes.equalsTo) {
|
||||
if (next === charCodes.lessThan) {
|
||||
if (this.input.charCodeAt(pos + 2) === charCodes.equalsTo) {
|
||||
this.finishOp(tt.assign, 3);
|
||||
return;
|
||||
}
|
||||
this.finishOp(tt.bitShift, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (next === charCodes.equalsTo) {
|
||||
// <=
|
||||
this.finishOp(tt.relational, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
this.finishOp(tt.lt, 1);
|
||||
}
|
||||
|
||||
readToken_gt(): void {
|
||||
// '>'
|
||||
const { pos } = this.state;
|
||||
const next = this.input.charCodeAt(pos + 1);
|
||||
|
||||
if (next === charCodes.greaterThan) {
|
||||
const size =
|
||||
this.input.charCodeAt(pos + 2) === charCodes.greaterThan ? 3 : 2;
|
||||
if (this.input.charCodeAt(pos + size) === charCodes.equalsTo) {
|
||||
this.finishOp(tt.assign, size + 1);
|
||||
return;
|
||||
}
|
||||
@@ -748,10 +768,11 @@ export default class Tokenizer extends ParserErrors {
|
||||
|
||||
if (next === charCodes.equalsTo) {
|
||||
// <= | >=
|
||||
size = 2;
|
||||
this.finishOp(tt.relational, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
this.finishOp(tt.relational, size);
|
||||
this.finishOp(tt.gt, 1);
|
||||
}
|
||||
|
||||
readToken_eq_excl(code: number): void {
|
||||
@@ -963,8 +984,11 @@ export default class Tokenizer extends ParserErrors {
|
||||
return;
|
||||
|
||||
case charCodes.lessThan:
|
||||
this.readToken_lt();
|
||||
return;
|
||||
|
||||
case charCodes.greaterThan:
|
||||
this.readToken_lt_gt(code);
|
||||
this.readToken_gt();
|
||||
return;
|
||||
|
||||
case charCodes.equalsTo:
|
||||
|
||||
@@ -200,6 +200,8 @@ export const tt: { [name: string]: TokenType } = {
|
||||
bitwiseXOR: createBinop("^", 4),
|
||||
bitwiseAND: createBinop("&", 5),
|
||||
equality: createBinop("==/!=/===/!==", 6),
|
||||
lt: createBinop("</>/<=/>=", 7),
|
||||
gt: createBinop("</>/<=/>=", 7),
|
||||
relational: createBinop("</>/<=/>=", 7),
|
||||
bitShift: createBinop("<</>>/>>>", 8),
|
||||
plusMin: createToken("+/-", { beforeExpr, binop: 9, prefix, startsExpr }),
|
||||
|
||||
Reference in New Issue
Block a user