Skip to content

Commit cb656c3

Browse files
committed
Optimize
1 parent 0c65540 commit cb656c3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/core/parse/ast/ast.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,16 @@ export class AST {
588588
* @returns {import('../lexer/lexer.js').Token|boolean} The next token if it matches, otherwise false.
589589
*/
590590
_peek(...expected) {
591-
if (this._tokens.length > this._index) {
592-
const token = this._tokens[this._index];
591+
const token = this._tokens[this._index];
593592

594-
const { text } = token;
593+
const j = expected.length;
595594

596-
if (
597-
expected.includes(text) ||
598-
(!expected[0] && !expected[1] && !expected[2] && !expected[3])
599-
) {
600-
return token;
601-
}
595+
if (!token || !j) return token;
596+
597+
const txt = token.text;
598+
599+
for (let i = 0; i < j; i++) {
600+
if (expected[i] === txt || !expected[i]) return token;
602601
}
603602

604603
return false;

0 commit comments

Comments
 (0)