1
- // https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01 /lib/internal/test_runner/tap_lexer.js
1
+ // https://github.com/nodejs/node/blob/2483da743cbb48f31c6b3f8cb186d89f31d73611 /lib/internal/test_runner/tap_lexer.js
2
2
'use strict'
3
3
4
- const { SafeSet, MathMax, StringPrototypeIncludes } = require ( '#internal/per_context/primordials' )
4
+ const {
5
+ ArrayPrototypePop,
6
+ ArrayPrototypePush,
7
+ MathMax,
8
+ SafeSet,
9
+ StringPrototypeIncludes,
10
+ StringPrototypeTrim
11
+ } = require ( '#internal/per_context/primordials' )
5
12
const {
6
13
codes : { ERR_TAP_LEXER_ERROR }
7
14
} = require ( '#internal/errors' )
@@ -137,21 +144,21 @@ class TapLexer {
137
144
this . #lastScannedToken = token
138
145
}
139
146
147
+ ArrayPrototypePush ( chunk , token )
140
148
if ( token . kind === TokenKind . NEWLINE ) {
141
149
// Store the current chunk + NEWLINE token
142
- tokens . push ( [ ... chunk , token ] )
150
+ ArrayPrototypePush ( tokens , chunk )
143
151
chunk = [ ]
144
- } else {
145
- chunk . push ( token )
146
152
}
147
153
}
148
154
149
155
if ( chunk . length > 0 ) {
150
- tokens . push ( [ ...chunk , this . #scanEOL( ) ] )
156
+ ArrayPrototypePush ( chunk , this . #scanEOL( ) )
157
+ ArrayPrototypePush ( tokens , chunk )
151
158
}
152
159
153
160
// send EOF as a separate chunk
154
- tokens . push ( [ this . #scanEOF( ) ] )
161
+ ArrayPrototypePush ( tokens , [ this . #scanEOF( ) ] )
155
162
156
163
return tokens
157
164
}
@@ -239,7 +246,7 @@ class TapLexer {
239
246
this . #hasTheCurrentCharacterBeenEscaped( ) ||
240
247
this . #source. peek ( 1 ) === TokenKind . WHITESPACE
241
248
) {
242
- this . #escapeStack. pop ( )
249
+ ArrayPrototypePop ( this . #escapeStack)
243
250
return new Token ( {
244
251
kind : TokenKind . LITERAL ,
245
252
value : char ,
@@ -250,7 +257,7 @@ class TapLexer {
250
257
// Otherwise, consume the escape symbol as an escape symbol that should be ignored by the parser
251
258
// we also need to push the escape symbol to the escape stack
252
259
// and consume the next character as a literal (done in the next turn)
253
- this . #escapeStack. push ( char )
260
+ ArrayPrototypePush ( this . #escapeStack, char )
254
261
return new Token ( {
255
262
kind : TokenKind . ESCAPE ,
256
263
value : char ,
@@ -327,7 +334,7 @@ class TapLexer {
327
334
const charHasBeenEscaped = this . #hasTheCurrentCharacterBeenEscaped( )
328
335
if ( this . #isComment || charHasBeenEscaped ) {
329
336
if ( charHasBeenEscaped ) {
330
- this . #escapeStack. pop ( )
337
+ ArrayPrototypePop ( this . #escapeStack)
331
338
}
332
339
333
340
return new Token ( {
@@ -356,7 +363,7 @@ class TapLexer {
356
363
}
357
364
}
358
365
359
- word = word . trim ( )
366
+ word = StringPrototypeTrim ( word )
360
367
361
368
if ( TapLexer . Keywords . has ( word ) ) {
362
369
const token = this . #scanTAPKeyword( word )
@@ -381,10 +388,9 @@ class TapLexer {
381
388
}
382
389
383
390
#scanTAPKeyword ( word ) {
384
- const isLastScannedTokenEOLorNewLine = StringPrototypeIncludes (
385
- [ TokenKind . EOL , TokenKind . NEWLINE ] ,
386
- this . #lastScannedToken. kind
387
- )
391
+ const isLastScannedTokenEOLorNewLine =
392
+ TokenKind . EOL === this . #lastScannedToken. kind ||
393
+ TokenKind . NEWLINE === this . #lastScannedToken. kind
388
394
389
395
if ( word === 'TAP' && isLastScannedTokenEOLorNewLine ) {
390
396
return new Token ( {
@@ -480,7 +486,7 @@ class TapLexer {
480
486
// We deliberately do not include "# \ + -"" in this list
481
487
// these are used for comments/reasons explanations, pragma and escape characters
482
488
// whitespace is not included because it is handled separately
483
- return '!"$%&\'()*,./:;<=>?@[]^_`{|}~' . indexOf ( char ) > - 1
489
+ return StringPrototypeIncludes ( '!"$%&\'()*,./:;<=>?@[]^_`{|}~' , char )
484
490
}
485
491
486
492
#isWhitespaceSymbol ( char ) {
0 commit comments