@@ -665,6 +665,10 @@ private Expression ParsePrimaryExpression()
665
665
{
666
666
expr = ParseClassExpression ( ) ;
667
667
}
668
+ else if ( MatchKeyword ( "new" ) )
669
+ {
670
+ expr = ParseNewExpression ( ) ;
671
+ }
668
672
else if ( MatchImportCall ( ) )
669
673
{
670
674
expr = ParseImportCall ( ) ;
@@ -833,7 +837,7 @@ private FunctionExpression ParsePropertyMethodAsyncFunction(bool isGenerator)
833
837
return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , isGenerator , hasStrictDirective , true ) ) ;
834
838
}
835
839
836
- private Expression ParseObjectPropertyKey ( )
840
+ private Expression ParseObjectPropertyKey ( Boolean isPrivate = false )
837
841
{
838
842
var node = CreateNode ( ) ;
839
843
var token = NextToken ( ) ;
@@ -865,7 +869,7 @@ private Expression ParseObjectPropertyKey()
865
869
case TokenType . BooleanLiteral :
866
870
case TokenType . NullLiteral :
867
871
case TokenType . Keyword :
868
- key = Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
872
+ key = isPrivate ? Finalize ( node , new PrivateIdentifier ( ( string ? ) token . Value ) ) : Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
869
873
break ;
870
874
871
875
case TokenType . Punctuator :
@@ -963,7 +967,7 @@ private Property ParseObjectProperty(Token hasProto)
963
967
kind = PropertyKind . Init ;
964
968
computed = Match ( "[" ) ;
965
969
key = ParseObjectPropertyKey ( ) ;
966
- value = ParseGeneratorMethod ( ) ;
970
+ value = ParseGeneratorMethod ( isAsync ) ;
967
971
method = true ;
968
972
}
969
973
else
@@ -1419,6 +1423,29 @@ private Identifier ParseIdentifierName()
1419
1423
return Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
1420
1424
}
1421
1425
1426
+ private Expression ParseIdentifierOrPrivateIdentifierName ( )
1427
+ {
1428
+ var isPrivateField = false ;
1429
+
1430
+ var node = CreateNode ( ) ;
1431
+
1432
+ var token = NextToken ( ) ;
1433
+
1434
+ if ( Equals ( token . Value , "#" ) )
1435
+ {
1436
+ token = NextToken ( ) ;
1437
+ token . Value = '#' + ( string ? ) token . Value ;
1438
+ isPrivateField = true ;
1439
+ }
1440
+
1441
+ if ( ! IsIdentifierName ( token ) )
1442
+ {
1443
+ return ThrowUnexpectedToken < Identifier > ( token ) ;
1444
+ }
1445
+
1446
+ return isPrivateField ? Finalize ( node , new PrivateIdentifier ( ( string ? ) token . Value ) ) : Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
1447
+ }
1448
+
1422
1449
private Expression ParseNewExpression ( )
1423
1450
{
1424
1451
var node = CreateNode ( ) ;
@@ -1655,7 +1682,7 @@ private Expression ParseLeftHandSideExpressionAllowCall()
1655
1682
Expect ( "." ) ;
1656
1683
}
1657
1684
1658
- var property = ParseIdentifierName ( ) ;
1685
+ var property = ParseIdentifierOrPrivateIdentifierName ( ) ;
1659
1686
expr = Finalize ( StartNode ( startToken ) , new StaticMemberExpression ( expr , property , optional ) ) ;
1660
1687
}
1661
1688
else
@@ -4143,7 +4170,7 @@ private static bool QualifiedPropertyName(Token token)
4143
4170
TokenType . NullLiteral => true ,
4144
4171
TokenType . NumericLiteral => true ,
4145
4172
TokenType . Keyword => true ,
4146
- TokenType . Punctuator => Equals ( token . Value , "[" ) ,
4173
+ TokenType . Punctuator => Equals ( token . Value , "[" ) || Equals ( token . Value , "#" ) ,
4147
4174
_ => false
4148
4175
} ;
4149
4176
}
@@ -4191,7 +4218,7 @@ private FunctionExpression ParseSetterMethod()
4191
4218
return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref formalParameters . Parameters ) , method , isGenerator , hasStrictDirective , false ) ) ;
4192
4219
}
4193
4220
4194
- private FunctionExpression ParseGeneratorMethod ( )
4221
+ private FunctionExpression ParseGeneratorMethod ( bool isAsync = false )
4195
4222
{
4196
4223
var node = CreateNode ( ) ;
4197
4224
@@ -4203,7 +4230,7 @@ private FunctionExpression ParseGeneratorMethod()
4203
4230
var method = ParsePropertyMethod ( parameters , out var hasStrictDirective ) ;
4204
4231
_context . AllowYield = previousAllowYield ;
4205
4232
4206
- return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , true , hasStrictDirective , false ) ) ;
4233
+ return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , true , hasStrictDirective , isAsync ) ) ;
4207
4234
}
4208
4235
4209
4236
// https://tc39.github.io/ecma262/#sec-generator-function-definitions
@@ -4300,12 +4327,13 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4300
4327
4301
4328
var kind = PropertyKind . None ;
4302
4329
Expression ? key = null ;
4303
- FunctionExpression ? value = null ;
4330
+ Expression ? value = null ;
4304
4331
var computed = false ;
4305
4332
var method = false ;
4306
4333
var isStatic = false ;
4307
4334
var isAsync = false ;
4308
- var isGenerator = false ;
4335
+ var isGenerator = false ;
4336
+ var isPrivate = false ;
4309
4337
4310
4338
if ( Match ( "*" ) )
4311
4339
{
@@ -4315,10 +4343,17 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4315
4343
else
4316
4344
{
4317
4345
computed = Match ( "[" ) ;
4318
- key = ParseObjectPropertyKey ( ) ;
4346
+ if ( Match ( "#" ) )
4347
+ {
4348
+ isPrivate = true ;
4349
+ NextToken ( ) ;
4350
+ token = _lookahead ;
4351
+ }
4352
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4319
4353
var id = key switch
4320
4354
{
4321
4355
Identifier identifier => identifier . Name ,
4356
+ PrivateIdentifier privateIdentifier => privateIdentifier . Name ,
4322
4357
Literal literal => literal . StringValue , // "constructor"
4323
4358
_ => null
4324
4359
} ;
@@ -4331,9 +4366,21 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4331
4366
if ( Match ( "*" ) )
4332
4367
{
4333
4368
NextToken ( ) ;
4369
+ if ( Match ( "#" ) )
4370
+ {
4371
+ isPrivate = true ;
4372
+ NextToken ( ) ;
4373
+ token = _lookahead ;
4374
+ }
4334
4375
}
4335
4376
else
4336
4377
{
4378
+ if ( Match ( "#" ) )
4379
+ {
4380
+ isPrivate = true ;
4381
+ NextToken ( ) ;
4382
+ token = _lookahead ;
4383
+ }
4337
4384
key = ParseObjectPropertyKey ( ) ;
4338
4385
}
4339
4386
}
@@ -4347,11 +4394,17 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4347
4394
if ( isGenerator )
4348
4395
{
4349
4396
NextToken ( ) ;
4397
+ }
4398
+
4399
+ if ( Match ( "#" ) )
4400
+ {
4401
+ isPrivate = true ;
4402
+ NextToken ( ) ;
4350
4403
}
4351
4404
4352
4405
token = _lookahead ;
4353
4406
computed = Match ( "[" ) ;
4354
- key = ParseObjectPropertyKey ( ) ;
4407
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4355
4408
if ( token . Type == TokenType . Identifier && ( string ? ) token . Value == "constructor" )
4356
4409
{
4357
4410
TolerateUnexpectedToken ( token , Messages . ConstructorIsAsync ) ;
@@ -4365,26 +4418,49 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4365
4418
{
4366
4419
if ( lookaheadPropertyKey && ( string ? ) token . Value == "get" )
4367
4420
{
4368
- kind = PropertyKind . Get ;
4421
+ kind = PropertyKind . Get ;
4422
+ if ( Match ( "#" ) )
4423
+ {
4424
+ isPrivate = true ;
4425
+ NextToken ( ) ;
4426
+ token = _lookahead ;
4427
+ }
4369
4428
computed = Match ( "[" ) ;
4370
- key = ParseObjectPropertyKey ( ) ;
4429
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4371
4430
_context . AllowYield = false ;
4372
4431
value = ParseGetterMethod ( ) ;
4373
4432
}
4374
4433
else if ( lookaheadPropertyKey && ( string ? ) token . Value == "set" )
4375
4434
{
4376
4435
kind = PropertyKind . Set ;
4436
+ if ( Match ( "#" ) )
4437
+ {
4438
+ isPrivate = true ;
4439
+ NextToken ( ) ;
4440
+ token = _lookahead ;
4441
+ }
4377
4442
computed = Match ( "[" ) ;
4378
- key = ParseObjectPropertyKey ( ) ;
4379
- value = ParseSetterMethod ( ) ;
4443
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4444
+ value = ParseSetterMethod ( ) ;
4445
+ }
4446
+ else if ( ! Match ( "(" ) )
4447
+ {
4448
+ kind = PropertyKind . Property ;
4449
+ computed = false ;
4450
+
4451
+ if ( Match ( "=" ) )
4452
+ {
4453
+ NextToken ( ) ;
4454
+ value = IsolateCoverGrammar ( this . parseAssignmentExpression ) ;
4455
+ }
4380
4456
}
4381
4457
}
4382
4458
else if ( token . Type == TokenType . Punctuator && ( string ? ) token . Value == "*" && lookaheadPropertyKey )
4383
4459
{
4384
4460
kind = PropertyKind . Init ;
4385
4461
computed = Match ( "[" ) ;
4386
- key = ParseObjectPropertyKey ( ) ;
4387
- value = ParseGeneratorMethod ( ) ;
4462
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4463
+ value = ParseGeneratorMethod ( isAsync ) ;
4388
4464
method = true ;
4389
4465
}
4390
4466
@@ -4420,7 +4496,7 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4420
4496
4421
4497
if ( ! isStatic && IsPropertyKey ( key ! , "constructor" ) )
4422
4498
{
4423
- if ( kind != PropertyKind . Method || ! method || value ! . Generator )
4499
+ if ( kind != PropertyKind . Method || ! method || ( ( FunctionExpression ) value ! ) . Generator )
4424
4500
{
4425
4501
ThrowUnexpectedToken ( token , Messages . ConstructorSpecialMethod ) ;
4426
4502
}
@@ -4436,10 +4512,15 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4436
4512
4437
4513
kind = PropertyKind . Constructor ;
4438
4514
}
4439
- }
4440
-
4441
-
4442
- return Finalize ( node , new MethodDefinition ( key ! , computed , value ! , kind , isStatic ) ) ;
4515
+ }
4516
+
4517
+ if ( kind == PropertyKind . Property )
4518
+ {
4519
+ ConsumeSemicolon ( ) ;
4520
+ return Finalize ( node , new PropertyDefinition ( key ! , computed , value ! , isStatic ) ) ;
4521
+ }
4522
+
4523
+ return Finalize ( node , new MethodDefinition ( key ! , computed , ( FunctionExpression ) value ! , kind , isStatic ) ) ;
4443
4524
}
4444
4525
4445
4526
private ArrayList < ClassProperty > ParseClassElementList ( )
0 commit comments