@@ -666,6 +666,10 @@ private Expression ParsePrimaryExpression()
666
666
{
667
667
expr = ParseClassExpression ( ) ;
668
668
}
669
+ else if ( MatchKeyword ( "new" ) )
670
+ {
671
+ expr = ParseNewExpression ( ) ;
672
+ }
669
673
else if ( MatchImportCall ( ) )
670
674
{
671
675
expr = ParseImportCall ( ) ;
@@ -834,7 +838,7 @@ private FunctionExpression ParsePropertyMethodAsyncFunction(bool isGenerator)
834
838
return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , isGenerator , hasStrictDirective , true ) ) ;
835
839
}
836
840
837
- private Expression ParseObjectPropertyKey ( )
841
+ private Expression ParseObjectPropertyKey ( Boolean isPrivate = false )
838
842
{
839
843
var node = CreateNode ( ) ;
840
844
var token = NextToken ( ) ;
@@ -866,7 +870,7 @@ private Expression ParseObjectPropertyKey()
866
870
case TokenType . BooleanLiteral :
867
871
case TokenType . NullLiteral :
868
872
case TokenType . Keyword :
869
- key = Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
873
+ key = isPrivate ? Finalize ( node , new PrivateIdentifier ( ( string ? ) token . Value ) ) : Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
870
874
break ;
871
875
872
876
case TokenType . Punctuator :
@@ -964,7 +968,7 @@ private Property ParseObjectProperty(Token hasProto)
964
968
kind = PropertyKind . Init ;
965
969
computed = Match ( "[" ) ;
966
970
key = ParseObjectPropertyKey ( ) ;
967
- value = ParseGeneratorMethod ( ) ;
971
+ value = ParseGeneratorMethod ( isAsync ) ;
968
972
method = true ;
969
973
}
970
974
else
@@ -1420,6 +1424,29 @@ private Identifier ParseIdentifierName()
1420
1424
return Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
1421
1425
}
1422
1426
1427
+ private Expression ParseIdentifierOrPrivateIdentifierName ( )
1428
+ {
1429
+ var isPrivateField = false ;
1430
+
1431
+ var node = CreateNode ( ) ;
1432
+
1433
+ var token = NextToken ( ) ;
1434
+
1435
+ if ( Equals ( token . Value , "#" ) )
1436
+ {
1437
+ token = NextToken ( ) ;
1438
+ token . Value = '#' + ( string ? ) token . Value ;
1439
+ isPrivateField = true ;
1440
+ }
1441
+
1442
+ if ( ! IsIdentifierName ( token ) )
1443
+ {
1444
+ return ThrowUnexpectedToken < Identifier > ( token ) ;
1445
+ }
1446
+
1447
+ return isPrivateField ? Finalize ( node , new PrivateIdentifier ( ( string ? ) token . Value ) ) : Finalize ( node , new Identifier ( ( string ? ) token . Value ) ) ;
1448
+ }
1449
+
1423
1450
private Expression ParseNewExpression ( )
1424
1451
{
1425
1452
var node = CreateNode ( ) ;
@@ -1672,7 +1699,7 @@ private Expression ParseLeftHandSideExpressionAllowCall()
1672
1699
Expect ( "." ) ;
1673
1700
}
1674
1701
1675
- var property = ParseIdentifierName ( ) ;
1702
+ var property = ParseIdentifierOrPrivateIdentifierName ( ) ;
1676
1703
expr = Finalize ( StartNode ( startToken ) , new StaticMemberExpression ( expr , property , optional ) ) ;
1677
1704
}
1678
1705
else
@@ -4164,7 +4191,7 @@ private static bool QualifiedPropertyName(Token token)
4164
4191
TokenType . NullLiteral => true ,
4165
4192
TokenType . NumericLiteral => true ,
4166
4193
TokenType . Keyword => true ,
4167
- TokenType . Punctuator => Equals ( token . Value , "[" ) ,
4194
+ TokenType . Punctuator => Equals ( token . Value , "[" ) || Equals ( token . Value , "#" ) ,
4168
4195
_ => false
4169
4196
} ;
4170
4197
}
@@ -4212,7 +4239,7 @@ private FunctionExpression ParseSetterMethod()
4212
4239
return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref formalParameters . Parameters ) , method , isGenerator , hasStrictDirective , false ) ) ;
4213
4240
}
4214
4241
4215
- private FunctionExpression ParseGeneratorMethod ( )
4242
+ private FunctionExpression ParseGeneratorMethod ( bool isAsync = false )
4216
4243
{
4217
4244
var node = CreateNode ( ) ;
4218
4245
@@ -4224,7 +4251,7 @@ private FunctionExpression ParseGeneratorMethod()
4224
4251
var method = ParsePropertyMethod ( parameters , out var hasStrictDirective ) ;
4225
4252
_context . AllowYield = previousAllowYield ;
4226
4253
4227
- return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , true , hasStrictDirective , false ) ) ;
4254
+ return Finalize ( node , new FunctionExpression ( null , NodeList . From ( ref parameters . Parameters ) , method , true , hasStrictDirective , isAsync ) ) ;
4228
4255
}
4229
4256
4230
4257
// https://tc39.github.io/ecma262/#sec-generator-function-definitions
@@ -4321,12 +4348,13 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4321
4348
4322
4349
var kind = PropertyKind . None ;
4323
4350
Expression ? key = null ;
4324
- FunctionExpression ? value = null ;
4351
+ Expression ? value = null ;
4325
4352
var computed = false ;
4326
4353
var method = false ;
4327
4354
var isStatic = false ;
4328
4355
var isAsync = false ;
4329
- var isGenerator = false ;
4356
+ var isGenerator = false ;
4357
+ var isPrivate = false ;
4330
4358
4331
4359
if ( Match ( "*" ) )
4332
4360
{
@@ -4336,10 +4364,17 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4336
4364
else
4337
4365
{
4338
4366
computed = Match ( "[" ) ;
4339
- key = ParseObjectPropertyKey ( ) ;
4367
+ if ( Match ( "#" ) )
4368
+ {
4369
+ isPrivate = true ;
4370
+ NextToken ( ) ;
4371
+ token = _lookahead ;
4372
+ }
4373
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4340
4374
var id = key switch
4341
4375
{
4342
4376
Identifier identifier => identifier . Name ,
4377
+ PrivateIdentifier privateIdentifier => privateIdentifier . Name ,
4343
4378
Literal literal => literal . StringValue , // "constructor"
4344
4379
_ => null
4345
4380
} ;
@@ -4352,9 +4387,21 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4352
4387
if ( Match ( "*" ) )
4353
4388
{
4354
4389
NextToken ( ) ;
4390
+ if ( Match ( "#" ) )
4391
+ {
4392
+ isPrivate = true ;
4393
+ NextToken ( ) ;
4394
+ token = _lookahead ;
4395
+ }
4355
4396
}
4356
4397
else
4357
4398
{
4399
+ if ( Match ( "#" ) )
4400
+ {
4401
+ isPrivate = true ;
4402
+ NextToken ( ) ;
4403
+ token = _lookahead ;
4404
+ }
4358
4405
key = ParseObjectPropertyKey ( ) ;
4359
4406
}
4360
4407
}
@@ -4368,11 +4415,17 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4368
4415
if ( isGenerator )
4369
4416
{
4370
4417
NextToken ( ) ;
4418
+ }
4419
+
4420
+ if ( Match ( "#" ) )
4421
+ {
4422
+ isPrivate = true ;
4423
+ NextToken ( ) ;
4371
4424
}
4372
4425
4373
4426
token = _lookahead ;
4374
4427
computed = Match ( "[" ) ;
4375
- key = ParseObjectPropertyKey ( ) ;
4428
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4376
4429
if ( token . Type == TokenType . Identifier && ( string ? ) token . Value == "constructor" )
4377
4430
{
4378
4431
TolerateUnexpectedToken ( token , Messages . ConstructorIsAsync ) ;
@@ -4386,26 +4439,49 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4386
4439
{
4387
4440
if ( lookaheadPropertyKey && ( string ? ) token . Value == "get" )
4388
4441
{
4389
- kind = PropertyKind . Get ;
4442
+ kind = PropertyKind . Get ;
4443
+ if ( Match ( "#" ) )
4444
+ {
4445
+ isPrivate = true ;
4446
+ NextToken ( ) ;
4447
+ token = _lookahead ;
4448
+ }
4390
4449
computed = Match ( "[" ) ;
4391
- key = ParseObjectPropertyKey ( ) ;
4450
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4392
4451
_context . AllowYield = false ;
4393
4452
value = ParseGetterMethod ( ) ;
4394
4453
}
4395
4454
else if ( lookaheadPropertyKey && ( string ? ) token . Value == "set" )
4396
4455
{
4397
4456
kind = PropertyKind . Set ;
4457
+ if ( Match ( "#" ) )
4458
+ {
4459
+ isPrivate = true ;
4460
+ NextToken ( ) ;
4461
+ token = _lookahead ;
4462
+ }
4398
4463
computed = Match ( "[" ) ;
4399
- key = ParseObjectPropertyKey ( ) ;
4400
- value = ParseSetterMethod ( ) ;
4464
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4465
+ value = ParseSetterMethod ( ) ;
4466
+ }
4467
+ else if ( ! Match ( "(" ) )
4468
+ {
4469
+ kind = PropertyKind . Property ;
4470
+ computed = false ;
4471
+
4472
+ if ( Match ( "=" ) )
4473
+ {
4474
+ NextToken ( ) ;
4475
+ value = IsolateCoverGrammar ( this . parseAssignmentExpression ) ;
4476
+ }
4401
4477
}
4402
4478
}
4403
4479
else if ( token . Type == TokenType . Punctuator && ( string ? ) token . Value == "*" && lookaheadPropertyKey )
4404
4480
{
4405
4481
kind = PropertyKind . Init ;
4406
4482
computed = Match ( "[" ) ;
4407
- key = ParseObjectPropertyKey ( ) ;
4408
- value = ParseGeneratorMethod ( ) ;
4483
+ key = ParseObjectPropertyKey ( isPrivate ) ;
4484
+ value = ParseGeneratorMethod ( isAsync ) ;
4409
4485
method = true ;
4410
4486
}
4411
4487
@@ -4441,7 +4517,7 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4441
4517
4442
4518
if ( ! isStatic && IsPropertyKey ( key ! , "constructor" ) )
4443
4519
{
4444
- if ( kind != PropertyKind . Method || ! method || value ! . Generator )
4520
+ if ( kind != PropertyKind . Method || ! method || ( ( FunctionExpression ) value ! ) . Generator )
4445
4521
{
4446
4522
ThrowUnexpectedToken ( token , Messages . ConstructorSpecialMethod ) ;
4447
4523
}
@@ -4457,10 +4533,15 @@ private ClassProperty ParseClassElement(ref bool hasConstructor)
4457
4533
4458
4534
kind = PropertyKind . Constructor ;
4459
4535
}
4460
- }
4461
-
4462
-
4463
- return Finalize ( node , new MethodDefinition ( key ! , computed , value ! , kind , isStatic ) ) ;
4536
+ }
4537
+
4538
+ if ( kind == PropertyKind . Property )
4539
+ {
4540
+ ConsumeSemicolon ( ) ;
4541
+ return Finalize ( node , new PropertyDefinition ( key ! , computed , value ! , isStatic ) ) ;
4542
+ }
4543
+
4544
+ return Finalize ( node , new MethodDefinition ( key ! , computed , ( FunctionExpression ) value ! , kind , isStatic ) ) ;
4464
4545
}
4465
4546
4466
4547
private ArrayList < ClassProperty > ParseClassElementList ( )
0 commit comments