Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2dce0c5

Browse filesBrowse files
authored
Intentionally regress one buggy declaration output to an older version (#62163)
1 parent 5be3346 commit 2dce0c5
Copy full SHA for 2dce0c5

File tree

Expand file treeCollapse file tree

5 files changed

+173
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+173
-1
lines changed
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8908,7 +8908,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
89088908
function getPropertyNameNodeForSymbol(symbol: Symbol, context: NodeBuilderContext) {
89098909
const hashPrivateName = getClonedHashPrivateName(symbol);
89108910
if (hashPrivateName) {
8911-
return hashPrivateName;
8911+
const shouldEmitErroneousFieldName = !!context.tracker.reportPrivateInBaseOfClassExpression &&
8912+
context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral;
8913+
if (!shouldEmitErroneousFieldName) {
8914+
return hashPrivateName;
8915+
}
8916+
else {
8917+
let rawName = unescapeLeadingUnderscores(symbol.escapedName);
8918+
// symbol IDs are unstable - replace #nnn# with #private#
8919+
rawName = rawName.replace(/__#\d+@#/g, "__#private@#");
8920+
return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), /*singleQuote*/ false, /*stringNamed*/ true, !!(symbol.flags & SymbolFlags.Method));
8921+
}
89128922
}
89138923
const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed);
89148924
const singleQuote = !!length(symbol.declarations) && every(symbol.declarations, isSingleQuotedStringNamed);
Collapse file
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [tests/cases/compiler/privateFieldsInClassExpressionDeclaration.ts] ////
2+
3+
//// [privateFieldsInClassExpressionDeclaration.ts]
4+
export const ClassExpression = class {
5+
#context = 0;
6+
#method() { return 42; }
7+
public value = 1;
8+
};
9+
10+
// Additional test with static private fields
11+
export const ClassExpressionStatic = class {
12+
static #staticPrivate = "hidden";
13+
#instancePrivate = true;
14+
public exposed = "visible";
15+
};
16+
17+
//// [privateFieldsInClassExpressionDeclaration.js]
18+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
19+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
20+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
21+
};
22+
var _instances, _context, _method, _a, _b, _ClassExpressionStatic_staticPrivate, _ClassExpressionStatic_instancePrivate;
23+
export const ClassExpression = (_a = class {
24+
constructor() {
25+
_instances.add(this);
26+
_context.set(this, 0);
27+
this.value = 1;
28+
}
29+
},
30+
_context = new WeakMap(),
31+
_instances = new WeakSet(),
32+
_method = function _method() { return 42; },
33+
_a);
34+
// Additional test with static private fields
35+
export const ClassExpressionStatic = (_b = class {
36+
constructor() {
37+
_ClassExpressionStatic_instancePrivate.set(this, true);
38+
this.exposed = "visible";
39+
}
40+
},
41+
_ClassExpressionStatic_instancePrivate = new WeakMap(),
42+
__setFunctionName(_b, "ClassExpressionStatic"),
43+
_ClassExpressionStatic_staticPrivate = { value: "hidden" },
44+
_b);
45+
46+
47+
//// [privateFieldsInClassExpressionDeclaration.d.ts]
48+
export declare const ClassExpression: {
49+
new (): {
50+
"__#private@#context": number;
51+
"__#private@#method"(): number;
52+
value: number;
53+
};
54+
};
55+
export declare const ClassExpressionStatic: {
56+
new (): {
57+
"__#private@#instancePrivate": boolean;
58+
exposed: string;
59+
};
60+
"__#private@#staticPrivate": string;
61+
};
Collapse file
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/privateFieldsInClassExpressionDeclaration.ts] ////
2+
3+
=== privateFieldsInClassExpressionDeclaration.ts ===
4+
export const ClassExpression = class {
5+
>ClassExpression : Symbol(ClassExpression, Decl(privateFieldsInClassExpressionDeclaration.ts, 0, 12))
6+
7+
#context = 0;
8+
>#context : Symbol(ClassExpression.#context, Decl(privateFieldsInClassExpressionDeclaration.ts, 0, 38))
9+
10+
#method() { return 42; }
11+
>#method : Symbol(ClassExpression.#method, Decl(privateFieldsInClassExpressionDeclaration.ts, 1, 17))
12+
13+
public value = 1;
14+
>value : Symbol(ClassExpression.value, Decl(privateFieldsInClassExpressionDeclaration.ts, 2, 28))
15+
16+
};
17+
18+
// Additional test with static private fields
19+
export const ClassExpressionStatic = class {
20+
>ClassExpressionStatic : Symbol(ClassExpressionStatic, Decl(privateFieldsInClassExpressionDeclaration.ts, 7, 12))
21+
22+
static #staticPrivate = "hidden";
23+
>#staticPrivate : Symbol(ClassExpressionStatic.#staticPrivate, Decl(privateFieldsInClassExpressionDeclaration.ts, 7, 44))
24+
25+
#instancePrivate = true;
26+
>#instancePrivate : Symbol(ClassExpressionStatic.#instancePrivate, Decl(privateFieldsInClassExpressionDeclaration.ts, 8, 37))
27+
28+
public exposed = "visible";
29+
>exposed : Symbol(ClassExpressionStatic.exposed, Decl(privateFieldsInClassExpressionDeclaration.ts, 9, 28))
30+
31+
};
Collapse file
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [tests/cases/compiler/privateFieldsInClassExpressionDeclaration.ts] ////
2+
3+
=== privateFieldsInClassExpressionDeclaration.ts ===
4+
export const ClassExpression = class {
5+
>ClassExpression : typeof ClassExpression
6+
> : ^^^^^^^^^^^^^^^^^^^^^^
7+
>class { #context = 0; #method() { return 42; } public value = 1;} : typeof ClassExpression
8+
> : ^^^^^^^^^^^^^^^^^^^^^^
9+
10+
#context = 0;
11+
>#context : number
12+
> : ^^^^^^
13+
>0 : 0
14+
> : ^
15+
16+
#method() { return 42; }
17+
>#method : () => number
18+
> : ^^^^^^^^^^^^
19+
>42 : 42
20+
> : ^^
21+
22+
public value = 1;
23+
>value : number
24+
> : ^^^^^^
25+
>1 : 1
26+
> : ^
27+
28+
};
29+
30+
// Additional test with static private fields
31+
export const ClassExpressionStatic = class {
32+
>ClassExpressionStatic : typeof ClassExpressionStatic
33+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
>class { static #staticPrivate = "hidden"; #instancePrivate = true; public exposed = "visible";} : typeof ClassExpressionStatic
35+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
static #staticPrivate = "hidden";
38+
>#staticPrivate : string
39+
> : ^^^^^^
40+
>"hidden" : "hidden"
41+
> : ^^^^^^^^
42+
43+
#instancePrivate = true;
44+
>#instancePrivate : boolean
45+
> : ^^^^^^^
46+
>true : true
47+
> : ^^^^
48+
49+
public exposed = "visible";
50+
>exposed : string
51+
> : ^^^^^^
52+
>"visible" : "visible"
53+
> : ^^^^^^^^^
54+
55+
};
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @target: ES2015
2+
// @declaration: true
3+
4+
export const ClassExpression = class {
5+
#context = 0;
6+
#method() { return 42; }
7+
public value = 1;
8+
};
9+
10+
// Additional test with static private fields
11+
export const ClassExpressionStatic = class {
12+
static #staticPrivate = "hidden";
13+
#instancePrivate = true;
14+
public exposed = "visible";
15+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.