Skip to content

Commit 0520713

Browse files
committed
Private Name Support in the Checker (#5)
- [x] treat private names as unique: - case 1: cannot say that a variable is of a class type unless the variable points to an instance of the class - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesUnique.ts) - case 2: private names in class hierarchies do not conflict - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoConflictWhenInheriting.ts) - [x] `#constructor` is reserved - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts) - check in `bindWorker`, where every node is visited - [x] Accessibility modifiers can't be used with private names - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoAccessibilityModifiers.ts) - implemented in `checkAccessibilityModifiers`, using `ModifierFlags.AccessibilityModifier` - [x] `delete #foo` not allowed - [x] Private name accesses not allowed outside of the defining class - see test: https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameNotAccessibleOutsideDefiningClass.ts - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts) - implemented in `checkDeleteExpression` - [x] Do [the right thing](https://gist.github.com/mheiber/b6fc7adb426c2e1cdaceb5d7786fc630) for nested classes mv private name tests together more checker tests for private names update naming and cleanup for check private names for private name support in the checker: - make names more consistent - remove unnecessary checks - add utility function to public API - other small cleanup Move getPropertyNameForUniqueESSymbol to utility for consistency with other calculation of special property names (starting with __), move the calculation of property names for unique es symbols to `utilities.ts`. private name tests strict+es6 Update private name tests to use 'strict' type checking and to target es6 instead of default. Makes the js output easier to read and tests more surface area with other checker features. error message for private names in obj literals Disallow decorating private-named properties because the spec is still in flux. Signed-off-by: Max Heiber <[email protected]>
1 parent 154deb0 commit 0520713

File tree

133 files changed

+3301
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+3301
-59
lines changed

