11'use strict' ;
22
3- const { SafeSet, MathMax, StringPrototypeIncludes } = primordials ;
3+ const {
4+ ArrayPrototypePop,
5+ ArrayPrototypePush,
6+ MathMax,
7+ SafeSet,
8+ StringPrototypeIncludes,
9+ StringPrototypeTrim,
10+ } = primordials ;
411const {
512 codes : { ERR_TAP_LEXER_ERROR } ,
613} = require ( 'internal/errors' ) ;
@@ -136,21 +143,21 @@ class TapLexer {
136143 this . #lastScannedToken = token ;
137144 }
138145
146+ ArrayPrototypePush ( chunk , token ) ;
139147 if ( token . kind === TokenKind . NEWLINE ) {
140148 // Store the current chunk + NEWLINE token
141- tokens . push ( [ ... chunk , token ] ) ;
149+ ArrayPrototypePush ( tokens , chunk ) ;
142150 chunk = [ ] ;
143- } else {
144- chunk . push ( token ) ;
145151 }
146152 }
147153
148154 if ( chunk . length > 0 ) {
149- tokens . push ( [ ...chunk , this . #scanEOL( ) ] ) ;
155+ ArrayPrototypePush ( chunk , this . #scanEOL( ) ) ;
156+ ArrayPrototypePush ( tokens , chunk ) ;
150157 }
151158
152159 // send EOF as a separate chunk
153- tokens . push ( [ this . #scanEOF( ) ] ) ;
160+ ArrayPrototypePush ( tokens , [ this . #scanEOF( ) ] ) ;
154161
155162 return tokens ;
156163 }
@@ -238,7 +245,7 @@ class TapLexer {
238245 this . #hasTheCurrentCharacterBeenEscaped( ) ||
239246 this . #source. peek ( 1 ) === TokenKind . WHITESPACE
240247 ) {
241- this . #escapeStack. pop ( ) ;
248+ ArrayPrototypePop ( this . #escapeStack) ;
242249 return new Token ( {
243250 kind : TokenKind . LITERAL ,
244251 value : char ,
@@ -249,7 +256,7 @@ class TapLexer {
249256 // Otherwise, consume the escape symbol as an escape symbol that should be ignored by the parser
250257 // we also need to push the escape symbol to the escape stack
251258 // and consume the next character as a literal (done in the next turn)
252- this . #escapeStack. push ( char ) ;
259+ ArrayPrototypePush ( this . #escapeStack, char ) ;
253260 return new Token ( {
254261 kind : TokenKind . ESCAPE ,
255262 value : char ,
@@ -326,7 +333,7 @@ class TapLexer {
326333 const charHasBeenEscaped = this . #hasTheCurrentCharacterBeenEscaped( ) ;
327334 if ( this . #isComment || charHasBeenEscaped ) {
328335 if ( charHasBeenEscaped ) {
329- this . #escapeStack. pop ( ) ;
336+ ArrayPrototypePop ( this . #escapeStack) ;
330337 }
331338
332339 return new Token ( {
@@ -355,7 +362,7 @@ class TapLexer {
355362 }
356363 }
357364
358- word = word . trim ( ) ;
365+ word = StringPrototypeTrim ( word ) ;
359366
360367 if ( TapLexer . Keywords . has ( word ) ) {
361368 const token = this . #scanTAPKeyword( word ) ;
@@ -380,10 +387,9 @@ class TapLexer {
380387 }
381388
382389 #scanTAPKeyword( word ) {
383- const isLastScannedTokenEOLorNewLine = StringPrototypeIncludes (
384- [ TokenKind . EOL , TokenKind . NEWLINE ] ,
385- this . #lastScannedToken. kind
386- ) ;
390+ const isLastScannedTokenEOLorNewLine =
391+ TokenKind . EOL === this . #lastScannedToken. kind ||
392+ TokenKind . NEWLINE === this . #lastScannedToken. kind ;
387393
388394 if ( word === 'TAP' && isLastScannedTokenEOLorNewLine ) {
389395 return new Token ( {
@@ -479,7 +485,7 @@ class TapLexer {
479485 // We deliberately do not include "# \ + -"" in this list
480486 // these are used for comments/reasons explanations, pragma and escape characters
481487 // whitespace is not included because it is handled separately
482- return '!"$%&\'()*,./:;<=>?@[]^_`{|}~' . indexOf ( char ) > - 1 ;
488+ return StringPrototypeIncludes ( '!"$%&\'()*,./:;<=>?@[]^_`{|}~' , char ) ;
483489 }
484490
485491 #isWhitespaceSymbol( char ) {
0 commit comments