487
487
SCOPE_SUPER = 64 ,
488
488
SCOPE_DIRECT_SUPER = 128 ,
489
489
SCOPE_CLASS_STATIC_BLOCK = 256 ,
490
+ SCOPE_CLASS_FIELD_INIT = 512 ,
490
491
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK ;
491
492
492
493
function functionFlags ( async , generator ) {
@@ -597,35 +598,38 @@ Parser.prototype.parse = function parse () {
597
598
598
599
prototypeAccessors . inFunction . get = function ( ) { return ( this . currentVarScope ( ) . flags & SCOPE_FUNCTION ) > 0 } ;
599
600
600
- prototypeAccessors . inGenerator . get = function ( ) { return ( this . currentVarScope ( ) . flags & SCOPE_GENERATOR ) > 0 && ! this . currentVarScope ( ) . inClassFieldInit } ;
601
+ prototypeAccessors . inGenerator . get = function ( ) { return ( this . currentVarScope ( ) . flags & SCOPE_GENERATOR ) > 0 } ;
601
602
602
- prototypeAccessors . inAsync . get = function ( ) { return ( this . currentVarScope ( ) . flags & SCOPE_ASYNC ) > 0 && ! this . currentVarScope ( ) . inClassFieldInit } ;
603
+ prototypeAccessors . inAsync . get = function ( ) { return ( this . currentVarScope ( ) . flags & SCOPE_ASYNC ) > 0 } ;
603
604
604
605
prototypeAccessors . canAwait . get = function ( ) {
605
606
for ( var i = this . scopeStack . length - 1 ; i >= 0 ; i -- ) {
606
- var scope = this . scopeStack [ i ] ;
607
- if ( scope . inClassFieldInit || scope . flags & SCOPE_CLASS_STATIC_BLOCK ) { return false }
608
- if ( scope . flags & SCOPE_FUNCTION ) { return ( scope . flags & SCOPE_ASYNC ) > 0 }
607
+ var ref = this . scopeStack [ i ] ;
608
+ var flags = ref . flags ;
609
+ if ( flags & ( SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT ) ) { return false }
610
+ if ( flags & SCOPE_FUNCTION ) { return ( flags & SCOPE_ASYNC ) > 0 }
609
611
}
610
612
return ( this . inModule && this . options . ecmaVersion >= 13 ) || this . options . allowAwaitOutsideFunction
611
613
} ;
612
614
613
615
prototypeAccessors . allowSuper . get = function ( ) {
614
616
var ref = this . currentThisScope ( ) ;
615
617
var flags = ref . flags ;
616
- var inClassFieldInit = ref . inClassFieldInit ;
617
- return ( flags & SCOPE_SUPER ) > 0 || inClassFieldInit || this . options . allowSuperOutsideMethod
618
+ return ( flags & SCOPE_SUPER ) > 0 || this . options . allowSuperOutsideMethod
618
619
} ;
619
620
620
621
prototypeAccessors . allowDirectSuper . get = function ( ) { return ( this . currentThisScope ( ) . flags & SCOPE_DIRECT_SUPER ) > 0 } ;
621
622
622
623
prototypeAccessors . treatFunctionsAsVar . get = function ( ) { return this . treatFunctionsAsVarInScope ( this . currentScope ( ) ) } ;
623
624
624
625
prototypeAccessors . allowNewDotTarget . get = function ( ) {
625
- var ref = this . currentThisScope ( ) ;
626
- var flags = ref . flags ;
627
- var inClassFieldInit = ref . inClassFieldInit ;
628
- return ( flags & ( SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK ) ) > 0 || inClassFieldInit
626
+ for ( var i = this . scopeStack . length - 1 ; i >= 0 ; i -- ) {
627
+ var ref = this . scopeStack [ i ] ;
628
+ var flags = ref . flags ;
629
+ if ( flags & ( SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT ) ||
630
+ ( ( flags & SCOPE_FUNCTION ) && ! ( flags & SCOPE_ARROW ) ) ) { return true }
631
+ }
632
+ return false
629
633
} ;
630
634
631
635
prototypeAccessors . inClassStaticBlock . get = function ( ) {
@@ -1552,11 +1556,9 @@ pp$8.parseClassField = function(field) {
1552
1556
1553
1557
if ( this . eat ( types$1 . eq ) ) {
1554
1558
// To raise SyntaxError if 'arguments' exists in the initializer.
1555
- var scope = this . currentThisScope ( ) ;
1556
- var inClassFieldInit = scope . inClassFieldInit ;
1557
- scope . inClassFieldInit = true ;
1559
+ this . enterScope ( SCOPE_CLASS_FIELD_INIT | SCOPE_SUPER ) ;
1558
1560
field . value = this . parseMaybeAssign ( ) ;
1559
- scope . inClassFieldInit = inClassFieldInit ;
1561
+ this . exitScope ( ) ;
1560
1562
} else {
1561
1563
field . value = null ;
1562
1564
}
@@ -1698,6 +1700,8 @@ pp$8.parseExport = function(node, exports) {
1698
1700
{ this . checkExport ( exports , node . declaration . id , node . declaration . id . start ) ; }
1699
1701
node . specifiers = [ ] ;
1700
1702
node . source = null ;
1703
+ if ( this . options . ecmaVersion >= 16 )
1704
+ { node . attributes = [ ] ; }
1701
1705
} else { // export { x, y as z } [from '...']
1702
1706
node . declaration = null ;
1703
1707
node . specifiers = this . parseExportSpecifiers ( exports ) ;
@@ -1721,6 +1725,8 @@ pp$8.parseExport = function(node, exports) {
1721
1725
}
1722
1726
1723
1727
node . source = null ;
1728
+ if ( this . options . ecmaVersion >= 16 )
1729
+ { node . attributes = [ ] ; }
1724
1730
}
1725
1731
this . semicolon ( ) ;
1726
1732
}
@@ -3300,9 +3306,10 @@ pp$5.parseProperty = function(isPattern, refDestructuringErrors) {
3300
3306
} ;
3301
3307
3302
3308
pp$5 . parseGetterSetter = function ( prop ) {
3303
- prop . kind = prop . key . name ;
3309
+ var kind = prop . key . name ;
3304
3310
this . parsePropertyName ( prop ) ;
3305
3311
prop . value = this . parseMethod ( false ) ;
3312
+ prop . kind = kind ;
3306
3313
var paramCount = prop . kind === "get" ? 0 : 1 ;
3307
3314
if ( prop . value . params . length !== paramCount ) {
3308
3315
var start = prop . value . start ;
@@ -3325,9 +3332,9 @@ pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP
3325
3332
prop . kind = "init" ;
3326
3333
} else if ( this . options . ecmaVersion >= 6 && this . type === types$1 . parenL ) {
3327
3334
if ( isPattern ) { this . unexpected ( ) ; }
3328
- prop . kind = "init" ;
3329
3335
prop . method = true ;
3330
3336
prop . value = this . parseMethod ( isGenerator , isAsync ) ;
3337
+ prop . kind = "init" ;
3331
3338
} else if ( ! isPattern && ! containsEsc &&
3332
3339
this . options . ecmaVersion >= 5 && ! prop . computed && prop . key . type === "Identifier" &&
3333
3340
( prop . key . name === "get" || prop . key . name === "set" ) &&
@@ -3339,7 +3346,6 @@ pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP
3339
3346
this . checkUnreserved ( prop . key ) ;
3340
3347
if ( prop . key . name === "await" && ! this . awaitIdentPos )
3341
3348
{ this . awaitIdentPos = startPos ; }
3342
- prop . kind = "init" ;
3343
3349
if ( isPattern ) {
3344
3350
prop . value = this . parseMaybeDefault ( startPos , startLoc , this . copyNode ( prop . key ) ) ;
3345
3351
} else if ( this . type === types$1 . eq && refDestructuringErrors ) {
@@ -3349,6 +3355,7 @@ pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP
3349
3355
} else {
3350
3356
prop . value = this . copyNode ( prop . key ) ;
3351
3357
}
3358
+ prop . kind = "init" ;
3352
3359
prop . shorthand = true ;
3353
3360
} else { this . unexpected ( ) ; }
3354
3361
} ;
@@ -3524,7 +3531,7 @@ pp$5.checkUnreserved = function(ref) {
3524
3531
{ this . raiseRecoverable ( start , "Cannot use 'yield' as identifier inside a generator" ) ; }
3525
3532
if ( this . inAsync && name === "await" )
3526
3533
{ this . raiseRecoverable ( start , "Cannot use 'await' as identifier inside an async function" ) ; }
3527
- if ( this . currentThisScope ( ) . inClassFieldInit && name === "arguments" )
3534
+ if ( ! ( this . currentThisScope ( ) . flags & SCOPE_VAR ) && name === "arguments" )
3528
3535
{ this . raiseRecoverable ( start , "Cannot use 'arguments' in class field initializer" ) ; }
3529
3536
if ( this . inClassStaticBlock && ( name === "arguments" || name === "await" ) )
3530
3537
{ this . raise ( start , ( "Cannot use " + name + " in class static initialization block" ) ) ; }
@@ -3637,6 +3644,9 @@ var pp$4 = Parser.prototype;
3637
3644
pp$4 . raise = function ( pos , message ) {
3638
3645
var loc = getLineInfo ( this . input , pos ) ;
3639
3646
message += " (" + loc . line + ":" + loc . column + ")" ;
3647
+ if ( this . sourceFile ) {
3648
+ message += " in " + this . sourceFile ;
3649
+ }
3640
3650
var err = new SyntaxError ( message ) ;
3641
3651
err . pos = pos ; err . loc = loc ; err . raisedAt = this . pos ;
3642
3652
throw err
@@ -3660,8 +3670,6 @@ var Scope = function Scope(flags) {
3660
3670
this . lexical = [ ] ;
3661
3671
// A list of lexically-declared FunctionDeclaration names in the current lexical scope
3662
3672
this . functions = [ ] ;
3663
- // A switch to disallow the identifier reference 'arguments'
3664
- this . inClassFieldInit = false ;
3665
3673
} ;
3666
3674
3667
3675
// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
@@ -3731,15 +3739,16 @@ pp$3.currentScope = function() {
3731
3739
pp$3 . currentVarScope = function ( ) {
3732
3740
for ( var i = this . scopeStack . length - 1 ; ; i -- ) {
3733
3741
var scope = this . scopeStack [ i ] ;
3734
- if ( scope . flags & SCOPE_VAR ) { return scope }
3742
+ if ( scope . flags & ( SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK ) ) { return scope }
3735
3743
}
3736
3744
} ;
3737
3745
3738
3746
// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
3739
3747
pp$3 . currentThisScope = function ( ) {
3740
3748
for ( var i = this . scopeStack . length - 1 ; ; i -- ) {
3741
3749
var scope = this . scopeStack [ i ] ;
3742
- if ( scope . flags & SCOPE_VAR && ! ( scope . flags & SCOPE_ARROW ) ) { return scope }
3750
+ if ( scope . flags & ( SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK ) &&
3751
+ ! ( scope . flags & SCOPE_ARROW ) ) { return scope }
3743
3752
}
3744
3753
} ;
3745
3754
@@ -6093,7 +6102,7 @@ pp.readWord = function() {
6093
6102
// [walk]: util/walk.js
6094
6103
6095
6104
6096
- var version = "8.14.0 " ;
6105
+ var version = "8.14.1 " ;
6097
6106
6098
6107
Parser . acorn = {
6099
6108
Parser : Parser ,
0 commit comments