@@ -79,7 +79,7 @@ function parseSource (cjsSource) {
79
79
if ( openTokenDepth === 0 ) {
80
80
switch ( ch ) {
81
81
case 105 /*i*/ :
82
- if ( source . slice ( pos + 1 , pos + 6 ) === 'mport' && keywordStart ( pos ) )
82
+ if ( source . startsWith ( 'mport' , pos + 1 ) && keywordStart ( pos ) )
83
83
throwIfImportStatement ( ) ;
84
84
lastTokenPos = pos ;
85
85
continue ;
@@ -90,9 +90,9 @@ function parseSource (cjsSource) {
90
90
lastTokenPos = pos ;
91
91
continue ;
92
92
case 95 /*_*/ :
93
- if ( source . slice ( pos + 1 , pos + 8 ) === '_export' && ( keywordStart ( pos ) || source . charCodeAt ( pos - 1 ) === 46 /*.*/ ) ) {
93
+ if ( source . startsWith ( '_export' , pos + 1 ) && ( keywordStart ( pos ) || source . charCodeAt ( pos - 1 ) === 46 /*.*/ ) ) {
94
94
pos += 8 ;
95
- if ( source . slice ( pos , pos + 4 ) === 'Star' )
95
+ if ( source . startsWith ( 'Star' , pos ) )
96
96
pos += 4 ;
97
97
if ( source . charCodeAt ( pos ) === 40 /*(*/ ) {
98
98
openTokenPosStack [ openTokenDepth ++ ] = lastTokenPos ;
@@ -107,23 +107,23 @@ function parseSource (cjsSource) {
107
107
108
108
switch ( ch ) {
109
109
case 101 /*e*/ :
110
- if ( source . slice ( pos + 1 , pos + 6 ) === 'xport' && keywordStart ( pos ) ) {
110
+ if ( source . startsWith ( 'xport' , pos + 1 ) && keywordStart ( pos ) ) {
111
111
if ( source . charCodeAt ( pos + 6 ) === 115 /*s*/ )
112
112
tryParseExportsDotAssign ( false ) ;
113
113
else if ( openTokenDepth === 0 )
114
114
throwIfExportStatement ( ) ;
115
115
}
116
116
break ;
117
117
case 99 /*c*/ :
118
- if ( keywordStart ( pos ) && source . slice ( pos + 1 , pos + 5 ) === 'lass' && isBrOrWs ( source . charCodeAt ( pos + 5 ) ) )
118
+ if ( keywordStart ( pos ) && source . startsWith ( 'lass' , pos + 1 ) && isBrOrWs ( source . charCodeAt ( pos + 5 ) ) )
119
119
nextBraceIsClass = true ;
120
120
break ;
121
121
case 109 /*m*/ :
122
- if ( source . slice ( pos + 1 , pos + 6 ) === 'odule' && keywordStart ( pos ) )
122
+ if ( source . startsWith ( 'odule' , pos + 1 ) && keywordStart ( pos ) )
123
123
tryParseModuleExportsDotAssign ( ) ;
124
124
break ;
125
125
case 79 /*O*/ :
126
- if ( source . slice ( pos + 1 , pos + 6 ) === 'bject' && keywordStart ( pos ) )
126
+ if ( source . startsWith ( 'bject' , pos + 1 ) && keywordStart ( pos ) )
127
127
tryParseObjectDefineOrKeys ( openTokenDepth === 0 ) ;
128
128
break ;
129
129
case 40 /*(*/ :
@@ -233,11 +233,11 @@ function tryBacktrackAddStarExportBinding (bPos) {
233
233
bPos -- ;
234
234
switch ( source . charCodeAt ( bPos ) ) {
235
235
case 114 /*r*/ :
236
- if ( source . slice ( bPos - 2 , bPos ) !== 'va' )
236
+ if ( ! source . startsWith ( 'va' , bPos - 2 ) )
237
237
return ;
238
238
break ;
239
239
case 116 /*t*/ :
240
- if ( source . slice ( bPos - 2 , bPos ) !== 'le' && source . slice ( bPos - 4 , bPos ) !== 'cons' )
240
+ if ( ! source . startsWith ( 'le' , bPos - 2 ) && ! source . startsWith ( 'cons' , bPos - 4 ) )
241
241
return ;
242
242
break ;
243
243
default : return ;
@@ -254,7 +254,7 @@ function tryParseObjectDefineOrKeys (keys) {
254
254
if ( ch === 46 /*.*/ ) {
255
255
pos ++ ;
256
256
ch = commentWhitespace ( ) ;
257
- if ( ch === 100 /*d*/ && source . slice ( pos + 1 , pos + 14 ) === 'efineProperty' ) {
257
+ if ( ch === 100 /*d*/ && source . startsWith ( 'efineProperty' , pos + 1 ) ) {
258
258
pos += 14 ;
259
259
revertPos = pos - 1 ;
260
260
ch = commentWhitespace ( ) ;
@@ -279,7 +279,7 @@ function tryParseObjectDefineOrKeys (keys) {
279
279
}
280
280
}
281
281
}
282
- else if ( keys && ch === 107 /*k*/ && source . slice ( pos + 1 , pos + 4 ) === 'eys' ) {
282
+ else if ( keys && ch === 107 /*k*/ && source . startsWith ( 'eys' , pos + 1 ) ) {
283
283
while ( true ) {
284
284
pos += 4 ;
285
285
revertPos = pos - 1 ;
@@ -298,14 +298,14 @@ function tryParseObjectDefineOrKeys (keys) {
298
298
if ( ch !== 46 /*.*/ ) break ;
299
299
pos ++ ;
300
300
ch = commentWhitespace ( ) ;
301
- if ( ch !== 102 /*f*/ || source . slice ( pos + 1 , pos + 7 ) !== 'orEach' ) break ;
301
+ if ( ch !== 102 /*f*/ || ! source . startsWith ( 'orEach' , pos + 1 ) ) break ;
302
302
pos += 7 ;
303
303
ch = commentWhitespace ( ) ;
304
304
revertPos = pos - 1 ;
305
305
if ( ch !== 40 /*(*/ ) break ;
306
306
pos ++ ;
307
307
ch = commentWhitespace ( ) ;
308
- if ( ch !== 102 /*f*/ || source . slice ( pos + 1 , pos + 8 ) !== 'unction' ) break ;
308
+ if ( ch !== 102 /*f*/ || ! source . startsWith ( 'unction' , pos + 1 ) ) break ;
309
309
pos += 8 ;
310
310
ch = commentWhitespace ( ) ;
311
311
if ( ch !== 40 /*(*/ ) break ;
@@ -321,23 +321,23 @@ function tryParseObjectDefineOrKeys (keys) {
321
321
if ( ch !== 123 /*{*/ ) break ;
322
322
pos ++ ;
323
323
ch = commentWhitespace ( ) ;
324
- if ( ch !== 105 /*i*/ || source . slice ( pos + 1 , pos + 3 ) !== 'f ' ) break ;
324
+ if ( ch !== 105 /*i*/ || ! source . startsWith ( 'f ' , pos + 1 ) ) break ;
325
325
pos += 3 ;
326
326
ch = commentWhitespace ( ) ;
327
327
if ( ch !== 40 /*(*/ ) break ;
328
328
pos ++ ;
329
329
ch = commentWhitespace ( ) ;
330
- if ( it_id !== source . slice ( pos , pos + it_id . length ) ) break ;
330
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
331
331
pos += it_id . length ;
332
332
ch = commentWhitespace ( ) ;
333
333
// `if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? |
334
334
if ( ch === 61 /*=*/ ) {
335
- if ( source . slice ( pos + 1 , pos + 3 ) !== '==' ) break ;
335
+ if ( ! source . startsWith ( '==' , pos + 1 ) ) break ;
336
336
pos += 3 ;
337
337
ch = commentWhitespace ( ) ;
338
338
if ( ch !== 34 /*"*/ && ch !== 39 /*'*/ ) break ;
339
339
let quot = ch ;
340
- if ( source . slice ( pos + 1 , pos + 8 ) !== 'default' ) break ;
340
+ if ( ! source . startsWith ( 'default' , pos + 1 ) ) break ;
341
341
pos += 8 ;
342
342
ch = commentWhitespace ( ) ;
343
343
if ( ch !== quot ) break ;
@@ -354,7 +354,7 @@ function tryParseObjectDefineOrKeys (keys) {
354
354
ch = commentWhitespace ( ) ;
355
355
if ( ch !== 34 /*"*/ && ch !== 39 /*'*/ ) break ;
356
356
quot = ch ;
357
- if ( source . slice ( pos + 1 , pos + 11 ) !== '__esModule' ) break ;
357
+ if ( ! source . startsWith ( '__esModule' , pos + 1 ) ) break ;
358
358
pos += 11 ;
359
359
ch = commentWhitespace ( ) ;
360
360
if ( ch !== quot ) break ;
@@ -363,7 +363,7 @@ function tryParseObjectDefineOrKeys (keys) {
363
363
if ( ch !== 41 /*)*/ ) break ;
364
364
pos += 1 ;
365
365
ch = commentWhitespace ( ) ;
366
- if ( ch !== 114 /*r*/ || source . slice ( pos + 1 , pos + 6 ) !== 'eturn' ) break ;
366
+ if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
367
367
pos += 6 ;
368
368
ch = commentWhitespace ( ) ;
369
369
if ( ch === 59 /*;*/ )
@@ -372,12 +372,12 @@ function tryParseObjectDefineOrKeys (keys) {
372
372
}
373
373
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
374
374
else if ( ch === 33 /*!*/ ) {
375
- if ( source . slice ( pos + 1 , pos + 3 ) !== '==' ) break ;
375
+ if ( ! source . startsWith ( '==' , pos + 1 ) ) break ;
376
376
pos += 3 ;
377
377
ch = commentWhitespace ( ) ;
378
378
if ( ch !== 34 /*"*/ && ch !== 39 /*'*/ ) break ;
379
379
const quot = ch ;
380
- if ( source . slice ( pos + 1 , pos + 8 ) !== 'default' ) break ;
380
+ if ( ! source . startsWith ( 'default' , pos + 1 ) ) break ;
381
381
pos += 8 ;
382
382
ch = commentWhitespace ( ) ;
383
383
if ( ch !== quot ) break ;
@@ -429,7 +429,7 @@ function tryParseObjectDefineOrKeys (keys) {
429
429
if ( ch !== 46 /*.*/ ) break ;
430
430
pos ++ ;
431
431
ch = commentWhitespace ( ) ;
432
- if ( ch !== 100 /*d*/ || source . slice ( pos + 1 , pos + 14 ) !== 'efineProperty' ) break ;
432
+ if ( ch !== 100 /*d*/ || ! source . startsWith ( 'efineProperty' , pos + 1 ) ) break ;
433
433
pos += 14 ;
434
434
ch = commentWhitespace ( ) ;
435
435
if ( ch !== 40 /*(*/ ) break ;
@@ -440,7 +440,7 @@ function tryParseObjectDefineOrKeys (keys) {
440
440
if ( ch !== 44 /*,*/ ) break ;
441
441
pos ++ ;
442
442
ch = commentWhitespace ( ) ;
443
- if ( source . slice ( pos , pos + it_id . length ) !== it_id ) break ;
443
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
444
444
pos += it_id . length ;
445
445
ch = commentWhitespace ( ) ;
446
446
if ( ch !== 44 /*,*/ ) break ;
@@ -449,25 +449,25 @@ function tryParseObjectDefineOrKeys (keys) {
449
449
if ( ch !== 123 /*{*/ ) break ;
450
450
pos ++ ;
451
451
ch = commentWhitespace ( ) ;
452
- if ( ch !== 101 /*e*/ || source . slice ( pos + 1 , pos + 10 ) !== 'numerable' ) break ;
452
+ if ( ch !== 101 /*e*/ || ! source . startsWith ( 'numerable' , pos + 1 ) ) break ;
453
453
pos += 10 ;
454
454
ch = commentWhitespace ( ) ;
455
455
if ( ch !== 58 /*:*/ ) break ;
456
456
pos ++ ;
457
457
ch = commentWhitespace ( ) ;
458
- if ( ch !== 116 /*t*/ && source . slice ( pos + 1 , pos + 4 ) !== 'rue' ) break ;
458
+ if ( ch !== 116 /*t*/ && ! source . startsWith ( 'rue' , pos + 1 ) ) break ;
459
459
pos += 4 ;
460
460
ch = commentWhitespace ( ) ;
461
461
if ( ch !== 44 /*,*/ ) break ;
462
462
pos ++ ;
463
463
ch = commentWhitespace ( ) ;
464
- if ( ch !== 103 /*g*/ || source . slice ( pos + 1 , pos + 3 ) !== 'et' ) break ;
464
+ if ( ch !== 103 /*g*/ || ! source . startsWith ( 'et' , pos + 1 ) ) break ;
465
465
pos += 3 ;
466
466
ch = commentWhitespace ( ) ;
467
467
if ( ch !== 58 /*:*/ ) break ;
468
468
pos ++ ;
469
469
ch = commentWhitespace ( ) ;
470
- if ( ch !== 102 /*f*/ || source . slice ( pos + 1 , pos + 8 ) !== 'unction' ) break ;
470
+ if ( ch !== 102 /*f*/ || ! source . startsWith ( 'unction' , pos + 1 ) ) break ;
471
471
pos += 8 ;
472
472
ch = commentWhitespace ( ) ;
473
473
if ( ch !== 40 /*(*/ ) break ;
@@ -479,16 +479,16 @@ function tryParseObjectDefineOrKeys (keys) {
479
479
if ( ch !== 123 /*{*/ ) break ;
480
480
pos ++ ;
481
481
ch = commentWhitespace ( ) ;
482
- if ( ch !== 114 /*r*/ || source . slice ( pos + 1 , pos + 6 ) !== 'eturn' ) break ;
482
+ if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
483
483
pos += 6 ;
484
484
ch = commentWhitespace ( ) ;
485
- if ( source . slice ( pos , pos + id . length ) !== id ) break ;
485
+ if ( ! source . startsWith ( id , pos ) ) break ;
486
486
pos += id . length ;
487
487
ch = commentWhitespace ( ) ;
488
488
if ( ch !== 91 /*[*/ ) break ;
489
489
pos ++ ;
490
490
ch = commentWhitespace ( ) ;
491
- if ( source . slice ( pos , pos + it_id . length ) !== it_id ) break ;
491
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
492
492
pos += it_id . length ;
493
493
ch = commentWhitespace ( ) ;
494
494
if ( ch !== 93 /*]*/ ) break ;
@@ -534,7 +534,7 @@ function tryParseObjectDefineOrKeys (keys) {
534
534
535
535
function readExportsOrModuleDotExports ( ch ) {
536
536
const revertPos = pos ;
537
- if ( ch === 109 /*m*/ && source . slice ( pos + 1 , pos + 6 ) === 'odule' ) {
537
+ if ( ch === 109 /*m*/ && source . startsWith ( 'odule' , pos + 1 ) ) {
538
538
pos += 6 ;
539
539
ch = commentWhitespace ( ) ;
540
540
if ( ch !== 46 /*.*/ ) {
@@ -544,7 +544,7 @@ function readExportsOrModuleDotExports (ch) {
544
544
pos ++ ;
545
545
ch = commentWhitespace ( ) ;
546
546
}
547
- if ( ch === 101 /*e*/ && source . slice ( pos + 1 , pos + 7 ) === 'xports' ) {
547
+ if ( ch === 101 /*e*/ && source . startsWith ( 'xports' , pos + 1 ) ) {
548
548
pos += 7 ;
549
549
return true ;
550
550
}
@@ -561,7 +561,7 @@ function tryParseModuleExportsDotAssign () {
561
561
if ( ch === 46 /*.*/ ) {
562
562
pos ++ ;
563
563
ch = commentWhitespace ( ) ;
564
- if ( ch === 101 /*e*/ && source . slice ( pos + 1 , pos + 7 ) === 'xports' ) {
564
+ if ( ch === 101 /*e*/ && source . startsWith ( 'xports' , pos + 1 ) ) {
565
565
tryParseExportsDotAssign ( true ) ;
566
566
return ;
567
567
}
@@ -632,7 +632,7 @@ function tryParseExportsDotAssign (assign) {
632
632
633
633
function tryParseRequire ( directStarExport ) {
634
634
// require('...')
635
- if ( source . slice ( pos + 1 , pos + 7 ) === 'equire' ) {
635
+ if ( source . startsWith ( 'equire' , pos + 1 ) ) {
636
636
pos += 7 ;
637
637
const revertPos = pos - 1 ;
638
638
let ch = commentWhitespace ( ) ;
@@ -1029,7 +1029,7 @@ function keywordStart (pos) {
1029
1029
function readPrecedingKeyword ( pos , match ) {
1030
1030
if ( pos < match . length - 1 )
1031
1031
return false ;
1032
- return source . slice ( pos - match . length + 1 , pos + 1 ) === match && ( pos === 0 || isBrOrWsOrPunctuatorNotDot ( source . charCodeAt ( pos - match . length ) ) ) ;
1032
+ return source . startsWith ( match , pos - match . length + 1 ) && ( pos === 0 || isBrOrWsOrPunctuatorNotDot ( source . charCodeAt ( pos - match . length ) ) ) ;
1033
1033
}
1034
1034
1035
1035
function readPrecedingKeyword1 ( pos , ch ) {
@@ -1111,8 +1111,8 @@ function isExpressionKeyword (pos) {
1111
1111
}
1112
1112
1113
1113
function isParenKeyword ( curPos ) {
1114
- return source . charCodeAt ( curPos ) === 101 /*e*/ && source . slice ( curPos - 4 , curPos ) === 'whil' ||
1115
- source . charCodeAt ( curPos ) === 114 /*r*/ && source . slice ( curPos - 2 , curPos ) === 'fo' ||
1114
+ return source . charCodeAt ( curPos ) === 101 /*e*/ && source . startsWith ( 'whil' , curPos - 4 ) ||
1115
+ source . charCodeAt ( curPos ) === 114 /*r*/ && source . startsWith ( 'fo' , curPos - 2 ) ||
1116
1116
source . charCodeAt ( curPos - 1 ) === 105 /*i*/ && source . charCodeAt ( curPos ) === 102 /*f*/ ;
1117
1117
}
1118
1118
@@ -1142,11 +1142,11 @@ function isExpressionTerminator (curPos) {
1142
1142
case 41 /*)*/ :
1143
1143
return true ;
1144
1144
case 104 /*h*/ :
1145
- return source . slice ( curPos - 4 , curPos ) === 'catc' ;
1145
+ return source . startsWith ( 'catc' , curPos - 4 ) ;
1146
1146
case 121 /*y*/ :
1147
- return source . slice ( curPos - 6 , curPos ) === 'finall' ;
1147
+ return source . startsWith ( 'finall' , curPos - 6 ) ;
1148
1148
case 101 /*e*/ :
1149
- return source . slice ( curPos - 3 , curPos ) === 'els' ;
1149
+ return source . startsWith ( 'els' , curPos - 3 ) ;
1150
1150
}
1151
1151
return false ;
1152
1152
}
0 commit comments