@@ -78,6 +78,7 @@ import { cloneIdentifier } from "./node";
7878
7979/*::
8080import type { SourceType } from "../options";
81+ declare var invariant;
8182*/
8283
8384const invalidHackPipeBodies = new Map ( [
@@ -329,6 +330,14 @@ export default class ExpressionParser extends LValParser {
329330 ) {
330331 refExpressionErrors . shorthandAssignLoc = null ; // reset because shorthand default was used correctly
331332 }
333+ if (
334+ refExpressionErrors . privateKeyLoc != null &&
335+ // $FlowIgnore[incompatible-type] We know this exists, so it can't be undefined.
336+ indexes . get ( refExpressionErrors . privateKeyLoc ) >= startPos
337+ ) {
338+ this . checkDestructuringPrivate ( refExpressionErrors ) ;
339+ refExpressionErrors . privateKeyLoc = null ; // reset because `({ #x: x })` is an assignable pattern
340+ }
332341 } else {
333342 node . left = left ;
334343 }
@@ -843,13 +852,14 @@ export default class ExpressionParser extends LValParser {
843852
844853 let node = this . startNodeAt ( startPos , startLoc ) ;
845854 node . callee = base ;
855+ const { maybeAsyncArrow, optionalChainMember } = state ;
846856
847- if ( state . maybeAsyncArrow ) {
857+ if ( maybeAsyncArrow ) {
848858 this . expressionScope . enter ( newAsyncArrowScope ( ) ) ;
849859 refExpressionErrors = new ExpressionErrors ( ) ;
850860 }
851861
852- if ( state . optionalChainMember ) {
862+ if ( optionalChainMember ) {
853863 node . optional = optional ;
854864 }
855865
@@ -864,18 +874,20 @@ export default class ExpressionParser extends LValParser {
864874 refExpressionErrors ,
865875 ) ;
866876 }
867- this . finishCallExpression ( node , state . optionalChainMember ) ;
877+ this . finishCallExpression ( node , optionalChainMember ) ;
868878
869- if ( state . maybeAsyncArrow && this . shouldParseAsyncArrow ( ) && ! optional ) {
879+ if ( maybeAsyncArrow && this . shouldParseAsyncArrow ( ) && ! optional ) {
880+ /*:: invariant(refExpressionErrors != null) */
870881 state . stop = true ;
882+ this . checkDestructuringPrivate ( refExpressionErrors ) ;
871883 this . expressionScope . validateAsPattern ( ) ;
872884 this . expressionScope . exit ( ) ;
873885 node = this . parseAsyncArrowFromCallExpression (
874886 this . startNodeAt ( startPos , startLoc ) ,
875887 node ,
876888 ) ;
877889 } else {
878- if ( state . maybeAsyncArrow ) {
890+ if ( maybeAsyncArrow ) {
879891 this . checkExpressionErrors ( refExpressionErrors , true ) ;
880892 this . expressionScope . exit ( ) ;
881893 }
@@ -1738,6 +1750,7 @@ export default class ExpressionParser extends LValParser {
17381750 this . shouldParseArrow ( exprList ) &&
17391751 ( arrowNode = this . parseArrow ( arrowNode ) )
17401752 ) {
1753+ this . checkDestructuringPrivate ( refExpressionErrors ) ;
17411754 this . expressionScope . validateAsPattern ( ) ;
17421755 this . expressionScope . exit ( ) ;
17431756 this . parseArrowExpression ( arrowNode , exprList , false ) ;
@@ -2040,7 +2053,7 @@ export default class ExpressionParser extends LValParser {
20402053 let isGenerator = this . eat ( tt . star ) ;
20412054 this . parsePropertyNamePrefixOperator ( prop ) ;
20422055 const containsEsc = this . state . containsEsc ;
2043- const key = this . parsePropertyName ( prop ) ;
2056+ const key = this . parsePropertyName ( prop , refExpressionErrors ) ;
20442057
20452058 if ( ! isGenerator && ! containsEsc && this . maybeAsyncOrAccessorProp ( prop ) ) {
20462059 const keyName = key . name ;
@@ -2245,8 +2258,12 @@ export default class ExpressionParser extends LValParser {
22452258 return node ;
22462259 }
22472260
2261+ // https://tc39.es/ecma262/#prod-PropertyName
2262+ // when refExpressionErrors presents, it will parse private name
2263+ // and record the position of the first private name
22482264 parsePropertyName (
22492265 prop : N . ObjectOrClassMember | N . ClassMember | N . TsNamedTypeElementBase ,
2266+ refExpressionErrors ?: ?ExpressionErrors ,
22502267 ) : N . Expression | N . Identifier {
22512268 if ( this . eat ( tt . bracketL ) ) {
22522269 ( prop : $FlowSubtype < N . ObjectOrClassMember > ) . computed = true ;
@@ -2275,10 +2292,16 @@ export default class ExpressionParser extends LValParser {
22752292 break ;
22762293 case tt . privateName : {
22772294 // the class private key has been handled in parseClassElementName
2278- this . raise ( Errors . UnexpectedPrivateField , {
2279- // FIXME: explain
2280- at : createPositionWithColumnOffset ( this . state . startLoc , 1 ) ,
2281- } ) ;
2295+ const privateKeyLoc = this . state . startLoc ;
2296+ if ( refExpressionErrors != null ) {
2297+ if ( refExpressionErrors . privateKeyLoc === null ) {
2298+ refExpressionErrors . privateKeyLoc = privateKeyLoc ;
2299+ }
2300+ } else {
2301+ this . raise ( Errors . UnexpectedPrivateField , {
2302+ at : privateKeyLoc ,
2303+ } ) ;
2304+ }
22822305 key = this . parsePrivateName ( ) ;
22832306 break ;
22842307 }
0 commit comments