@@ -366,6 +366,10 @@ var defaultOptions = {
366
366
// allowed and treated as a line comment. Enabled by default when
367
367
// `ecmaVersion` >= 2023.
368
368
allowHashBang : false ,
369
+ // By default, the parser will verify that private properties are
370
+ // only used in places where they are valid and have been declared.
371
+ // Set this to false to turn such checks off.
372
+ checkPrivateFields : true ,
369
373
// When `locations` is on, `loc` properties holding objects with
370
374
// `start` and `end` properties in `{line, column}` form (with
371
375
// line being 1-based and column 0-based) will be attached to the
@@ -1594,6 +1598,7 @@ pp$8.exitClassBody = function() {
1594
1598
var ref = this . privateNameStack . pop ( ) ;
1595
1599
var declared = ref . declared ;
1596
1600
var used = ref . used ;
1601
+ if ( ! this . options . checkPrivateFields ) { return }
1597
1602
var len = this . privateNameStack . length ;
1598
1603
var parent = len === 0 ? null : this . privateNameStack [ len - 1 ] ;
1599
1604
for ( var i = 0 ; i < used . length ; ++ i ) {
@@ -2655,7 +2660,7 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
2655
2660
else { sawUnary = true ; }
2656
2661
expr = this . finishNode ( node , update ? "UpdateExpression" : "UnaryExpression" ) ;
2657
2662
} else if ( ! sawUnary && this . type === types$1 . privateId ) {
2658
- if ( forInit || this . privateNameStack . length === 0 ) { this . unexpected ( ) ; }
2663
+ if ( ( forInit || this . privateNameStack . length === 0 ) && this . options . checkPrivateFields ) { this . unexpected ( ) ; }
2659
2664
expr = this . parsePrivateIdent ( ) ;
2660
2665
// only could be private fields in 'in', such as #x in obj
2661
2666
if ( this . type !== types$1 . _in ) { this . unexpected ( ) ; }
@@ -3498,10 +3503,12 @@ pp$5.parsePrivateIdent = function() {
3498
3503
this . finishNode ( node , "PrivateIdentifier" ) ;
3499
3504
3500
3505
// For validating existence
3501
- if ( this . privateNameStack . length === 0 ) {
3502
- this . raise ( node . start , ( "Private field '#" + ( node . name ) + "' must be declared in an enclosing class" ) ) ;
3503
- } else {
3504
- this . privateNameStack [ this . privateNameStack . length - 1 ] . used . push ( node ) ;
3506
+ if ( this . options . checkPrivateFields ) {
3507
+ if ( this . privateNameStack . length === 0 ) {
3508
+ this . raise ( node . start , ( "Private field '#" + ( node . name ) + "' must be declared in an enclosing class" ) ) ;
3509
+ } else {
3510
+ this . privateNameStack [ this . privateNameStack . length - 1 ] . used . push ( node ) ;
3511
+ }
3505
3512
}
3506
3513
3507
3514
return node
@@ -5901,7 +5908,7 @@ pp.readWord = function() {
5901
5908
// [walk]: util/walk.js
5902
5909
5903
5910
5904
- var version = "8.9 .0" ;
5911
+ var version = "8.10 .0" ;
5905
5912
5906
5913
Parser . acorn = {
5907
5914
Parser : Parser ,
0 commit comments