src/compiler/binder.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,15 @@ namespace ts {
356356
if (isWellKnownSymbolSyntactically(name)) {
357357
return getPropertyNameForKnownSymbolName(idText(name.name));
358358
}
359-
if (isPrivateName(node)) {
360-
return nodePosToString(node) as __String;
359+
if (isPrivateName(name)) {
360+
// containingClass exists because private names only allowed inside classes
361+
const containingClass = getContainingClass(name.parent);
362+
if (!containingClass) {
363+
// we're in a case where there's a private name outside a class (invalid)
364+
return undefined;
365+
}
366+
const containingClassSymbol = containingClass.symbol;
367+
return getPropertyNameForPrivateNameDescription(containingClassSymbol, name.escapedText);
361368
}
362369
return isPropertyNameLiteral(name) ? getEscapedTextOfIdentifierOrLiteral(name) : undefined;
363370
}
@@ -415,6 +422,10 @@ namespace ts {
415422

416423
const isDefaultExport = hasModifier(node, ModifierFlags.Default);
417424

425+
// need this before getDeclarationName
426+
if (isNamedDeclaration(node)) {
427+
node.name.parent = node;
428+
}
418429
// The exported symbol for an export default function/class node is always named "default"
419430
const name = isDefaultExport && parent ? InternalSymbolName.Default : getDeclarationName(node);
420431

@@ -467,11 +478,6 @@ namespace ts {
467478
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
468479
}
469480
else if (!(includes & SymbolFlags.Variable && symbol.flags & SymbolFlags.Assignment)) {
470-
// Assignment declarations are allowed to merge with variables, no matter what other flags they have.
471-
if (isNamedDeclaration(node)) {
472-
node.name.parent = node;
473-
}
474-
475481
// Report errors every position with duplicate declaration
476482
// Report errors on previous encountered declarations
477483
let message = symbol.flags & SymbolFlags.BlockScopedVariable
@@ -2071,6 +2077,18 @@ namespace ts {
20712077
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
20722078
}
20732079

2080+
// The binder visits every node, so this is a good place to check for
2081+
// the reserved private name (there is only one)
2082+
function checkPrivateName(node: PrivateName) {
2083+
if (node.escapedText === "#constructor") {
2084+
// Report error only if there are no parse errors in file
2085+
if (!file.parseDiagnostics.length) {
2086+
file.bindDiagnostics.push(createDiagnosticForNode(node,
2087+
Diagnostics.constructor_is_a_reserved_word, declarationNameToString(node)));
2088+
}
2089+
}
2090+
}
2091+
20742092
function checkStrictModeBinaryExpression(node: BinaryExpression) {
20752093
if (inStrictMode && isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
20762094
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
@@ -2343,6 +2361,8 @@ namespace ts {
23432361
node.flowNode = currentFlow;
23442362
}
23452363
return checkStrictModeIdentifier(<Identifier>node);
2364+
case SyntaxKind.PrivateName:
2365+
return checkPrivateName(node as PrivateName);
23462366
case SyntaxKind.PropertyAccessExpression:
23472367
case SyntaxKind.ElementAccessExpression:
23482368
const expr = node as PropertyAccessExpression | ElementAccessExpression;

src/compiler/checker.ts

Lines changed: 108 additions & 33 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5302,6 +5302,33 @@
53025302
"Private names cannot be used as parameters": {
53035303
"category": "Error",
53045304
"code": 18009
5305+
},
5306+
"Accessibility modifiers cannot be used with private names.": {
5307+
"category": "Error",
5308+
"code": 18010
5309+
},
5310+
"The operand of a delete operator cannot be a private name.": {
5311+
"category": "Error",
5312+
"code": 18011
5313+
},
5314+
"'#constructor' is a reserved word.": {
5315+
"category": "Error",
5316+
"code": 18012
5317+
},
5318+
"Property '{0}' is not accessible outside class '{1}' because it has a private name.": {
5319+
"category": "Error",
5320+
"code": 18013
5321+
},
5322+
"This usage of '{0}' refers to the private member declared in its enclosing class. While type '{1}' has a private member with the same spelling, its declaration and accessibility are distinct.": {
5323+
"category": "Error",
5324+
"code": 18014
5325+
},
5326+
"Property '{0}' is missing in type '{1}'. While type '{1}' has a private member with the same spelling, its declaration and accessibility are distinct.": {
5327+
"category": "Error",
5328+
"code": 18015
5329+
},
5330+
"Private names are not allowed outside class bodies.": {
5331+
"category": "Error",
5332+
"code": 18016
53055333
}
5306-
53075334
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,6 +3303,7 @@ namespace ts {
33033303
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
33043304
getPropertiesOfType(type: Type): Symbol[];
33053305
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
3306+
getPropertyForPrivateName(apparentType: Type, leftType: Type, right: PrivateName, errorNode: Node | undefined): Symbol | undefined;
33063307
/* @internal */ getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined;
33073308
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
33083309
getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[];

src/compiler/utilities.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,10 @@ namespace ts {
16031603
export function nodeCanBeDecorated(node: ClassElement, parent: Node): boolean;
16041604
export function nodeCanBeDecorated(node: Node, parent: Node, grandparent: Node): boolean;
16051605
export function nodeCanBeDecorated(node: Node, parent?: Node, grandparent?: Node): boolean {
1606+
// private names cannot be used with decorators yet
1607+
if (isNamedDeclaration(node) && isPrivateName(node.name)) {
1608+
return false;
1609+
}
16061610
switch (node.kind) {
16071611
case SyntaxKind.ClassDeclaration:
16081612
// classes are valid targets
@@ -2973,10 +2977,18 @@ namespace ts {
29732977
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.PrivateName ? node.escapedText : escapeLeadingUnderscores(node.text);
29742978
}
29752979

2980+
export function getPropertyNameForUniqueESSymbol(symbol: Symbol): __String {
2981+
return `__@${getSymbolId(symbol)}@${symbol.escapedName}` as __String;
2982+
}
2983+
29762984
export function getPropertyNameForKnownSymbolName(symbolName: string): __String {
29772985
return "__@" + symbolName as __String;
29782986
}
29792987

2988+
export function getPropertyNameForPrivateNameDescription(containingClassSymbol: Symbol, description: __String): __String {
2989+
return `__#${getSymbolId(containingClassSymbol)}@${description}` as __String;
2990+
}
2991+
29802992
export function isKnownSymbol(symbol: Symbol): boolean {
29812993
return startsWith(symbol.escapedName as string, "__@");
29822994
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,7 @@ declare namespace ts {
19841984
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
19851985
getPropertiesOfType(type: Type): Symbol[];
19861986
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
1987+
getPropertyForPrivateName(apparentType: Type, leftType: Type, right: PrivateName, errorNode: Node | undefined): Symbol | undefined;
19871988
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
19881989
getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[];
19891990
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,7 @@ declare namespace ts {
19841984
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
19851985
getPropertiesOfType(type: Type): Symbol[];
19861986
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
1987+
getPropertyForPrivateName(apparentType: Type, leftType: Type, right: PrivateName, errorNode: Node | undefined): Symbol | undefined;
19871988
getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined;
19881989
getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[];
19891990
getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
EmitSkipped: false
2+
FileName : ./dist/index.js
3+
"use strict";
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
var Foo = /** @class */ (function () {
6+
function Foo() {
7+
}
8+
Foo.prototype.methodName = function (propName) { };
9+
Foo.prototype.otherMethod = function () {
10+
if (Math.random() > 0.5) {
11+
return { x: 42 };
12+
}
13+
return { y: "yes" };
14+
};
15+
return Foo;
16+
}());
17+
exports.Foo = Foo;
18+
FileName : ./dist/index.d.ts.map
19+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts
20+
export declare class Foo {
21+
member: string;
22+
methodName(propName: SomeType): void;
23+
otherMethod(): {
24+
x: number;
25+
y?: undefined;
26+
} | {
27+
y: string;
28+
x?: undefined;
29+
};
30+
}
31+
export interface SomeType {
32+
member: number;
33+
}
34+
//# sourceMappingURL=index.d.ts.map
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
EmitSkipped: false
2+
FileName : ./dist/index.js.map
3+
{"version":3,"file":"index.js","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":";;AAAA;IAAA;IASA,CAAC;IAPG,wBAAU,GAAV,UAAW,QAAkB,IAAS,CAAC;IACvC,yBAAW,GAAX;QACI,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE;YACrB,OAAO,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC;SAClB;QACD,OAAO,EAAC,CAAC,EAAE,KAAK,EAAC,CAAC;IACtB,CAAC;IACL,UAAC;AAAD,CAAC,AATD,IASC;AATY,kBAAG"}FileName : ./dist/index.js
4+
"use strict";
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
var Foo = /** @class */ (function () {
7+
function Foo() {
8+
}
9+
Foo.prototype.methodName = function (propName) { };
10+
Foo.prototype.otherMethod = function () {
11+
if (Math.random() > 0.5) {
12+
return { x: 42 };
13+
}
14+
return { y: "yes" };
15+
};
16+
return Foo;
17+
}());
18+
exports.Foo = Foo;
19+
//# sourceMappingURL=index.js.mapFileName : ./dist/index.d.ts.map
20+
{"version":3,"file":"index.d.ts","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts
21+
export declare class Foo {
22+
member: string;
23+
methodName(propName: SomeType): void;
24+
otherMethod(): {
25+
x: number;
26+
y?: undefined;
27+
} | {
28+
y: string;
29+
x?: undefined;
30+
};
31+
}
32+
export interface SomeType {
33+
member: number;
34+
}
35+
//# sourceMappingURL=index.d.ts.map
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
EmitSkipped: false
2+
FileName : ./dist/index.js
3+
"use strict";
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
var Foo = /** @class */ (function () {
6+
function Foo() {
7+
}
8+
Foo.prototype.methodName = function (propName) { };
9+
Foo.prototype.otherMethod = function () {
10+
if (Math.random() > 0.5) {
11+
return { x: 42 };
12+
}
13+
return { y: "yes" };
14+
};
15+
return Foo;
16+
}());
17+
exports.Foo = Foo;
18+
FileName : ./dist/index.d.ts.map
19+
{"version":3,"file":"index.d.ts","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts
20+
export declare class Foo {
21+
member: string;
22+
methodName(propName: SomeType): void;
23+
otherMethod(): {
24+
x: number;
25+
y?: undefined;
26+
} | {
27+
y: string;
28+
x?: undefined;
29+
};
30+
}
31+
export interface SomeType {
32+
member: number;
33+
}
34+
//# sourceMappingURL=index.d.ts.map
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
EmitSkipped: false
2+
FileName : ./dist/index.js
3+
"use strict";
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
var Foo = /** @class */ (function () {
6+
function Foo() {
7+
}
8+
Foo.prototype.methodName = function (propName) { };
9+
Foo.prototype.otherMethod = function () {
10+
if (Math.random() > 0.5) {
11+
return { x: 42 };
12+
}
13+
return { y: "yes" };
14+
};
15+
return Foo;
16+
}());
17+
exports.Foo = Foo;
18+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90ZXN0cy9jYXNlcy9mb3Vyc2xhc2gvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUFBO0lBU0EsQ0FBQztJQVBHLHdCQUFVLEdBQVYsVUFBVyxRQUFrQixJQUFTLENBQUM7SUFDdkMseUJBQVcsR0FBWDtRQUNJLElBQUksSUFBSSxDQUFDLE1BQU0sRUFBRSxHQUFHLEdBQUcsRUFBRTtZQUNyQixPQUFPLEVBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBQyxDQUFDO1NBQ2xCO1FBQ0QsT0FBTyxFQUFDLENBQUMsRUFBRSxLQUFLLEVBQUMsQ0FBQztJQUN0QixDQUFDO0lBQ0wsVUFBQztBQUFELENBQUMsQUFURCxJQVNDO0FBVFksa0JBQUcifQ==FileName : ./dist/index.d.ts.map
19+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts
20+
export declare class Foo {
21+
member: string;
22+
methodName(propName: SomeType): void;
23+
otherMethod(): {
24+
x: number;
25+
y?: undefined;
26+
} | {
27+
y: string;
28+
x?: undefined;
29+
};
30+
}
31+
export interface SomeType {
32+
member: number;
33+
}
34+
//# sourceMappingURL=index.d.ts.map
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
EmitSkipped: false
2+
FileName : ./dist/index.js
3+
"use strict";
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
var Foo = /** @class */ (function () {
6+
function Foo() {
7+
}
8+
Foo.prototype.methodName = function (propName) { };
9+
Foo.prototype.otherMethod = function () {
10+
if (Math.random() > 0.5) {
11+
return { x: 42 };
12+
}
13+
return { y: "yes" };
14+
};
15+
return Foo;
16+
}());
17+
exports.Foo = Foo;
18+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90ZXN0cy9jYXNlcy9mb3Vyc2xhc2gvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUFBO0lBU0EsQ0FBQztJQVBHLHdCQUFVLEdBQVYsVUFBVyxRQUFrQixJQUFTLENBQUM7SUFDdkMseUJBQVcsR0FBWDtRQUNJLElBQUksSUFBSSxDQUFDLE1BQU0sRUFBRSxHQUFHLEdBQUcsRUFBRTtZQUNyQixPQUFPLEVBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBQyxDQUFDO1NBQ2xCO1FBQ0QsT0FBTyxFQUFDLENBQUMsRUFBRSxLQUFLLEVBQUMsQ0FBQztJQUN0QixDQUFDO0lBQ0wsVUFBQztBQUFELENBQUMsQUFURCxJQVNDO0FBVFksa0JBQUciLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY2xhc3MgRm9vIHtcbiAgICBtZW1iZXI6IHN0cmluZztcbiAgICBtZXRob2ROYW1lKHByb3BOYW1lOiBTb21lVHlwZSk6IHZvaWQge31cbiAgICBvdGhlck1ldGhvZCgpIHtcbiAgICAgICAgaWYgKE1hdGgucmFuZG9tKCkgPiAwLjUpIHtcbiAgICAgICAgICAgIHJldHVybiB7eDogNDJ9O1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB7eTogXCJ5ZXNcIn07XG4gICAgfVxufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNvbWVUeXBlIHtcbiAgICBtZW1iZXI6IG51bWJlcjtcbn0iXX0=FileName : ./dist/index.d.ts.map
19+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts
20+
export declare class Foo {
21+
member: string;
22+
methodName(propName: SomeType): void;
23+
otherMethod(): {
24+
x: number;
25+
y?: undefined;
26+
} | {
27+
y: string;
28+
x?: undefined;
29+
};
30+
}
31+
export interface SomeType {
32+
member: number;
33+
}
34+
//# sourceMappingURL=index.d.ts.map

tests/baselines/reference/privateNameAndIndexSignature.errors.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts(4,14): error TS2339: Property '#f' does not exist on type 'A'.
1+
tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts(6,14): error TS2339: Property '#f' does not exist on type 'A'.
22

33

44
==== tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts (1 errors) ====
5+
// @target es6
6+
57
class A {
68
[k: string]: any;
79
constructor(message: string) {

tests/baselines/reference/privateNameAndIndexSignature.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//// [privateNameAndIndexSignature.ts]
2+
// @target es6
3+
24
class A {
35
[k: string]: any;
46
constructor(message: string) {
@@ -8,6 +10,8 @@ class A {
810

911

1012
//// [privateNameAndIndexSignature.js]
13+
"use strict";
14+
// @target es6
1115
var A = /** @class */ (function () {
1216
function A(message) {
1317
this.#f = 3; // Error Property '#f' does not exist on type 'A'.

tests/baselines/reference/privateNameAndIndexSignature.symbols

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
=== tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts ===
2+
// @target es6
3+
24
class A {
35
>A : Symbol(A, Decl(privateNameAndIndexSignature.ts, 0, 0))
46

57
[k: string]: any;
6-
>k : Symbol(k, Decl(privateNameAndIndexSignature.ts, 1, 5))
8+
>k : Symbol(k, Decl(privateNameAndIndexSignature.ts, 3, 5))
79

810
constructor(message: string) {
9-
>message : Symbol(message, Decl(privateNameAndIndexSignature.ts, 2, 16))
11+
>message : Symbol(message, Decl(privateNameAndIndexSignature.ts, 4, 16))
1012

1113
this.#f = 3 // Error Property '#f' does not exist on type 'A'.
1214
>this : Symbol(A, Decl(privateNameAndIndexSignature.ts, 0, 0))

tests/baselines/reference/privateNameAndIndexSignature.types

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
=== tests/cases/conformance/classes/members/privateNames/privateNameAndIndexSignature.ts ===
2+
// @target es6
3+
24
class A {
35
>A : A
46

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts(4,5): error TS18012: '#constructor' is a reserved word.
2+
3+
4+
==== tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts (1 errors) ====
5+
// @target es6
6+
7+
class A {
8+
#constructor() {} // Error: `#constructor` is a reserved word.
9+
~~~~~~~~~~~~
10+
!!! error TS18012: '#constructor' is a reserved word.
11+
}
12+

0 commit comments

Comments
 (0)