@@ -366,6 +366,10 @@ var defaultOptions = {
366366 // allowed and treated as a line comment. Enabled by default when
367367 // `ecmaVersion` >= 2023.
368368 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 ,
369373 // When `locations` is on, `loc` properties holding objects with
370374 // `start` and `end` properties in `{line, column}` form (with
371375 // line being 1-based and column 0-based) will be attached to the
@@ -1594,6 +1598,7 @@ pp$8.exitClassBody = function() {
15941598 var ref = this . privateNameStack . pop ( ) ;
15951599 var declared = ref . declared ;
15961600 var used = ref . used ;
1601+ if ( ! this . options . checkPrivateFields ) { return }
15971602 var len = this . privateNameStack . length ;
15981603 var parent = len === 0 ? null : this . privateNameStack [ len - 1 ] ;
15991604 for ( var i = 0 ; i < used . length ; ++ i ) {
@@ -2655,7 +2660,7 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
26552660 else { sawUnary = true ; }
26562661 expr = this . finishNode ( node , update ? "UpdateExpression" : "UnaryExpression" ) ;
26572662 } 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 ( ) ; }
26592664 expr = this . parsePrivateIdent ( ) ;
26602665 // only could be private fields in 'in', such as #x in obj
26612666 if ( this . type !== types$1 . _in ) { this . unexpected ( ) ; }
@@ -3498,10 +3503,12 @@ pp$5.parsePrivateIdent = function() {
34983503 this . finishNode ( node , "PrivateIdentifier" ) ;
34993504
35003505 // 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+ }
35053512 }
35063513
35073514 return node
@@ -5901,7 +5908,7 @@ pp.readWord = function() {
59015908// [walk]: util/walk.js
59025909
59035910
5904- var version = "8.9 .0" ;
5911+ var version = "8.10 .0" ;
59055912
59065913Parser . acorn = {
59075914 Parser : Parser ,
0 commit comments