File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 4470
4470
"Add all missing enum members" : {
4471
4471
"category" : " Message" ,
4472
4472
"code" : 95064
4473
+ },
4474
+ "Private names are not allowed outside of class bodies" : {
4475
+ "category" : " Error" ,
4476
+ "code" : 95065
4473
4477
}
4474
4478
}
Original file line number Diff line number Diff line change @@ -1320,16 +1320,22 @@ namespace ts {
1320
1320
// An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues
1321
1321
// with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for
1322
1322
// each identifier in order to reduce memory consumption.
1323
- function createIdentifier ( isIdentifier : boolean , diagnosticMessage ?: DiagnosticMessage ) : Identifier {
1323
+ function createIdentifier ( isIdentifier : boolean , suggestedDiagnosticMessage ?: DiagnosticMessage ) : Identifier {
1324
1324
identifierCount ++ ;
1325
- if ( isIdentifier ) {
1325
+ let diagnosticMessage = suggestedDiagnosticMessage ;
1326
+ const isPrivateName = ! ! ( scanner . getTokenFlags ( ) & TokenFlags . PrivateName ) ;
1327
+ const privateNameIsAllowed = ! ! ( parsingContext & ( 1 << ParsingContext . ClassMembers ) ) ;
1328
+ if ( isPrivateName && ! privateNameIsAllowed ) {
1329
+ diagnosticMessage = Diagnostics . Private_names_are_not_allowed_outside_of_class_bodies ;
1330
+ }
1331
+ else if ( isIdentifier && ( ! isPrivateName || privateNameIsAllowed ) ) {
1326
1332
const node = < Identifier > createNode ( SyntaxKind . Identifier ) ;
1327
1333
1328
1334
// Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker
1329
1335
if ( token ( ) !== SyntaxKind . Identifier ) {
1330
1336
node . originalKeywordKind = token ( ) ;
1331
1337
}
1332
- node . isPrivateName = ! ! ( scanner . getTokenFlags ( ) & TokenFlags . PrivateName ) ;
1338
+ node . isPrivateName = isPrivateName ;
1333
1339
node . escapedText = escapeLeadingUnderscores ( internIdentifier ( scanner . getTokenValue ( ) ) ) ;
1334
1340
nextToken ( ) ;
1335
1341
return finishNode ( node ) ;
Original file line number Diff line number Diff line change @@ -1736,7 +1736,7 @@ namespace ts {
1736
1736
return token = SyntaxKind . Identifier ;
1737
1737
}
1738
1738
error ( Diagnostics . Invalid_character ) ;
1739
- pos ++ ;
1739
+ // no ` pos++` because already advanced at beginning of this `case` statement
1740
1740
return token = SyntaxKind . Unknown ;
1741
1741
default :
1742
1742
if ( isIdentifierStart ( ch , languageVersion ) ) {
You can’t perform that action at this time.
0 commit comments