From 10544efb21a4c00029f87f3044cd609085eab8a4 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 5 Dec 2022 12:17:48 +0100 Subject: [PATCH 1/3] test_runner: refactor `tap_lexer` to use more primordials --- lib/internal/test_runner/tap_lexer.js | 37 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/internal/test_runner/tap_lexer.js b/lib/internal/test_runner/tap_lexer.js index 24743a1853a833..e781781a7095f3 100644 --- a/lib/internal/test_runner/tap_lexer.js +++ b/lib/internal/test_runner/tap_lexer.js @@ -1,6 +1,14 @@ 'use strict'; -const { SafeSet, MathMax, StringPrototypeIncludes } = primordials; +const { + ArrayPrototypePop, + ArrayPrototypePush, + ArrayPrototypePushApply, + MathMax, + SafeSet, + StringPrototypeIncludes, + StringPrototypeTrim, +} = primordials; const { codes: { ERR_TAP_LEXER_ERROR }, } = require('internal/errors'); @@ -136,21 +144,21 @@ class TapLexer { this.#lastScannedToken = token; } + ArrayPrototypePush(chunk, token); if (token.kind === TokenKind.NEWLINE) { // Store the current chunk + NEWLINE token - tokens.push([...chunk, token]); + ArrayPrototypePushApply(tokens, chunk); chunk = []; - } else { - chunk.push(token); } } if (chunk.length > 0) { - tokens.push([...chunk, this.#scanEOL()]); + ArrayPrototypePushApply(tokens, chunk); + ArrayPrototypePush(chunk, this.#scanEOL()); } // send EOF as a separate chunk - tokens.push([this.#scanEOF()]); + ArrayPrototypePush(tokens, [this.#scanEOF()]); return tokens; } @@ -238,7 +246,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 +257,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 +334,7 @@ class TapLexer { const charHasBeenEscaped = this.#hasTheCurrentCharacterBeenEscaped(); if (this.#isComment || charHasBeenEscaped) { if (charHasBeenEscaped) { - this.#escapeStack.pop(); + ArrayPrototypePop(this.#escapeStack); } return new Token({ @@ -355,7 +363,7 @@ class TapLexer { } } - word = word.trim(); + word = StringPrototypeTrim(word); if (TapLexer.Keywords.has(word)) { const token = this.#scanTAPKeyword(word); @@ -380,10 +388,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 +486,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) { From 9e1e56fa50d8613c2e4870831d10d2c82caa4f95 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 5 Dec 2022 14:44:28 +0100 Subject: [PATCH 2/3] fixup! test_runner: refactor `tap_lexer` to use more primordials --- lib/internal/test_runner/tap_lexer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/test_runner/tap_lexer.js b/lib/internal/test_runner/tap_lexer.js index e781781a7095f3..985670b38f7cdb 100644 --- a/lib/internal/test_runner/tap_lexer.js +++ b/lib/internal/test_runner/tap_lexer.js @@ -147,14 +147,14 @@ class TapLexer { ArrayPrototypePush(chunk, token); if (token.kind === TokenKind.NEWLINE) { // Store the current chunk + NEWLINE token - ArrayPrototypePushApply(tokens, chunk); + ArrayPrototypePush(tokens, chunk); chunk = []; } } if (chunk.length > 0) { - ArrayPrototypePushApply(tokens, chunk); ArrayPrototypePush(chunk, this.#scanEOL()); + ArrayPrototypePush(tokens, chunk); } // send EOF as a separate chunk From 350ce5f21e56e10a9e7fff887e7a80b59077fbfc Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 6 Dec 2022 16:04:42 +0100 Subject: [PATCH 3/3] Update lib/internal/test_runner/tap_lexer.js --- lib/internal/test_runner/tap_lexer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/test_runner/tap_lexer.js b/lib/internal/test_runner/tap_lexer.js index 985670b38f7cdb..64ddafb4dba2da 100644 --- a/lib/internal/test_runner/tap_lexer.js +++ b/lib/internal/test_runner/tap_lexer.js @@ -3,7 +3,6 @@ const { ArrayPrototypePop, ArrayPrototypePush, - ArrayPrototypePushApply, MathMax, SafeSet, StringPrototypeIncludes,