11'use strict' ;
22
3- const Transform = require ( 'internal/streams/transform' ) ;
4- const { TapLexer, TokenKind } = require ( 'internal/test_runner/tap_lexer' ) ;
5- const { TapChecker } = require ( 'internal/test_runner/tap_checker' ) ;
6- const {
7- codes : { ERR_TAP_VALIDATION_ERROR , ERR_TAP_PARSER_ERROR } ,
8- } = require ( 'internal/errors' ) ;
9- const { kEmptyObject } = require ( 'internal/util' ) ;
103const {
114 ArrayPrototypeFilter,
125 ArrayPrototypeForEach,
6+ ArrayPrototypeIncludes,
137 ArrayPrototypeJoin,
148 ArrayPrototypeMap,
9+ ArrayPrototypePop,
1510 ArrayPrototypePush,
16- ArrayPrototypeIncludes,
17- ArrayPrototypeSplice,
1811 Boolean,
1912 Number,
2013 RegExpPrototypeExec,
21- RegExpPrototypeSymbolReplace,
2214 String,
23- StringPrototypeTrim,
15+ StringPrototypeEndsWith,
16+ StringPrototypeReplaceAll,
17+ StringPrototypeSlice,
2418 StringPrototypeSplit,
19+ StringPrototypeTrim,
2520} = primordials ;
21+ const Transform = require ( 'internal/streams/transform' ) ;
22+ const { TapLexer, TokenKind } = require ( 'internal/test_runner/tap_lexer' ) ;
23+ const { TapChecker } = require ( 'internal/test_runner/tap_checker' ) ;
24+ const {
25+ codes : { ERR_TAP_VALIDATION_ERROR , ERR_TAP_PARSER_ERROR } ,
26+ } = require ( 'internal/errors' ) ;
27+ const { kEmptyObject } = require ( 'internal/util' ) ;
2628/**
2729 *
2830 * TAP14 specifications
@@ -149,22 +151,26 @@ class TapParser extends Transform {
149151 processChunk ( chunk ) {
150152 const str = this . #lastLine + chunk . toString ( 'utf8' ) ;
151153 const lines = StringPrototypeSplit ( str , '\n' ) ;
152- this . #lastLine = ArrayPrototypeSplice ( lines , lines . length - 1 , 1 ) [ 0 ] ;
154+ this . #lastLine = ArrayPrototypePop ( lines ) ;
153155
154- let chunkAsString = lines . join ( '\n' ) ;
156+ let chunkAsString = ArrayPrototypeJoin ( lines , '\n' ) ;
155157 // Special case where chunk is emitted by a child process
156- chunkAsString = RegExpPrototypeSymbolReplace (
157- / \[ o u t \] / g,
158+ chunkAsString = StringPrototypeReplaceAll (
158159 chunkAsString ,
160+ '[out] ' ,
159161 ''
160162 ) ;
161- chunkAsString = RegExpPrototypeSymbolReplace (
162- / \[ e r r \] / g,
163+ chunkAsString = StringPrototypeReplaceAll (
163164 chunkAsString ,
165+ '[err] ' ,
164166 ''
165167 ) ;
166- chunkAsString = RegExpPrototypeSymbolReplace ( / \n $ / , chunkAsString , '' ) ;
167- chunkAsString = RegExpPrototypeSymbolReplace ( / E O F $ / , chunkAsString , '' ) ;
168+ if ( StringPrototypeEndsWith ( chunkAsString , '\n' ) ) {
169+ chunkAsString = StringPrototypeSlice ( chunkAsString , 0 , - 1 ) ;
170+ }
171+ if ( StringPrototypeEndsWith ( chunkAsString , 'EOF' ) ) {
172+ chunkAsString = StringPrototypeSlice ( chunkAsString , 0 , - 3 ) ;
173+ }
168174
169175 return chunkAsString ;
170176 }
@@ -371,7 +377,7 @@ class TapParser extends Transform {
371377 }
372378
373379 #addDiagnosticsToLastTestPoint( currentNode ) {
374- const lastTestPoint = this . #bufferedTestPoints. at ( - 1 ) ;
380+ const { length , [ length - 1 ] : lastTestPoint } = this . #bufferedTestPoints;
375381
376382 // Diagnostic nodes are only added to Test points of the same nesting level
377383 if ( lastTestPoint && lastTestPoint . nesting === currentNode . nesting ) {
@@ -396,7 +402,7 @@ class TapParser extends Transform {
396402
397403 #flushBufferedTestPointNode( shouldClearBuffer = true ) {
398404 if ( this . #bufferedTestPoints. length > 0 ) {
399- this . #emit( this . #bufferedTestPoints. at ( 0 ) ) ;
405+ this . #emit( this . #bufferedTestPoints[ 0 ] ) ;
400406
401407 if ( shouldClearBuffer ) {
402408 this . #bufferedTestPoints = [ ] ;
@@ -797,7 +803,7 @@ class TapParser extends Transform {
797803
798804 const commentContent = this . #peek( ) ;
799805 if ( commentContent ) {
800- if ( / ^ S u b t e s t : / i. test ( commentContent . value ) ) {
806+ if ( RegExpPrototypeExec ( / ^ S u b t e s t : / i, commentContent . value ) !== null ) {
801807 this . #next( ) ; // skip subtest keyword
802808 const name = StringPrototypeTrim ( this . #readNextLiterals( ) ) ;
803809 const node = {
@@ -898,7 +904,7 @@ class TapParser extends Transform {
898904 // YAMLLine := " " (YAML)* "\n"
899905 #YAMLLine( ) {
900906 const yamlLiteral = this . #readNextLiterals( ) ;
901- const { 0 : key , 1 : value } = StringPrototypeSplit ( yamlLiteral , ':' ) ;
907+ const { 0 : key , 1 : value } = StringPrototypeSplit ( yamlLiteral , ':' , 2 ) ;
902908
903909 // Note that this.#lastTestPointDetails has been cleared when we encounter a YAML start marker
904910
@@ -960,7 +966,7 @@ class TapParser extends Transform {
960966
961967 // In some cases, pragma key can be followed by a comma separator,
962968 // so we need to remove it
963- pragmaKey = RegExpPrototypeSymbolReplace ( / , / g , pragmaKey , '' ) ;
969+ pragmaKey = StringPrototypeReplaceAll ( pragmaKey , ',' , '' ) ;
964970
965971 pragmas [ pragmaKey ] = isEnabled ;
966972 nextToken = this . #peek( ) ;
0 commit comments