diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 594d7674b9287..240385df8dfcf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -944,7 +944,7 @@ namespace ts { initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS); // Prime the scanner. nextToken(); - const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false); + const entityName = parseEntityName(/*allowReservedWords*/ true); const isInvalid = token() === SyntaxKind.EndOfFileToken && !parseDiagnostics.length; clearState(); return isInvalid ? entityName : undefined; @@ -2829,7 +2829,7 @@ namespace ts { return createMissingList(); } - function parseEntityName(allowReservedWords: boolean, allowPrivateIdentifiers: boolean, diagnosticMessage?: DiagnosticMessage): EntityName { + function parseEntityName(allowReservedWords: boolean, diagnosticMessage?: DiagnosticMessage): EntityName { const pos = getNodePos(); let entity: EntityName = allowReservedWords ? parseIdentifierName(diagnosticMessage) : parseIdentifier(diagnosticMessage); let dotPos = getNodePos(); @@ -2843,7 +2843,7 @@ namespace ts { entity = finishNode( factory.createQualifiedName( entity, - parseRightSideOfDot(allowReservedWords, allowPrivateIdentifiers) as Identifier + parseRightSideOfDot(allowReservedWords, /* allowPrivateIdentifiers */ false) as Identifier ), pos ); @@ -3028,7 +3028,7 @@ namespace ts { // TYPES function parseEntityNameOfTypeReference() { - return parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false, Diagnostics.Type_expected); + return parseEntityName(/*allowReservedWords*/ true, Diagnostics.Type_expected); } function parseTypeArgumentsOfTypeReference() { @@ -3188,7 +3188,7 @@ namespace ts { function parseTypeQuery(): TypeQueryNode { const pos = getNodePos(); parseExpected(SyntaxKind.TypeOfKeyword); - const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true); + const entityName = parseEntityName(/*allowReservedWords*/ true); // Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression. const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined; return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos); @@ -7470,7 +7470,7 @@ namespace ts { function parseModuleReference() { return isExternalModuleReference() ? parseExternalModuleReference() - : parseEntityName(/*allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false); + : parseEntityName(/*allowReservedWords*/ false); } function parseExternalModuleReference() { @@ -7743,7 +7743,7 @@ namespace ts { const pos = getNodePos(); const hasBrace = parseOptional(SyntaxKind.OpenBraceToken); const p2 = getNodePos(); - let entityName: EntityName | JSDocMemberName = parseEntityName(/* allowReservedWords*/ false, /*allowPrivateIdentifiers*/ false); + let entityName: EntityName | JSDocMemberName = parseEntityName(/* allowReservedWords*/ false); while (token() === SyntaxKind.PrivateIdentifier) { reScanHashToken(); // rescan #id as # id nextTokenJSDoc(); // then skip the # @@ -8206,7 +8206,7 @@ namespace ts { // parseEntityName logs an error for non-identifier, so create a MissingNode ourselves to avoid the error const p2 = getNodePos(); let name: EntityName | JSDocMemberName | undefined = tokenIsIdentifierOrKeyword(token()) - ? parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ false) + ? parseEntityName(/*allowReservedWords*/ true) : undefined; if (name) { while (token() === SyntaxKind.PrivateIdentifier) { diff --git a/tests/baselines/reference/privateNameInTypeQuery.errors.txt b/tests/baselines/reference/privateNameInTypeQuery.errors.txt deleted file mode 100644 index c11a9db934a55..0000000000000 --- a/tests/baselines/reference/privateNameInTypeQuery.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts(6,15): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts(11,19): error TS18013: Property '#a' is not accessible outside class 'C' because it has a private identifier. - - -==== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts (2 errors) ==== - class C { - #a = 'a'; - - constructor() { - const a: typeof this.#a = ''; // Ok - const b: typeof this.#a = 1; // Error - ~ -!!! error TS2322: Type 'number' is not assignable to type 'string'. - } - } - - const c = new C(); - const a: typeof c.#a = ''; - ~~ -!!! error TS18013: Property '#a' is not accessible outside class 'C' because it has a private identifier. - \ No newline at end of file diff --git a/tests/baselines/reference/privateNameInTypeQuery.js b/tests/baselines/reference/privateNameInTypeQuery.js deleted file mode 100644 index 4f8e7cb38e195..0000000000000 --- a/tests/baselines/reference/privateNameInTypeQuery.js +++ /dev/null @@ -1,25 +0,0 @@ -//// [privateNameInTypeQuery.ts] -class C { - #a = 'a'; - - constructor() { - const a: typeof this.#a = ''; // Ok - const b: typeof this.#a = 1; // Error - } -} - -const c = new C(); -const a: typeof c.#a = ''; - - -//// [privateNameInTypeQuery.js] -"use strict"; -class C { - #a = 'a'; - constructor() { - const a = ''; // Ok - const b = 1; // Error - } -} -const c = new C(); -const a = ''; diff --git a/tests/baselines/reference/privateNameInTypeQuery.symbols b/tests/baselines/reference/privateNameInTypeQuery.symbols deleted file mode 100644 index 1d32e5aab733a..0000000000000 --- a/tests/baselines/reference/privateNameInTypeQuery.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts === -class C { ->C : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) - - #a = 'a'; ->#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) - - constructor() { - const a: typeof this.#a = ''; // Ok ->a : Symbol(a, Decl(privateNameInTypeQuery.ts, 4, 13)) ->this.#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) ->this : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) - - const b: typeof this.#a = 1; // Error ->b : Symbol(b, Decl(privateNameInTypeQuery.ts, 5, 13)) ->this.#a : Symbol(C.#a, Decl(privateNameInTypeQuery.ts, 0, 9)) ->this : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) - } -} - -const c = new C(); ->c : Symbol(c, Decl(privateNameInTypeQuery.ts, 9, 5)) ->C : Symbol(C, Decl(privateNameInTypeQuery.ts, 0, 0)) - -const a: typeof c.#a = ''; ->a : Symbol(a, Decl(privateNameInTypeQuery.ts, 10, 5)) ->c : Symbol(c, Decl(privateNameInTypeQuery.ts, 9, 5)) - diff --git a/tests/baselines/reference/privateNameInTypeQuery.types b/tests/baselines/reference/privateNameInTypeQuery.types deleted file mode 100644 index 22e34ba59b07b..0000000000000 --- a/tests/baselines/reference/privateNameInTypeQuery.types +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts === -class C { ->C : C - - #a = 'a'; ->#a : string ->'a' : "a" - - constructor() { - const a: typeof this.#a = ''; // Ok ->a : string ->this.#a : string ->this : this ->'' : "" - - const b: typeof this.#a = 1; // Error ->b : string ->this.#a : string ->this : this ->1 : 1 - } -} - -const c = new C(); ->c : C ->new C() : C ->C : typeof C - -const a: typeof c.#a = ''; ->a : any ->c.#a : any ->c : C ->'' : "" - diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts b/tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts deleted file mode 100644 index 3a7e966130ae9..0000000000000 --- a/tests/cases/conformance/classes/members/privateNames/privateNameInTypeQuery.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @strict: true -// @target: esnext - -class C { - #a = 'a'; - - constructor() { - const a: typeof this.#a = ''; // Ok - const b: typeof this.#a = 1; // Error - } -} - -const c = new C(); -const a: typeof c.#a = '';