Skip to content

Commit 76fc69c

Browse files
committed
Fix instability
1 parent 80797b4 commit 76fc69c

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

internal/checker/nodebuilderimpl.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,17 @@ func (b *nodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol) *ast.
21292129
if fromNameType != nil {
21302130
return fromNameType
21312131
}
2132-
return b.createPropertyNameNodeForIdentifierOrLiteral(symbol.Name, singleQuote, stringNamed, isMethod)
2132+
2133+
name := symbol.Name
2134+
const privateNamePrefix = ast.InternalSymbolNamePrefix + "#"
2135+
if strings.HasPrefix(name, privateNamePrefix) {
2136+
// symbol IDs are unstable - replace #nnn# with #private#
2137+
name = name[len(privateNamePrefix):]
2138+
name = strings.TrimLeftFunc(name, stringutil.IsDigit)
2139+
name = "__#private" + name
2140+
}
2141+
2142+
return b.createPropertyNameNodeForIdentifierOrLiteral(name, singleQuote, stringNamed, isMethod)
21332143
}
21342144

21352145
// See getNameForSymbolFromNameType for a stringy equivalent

testdata/baselines/reference/submodule/compiler/privateFieldsInClassExpressionDeclaration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export const ClassExpressionStatic = class {
3131
//// [privateFieldsInClassExpressionDeclaration.d.ts]
3232
export declare const ClassExpression: {
3333
new (): {
34-
"\uFFFD#124907@#context": number;
35-
"\uFFFD#124907@#method"(): number;
34+
"__#private@#context": number;
35+
"__#private@#method"(): number;
3636
value: number;
3737
};
3838
};
3939
export declare const ClassExpressionStatic: {
4040
new (): {
41-
"\uFFFD#124908@#instancePrivate": boolean;
41+
"__#private@#instancePrivate": boolean;
4242
exposed: string;
4343
};
44-
"\uFFFD#124908@#staticPrivate": string;
44+
"__#private@#staticPrivate": string;
4545
};

testdata/baselines/reference/submodule/compiler/privateFieldsInClassExpressionDeclaration.js.diff

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,4 @@
4242
+};
4343

4444

45-
//// [privateFieldsInClassExpressionDeclaration.d.ts]
46-
export declare const ClassExpression: {
47-
new (): {
48-
- "__#private@#context": number;
49-
- "__#private@#method"(): number;
50-
+ "\uFFFD#124907@#context": number;
51-
+ "\uFFFD#124907@#method"(): number;
52-
value: number;
53-
};
54-
};
55-
export declare const ClassExpressionStatic: {
56-
new (): {
57-
- "__#private@#instancePrivate": boolean;
58-
+ "\uFFFD#124908@#instancePrivate": boolean;
59-
exposed: string;
60-
};
61-
- "__#private@#staticPrivate": string;
62-
+ "\uFFFD#124908@#staticPrivate": string;
63-
};
45+
//// [privateFieldsInClassExpressionDeclaration.d.ts]

0 commit comments

Comments
 (0)