@@ -68,6 +68,7 @@ public void ReleaseLargeBuffers()
6868 public bool InIteration ;
6969 public bool InSwitch ;
7070 public bool InClassConstructor ;
71+ public bool InClassBody ;
7172 public bool Strict ;
7273 public bool AllowIdentifierEscape ;
7374
@@ -758,6 +759,8 @@ private protected virtual Expression ParsePrimaryExpression()
758759 expr = Finalize ( node , new Literal ( token . RegexValue ! . Pattern , token . RegexValue . Flags , token . Value , raw ) ) ;
759760 break ;
760761 case "#" :
762+ if ( ! _context . InClassBody )
763+ ThrowUnexpectedToken ( _lookahead ) ;
761764 NextToken ( ) ;
762765 token = NextToken ( ) ;
763766 expr = Finalize ( node , new PrivateIdentifier ( ( string ) token . Value ! ) ) ;
@@ -958,6 +961,7 @@ private FunctionExpression ParsePropertyMethodFunction(bool isGenerator)
958961 var previousAllowYield = _context . AllowYield ;
959962 _context . AllowYield = true ;
960963 var parameters = ParseFormalParameters ( ) ;
964+ _context . AllowYield = ! isGenerator ;
961965 var method = ParsePropertyMethod ( ref parameters , out var hasStrictDirective ) ;
962966 _context . AllowYield = previousAllowYield ;
963967
@@ -3881,6 +3885,13 @@ private Statement ParseStatement()
38813885 case TokenType . Punctuator :
38823886 switch ( ( string ? ) _lookahead . Value )
38833887 {
3888+ case "#!" :
3889+ ThrowUnexpectedToken ( _lookahead ) ;
3890+ statement = null ;
3891+ break ;
3892+ case "#" :
3893+ statement = MatchAsyncFunction ( ) ? ParseFunctionDeclaration ( ) : ParseLabelledStatement ( ) ;
3894+ break ;
38843895 case "{" :
38853896 statement = ParseBlock ( ) ;
38863897 break ;
@@ -4635,6 +4646,7 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
46354646 var isAsync = false ;
46364647 var isGenerator = false ;
46374648 var isPrivate = false ;
4649+ var isAccessor = false ;
46384650
46394651 var decorators = ParseDecorators ( ) ;
46404652
@@ -4654,7 +4666,10 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
46544666 if ( Match ( "#" ) )
46554667 {
46564668 isPrivate = true ;
4669+ token = _lookahead ;
46574670 NextToken ( ) ;
4671+ if ( token . End != _lookahead . Start )
4672+ ThrowUnexpectedToken ( _lookahead ) ;
46584673 token = _lookahead ;
46594674 }
46604675 key = ParseObjectPropertyKey ( isPrivate ) ;
@@ -4675,11 +4690,16 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
46754690 computed = Match ( "[" ) ;
46764691 if ( Match ( "*" ) )
46774692 {
4693+ isGenerator = true ;
46784694 NextToken ( ) ;
4695+ computed = Match ( "[" ) ;
46794696 if ( Match ( "#" ) )
46804697 {
46814698 isPrivate = true ;
4699+ token = _lookahead ;
46824700 NextToken ( ) ;
4701+ if ( token . End != _lookahead . Start )
4702+ ThrowUnexpectedToken ( _lookahead ) ;
46834703 token = _lookahead ;
46844704 }
46854705 }
@@ -4688,11 +4708,14 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
46884708 if ( Match ( "#" ) )
46894709 {
46904710 isPrivate = true ;
4711+ token = _lookahead ;
46914712 NextToken ( ) ;
4713+ if ( token . End != _lookahead . Start )
4714+ ThrowUnexpectedToken ( _lookahead ) ;
46924715 token = _lookahead ;
46934716 }
4694- key = ParseObjectPropertyKey ( ) ;
46954717 }
4718+ key = ParseObjectPropertyKey ( ) ;
46964719 }
46974720 else if ( Match ( "{" ) )
46984721 {
@@ -4714,7 +4737,10 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
47144737 if ( Match ( "#" ) )
47154738 {
47164739 isPrivate = true ;
4740+ token = _lookahead ;
47174741 NextToken ( ) ;
4742+ if ( token . End != _lookahead . Start )
4743+ ThrowUnexpectedToken ( _lookahead ) ;
47184744 }
47194745
47204746 token = _lookahead ;
@@ -4728,6 +4754,21 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
47284754 }
47294755 }
47304756
4757+ if ( object . Equals ( token . Value , "accessor" ) && ( _lookahead . Type == TokenType . Identifier || object . Equals ( _lookahead . Value , "#" ) ) )
4758+ {
4759+ isAccessor = true ;
4760+ if ( Match ( "#" ) )
4761+ {
4762+ isPrivate = true ;
4763+ token = _lookahead ;
4764+ NextToken ( ) ;
4765+ if ( token . End != _lookahead . Start )
4766+ ThrowUnexpectedToken ( _lookahead ) ;
4767+ token = _lookahead ;
4768+ }
4769+ key = ParseObjectPropertyKey ( isPrivate ) ;
4770+ }
4771+
47314772 var lookaheadPropertyKey = QualifiedPropertyName ( _lookahead ) ;
47324773 if ( token . Type == TokenType . Identifier )
47334774 {
@@ -4737,7 +4778,10 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
47374778 if ( Match ( "#" ) )
47384779 {
47394780 isPrivate = true ;
4781+ token = _lookahead ;
47404782 NextToken ( ) ;
4783+ if ( token . End != _lookahead . Start )
4784+ ThrowUnexpectedToken ( _lookahead ) ;
47414785 token = _lookahead ;
47424786 }
47434787 computed = Match ( "[" ) ;
@@ -4751,7 +4795,10 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
47514795 if ( Match ( "#" ) )
47524796 {
47534797 isPrivate = true ;
4798+ token = _lookahead ;
47544799 NextToken ( ) ;
4800+ if ( token . End != _lookahead . Start )
4801+ ThrowUnexpectedToken ( _lookahead ) ;
47554802 token = _lookahead ;
47564803 }
47574804 computed = Match ( "[" ) ;
@@ -4776,7 +4823,10 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
47764823 if ( Match ( "#" ) )
47774824 {
47784825 isPrivate = true ;
4826+ token = _lookahead ;
47794827 NextToken ( ) ;
4828+ if ( token . End != _lookahead . Start )
4829+ ThrowUnexpectedToken ( _lookahead ) ;
47804830 token = _lookahead ;
47814831 }
47824832 computed = Match ( "[" ) ;
@@ -4813,7 +4863,7 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
48134863
48144864 if ( ! computed )
48154865 {
4816- if ( isStatic && IsPropertyKey ( key ! , "prototype" ) )
4866+ if ( isStatic && ! isPrivate && IsPropertyKey ( key ! , "prototype" ) )
48174867 {
48184868 ThrowUnexpectedToken ( token , Messages . StaticPrototype ) ;
48194869 }
@@ -4838,6 +4888,12 @@ private ClassElement ParseClassElement(ref bool hasConstructor)
48384888 }
48394889 }
48404890
4891+ if ( isAccessor )
4892+ {
4893+ ConsumeSemicolon ( ) ;
4894+ return Finalize ( node , new AccessorProperty ( key ! , computed , value ! , isStatic , NodeList . From ( ref decorators ) ) ) ;
4895+ }
4896+
48414897 if ( kind == PropertyKind . Property )
48424898 {
48434899 ConsumeSemicolon ( ) ;
@@ -4873,7 +4929,10 @@ private ArrayList<ClassElement> ParseClassElementList()
48734929 private ClassBody ParseClassBody ( )
48744930 {
48754931 var node = CreateNode ( ) ;
4932+ var previousInClassBody = _context . InClassBody ;
4933+ _context . InClassBody = true ;
48764934 var elementList = ParseClassElementList ( ) ;
4935+ _context . InClassBody = previousInClassBody ;
48774936
48784937 return Finalize ( node , new ClassBody ( NodeList . From ( ref elementList ) ) ) ;
48794938 }
0 commit comments