mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
test_runner: refactor tap_lexer to use more primordials
PR-URL: https://github.com/nodejs/node/pull/45744 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
1 parent
1ddc438444
commit
24e2a4fbd7
1 file changed
+21
-15
@@ -1,6 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { SafeSet, MathMax, StringPrototypeIncludes } = primordials;
|
||||
const {
|
||||
ArrayPrototypePop,
|
||||
ArrayPrototypePush,
|
||||
MathMax,
|
||||
SafeSet,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeTrim,
|
||||
} = primordials;
|
||||
const {
|
||||
codes: { ERR_TAP_LEXER_ERROR },
|
||||
} = require('internal/errors');
|
||||
@@ -136,21 +143,21 @@ class TapLexer {
|
||||
this.#lastScannedToken = token;
|
||||
}
|
||||
|
||||
ArrayPrototypePush(chunk, token);
|
||||
if (token.kind === TokenKind.NEWLINE) {
|
||||
// Store the current chunk + NEWLINE token
|
||||
tokens.push([...chunk, token]);
|
||||
ArrayPrototypePush(tokens, chunk);
|
||||
chunk = [];
|
||||
} else {
|
||||
chunk.push(token);
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.length > 0) {
|
||||
tokens.push([...chunk, this.#scanEOL()]);
|
||||
ArrayPrototypePush(chunk, this.#scanEOL());
|
||||
ArrayPrototypePush(tokens, chunk);
|
||||
}
|
||||
|
||||
// send EOF as a separate chunk
|
||||
tokens.push([this.#scanEOF()]);
|
||||
ArrayPrototypePush(tokens, [this.#scanEOF()]);
|
||||
|
||||
return tokens;
|
||||
}
|
||||
@@ -238,7 +245,7 @@ class TapLexer {
|
||||
this.#hasTheCurrentCharacterBeenEscaped() ||
|
||||
this.#source.peek(1) === TokenKind.WHITESPACE
|
||||
) {
|
||||
this.#escapeStack.pop();
|
||||
ArrayPrototypePop(this.#escapeStack);
|
||||
return new Token({
|
||||
kind: TokenKind.LITERAL,
|
||||
value: char,
|
||||
@@ -249,7 +256,7 @@ class TapLexer {
|
||||
// Otherwise, consume the escape symbol as an escape symbol that should be ignored by the parser
|
||||
// we also need to push the escape symbol to the escape stack
|
||||
// and consume the next character as a literal (done in the next turn)
|
||||
this.#escapeStack.push(char);
|
||||
ArrayPrototypePush(this.#escapeStack, char);
|
||||
return new Token({
|
||||
kind: TokenKind.ESCAPE,
|
||||
value: char,
|
||||
@@ -326,7 +333,7 @@ class TapLexer {
|
||||
const charHasBeenEscaped = this.#hasTheCurrentCharacterBeenEscaped();
|
||||
if (this.#isComment || charHasBeenEscaped) {
|
||||
if (charHasBeenEscaped) {
|
||||
this.#escapeStack.pop();
|
||||
ArrayPrototypePop(this.#escapeStack);
|
||||
}
|
||||
|
||||
return new Token({
|
||||
@@ -355,7 +362,7 @@ class TapLexer {
|
||||
}
|
||||
}
|
||||
|
||||
word = word.trim();
|
||||
word = StringPrototypeTrim(word);
|
||||
|
||||
if (TapLexer.Keywords.has(word)) {
|
||||
const token = this.#scanTAPKeyword(word);
|
||||
@@ -380,10 +387,9 @@ class TapLexer {
|
||||
}
|
||||
|
||||
#scanTAPKeyword(word) {
|
||||
const isLastScannedTokenEOLorNewLine = StringPrototypeIncludes(
|
||||
[TokenKind.EOL, TokenKind.NEWLINE],
|
||||
this.#lastScannedToken.kind
|
||||
);
|
||||
const isLastScannedTokenEOLorNewLine =
|
||||
TokenKind.EOL === this.#lastScannedToken.kind ||
|
||||
TokenKind.NEWLINE === this.#lastScannedToken.kind;
|
||||
|
||||
if (word === 'TAP' && isLastScannedTokenEOLorNewLine) {
|
||||
return new Token({
|
||||
@@ -479,7 +485,7 @@ class TapLexer {
|
||||
// We deliberately do not include "# \ + -"" in this list
|
||||
// these are used for comments/reasons explanations, pragma and escape characters
|
||||
// whitespace is not included because it is handled separately
|
||||
return '!"$%&\'()*,./:;<=>?@[]^_`{|}~'.indexOf(char) > -1;
|
||||
return StringPrototypeIncludes('!"$%&\'()*,./:;<=>?@[]^_`{|}~', char);
|
||||
}
|
||||
|
||||
#isWhitespaceSymbol(char) {
|
||||
|
||||
Reference in new issue
Block a user