@@ -19,6 +19,7 @@ import {
1919 isJSDoc ,
2020 isJSDocParameterTag ,
2121 isJsxSelfClosingElement ,
22+ isMethodDeclaration ,
2223 isModuleDeclaration ,
2324 isNamedImports ,
2425 isObjectLiteralExpression ,
@@ -7171,6 +7172,31 @@ notCallable();
71717172} ) ;
71727173
71737174describe ( "Symbol - escaped names and tables" , { concurrency } , ( ) => {
7175+ test ( "private member display names do not expose unique symbol table keys" , async ( ) => {
7176+ await using api = spawnAPI ( {
7177+ "/tsconfig.json" : "{}" ,
7178+ "/src/main.ts" : "export class A { #value = 1; #method() {} } export class B { #value = 2; }" ,
7179+ } ) ;
7180+ const snapshot = await api . createSnapshot ( { openProjects : [ "/tsconfig.json" ] } ) ;
7181+ const project = snapshot . getConfiguredProject ( "/tsconfig.json" ) ! ;
7182+ const source = await project . program . getSourceFile ( "/src/main.ts" ) ;
7183+ assert . ok ( source ) ;
7184+ const symbols = [ ] ;
7185+ for ( const declaration of source . statements . filter ( isClassDeclaration ) ) {
7186+ for ( const member of declaration . members ) {
7187+ if ( ! ( isPropertyDeclaration ( member ) || isMethodDeclaration ( member ) ) || ! isPrivateIdentifier ( member . name ) ) continue ;
7188+ const symbol = await project . checker . getSymbolAtLocation ( member . name ) ;
7189+ assert . ok ( symbol ) ;
7190+ assert . strictEqual ( symbol . name , member . name . text ) ;
7191+ assert . notStrictEqual ( symbol . escapedName , symbol . name ) ;
7192+ symbols . push ( symbol ) ;
7193+ }
7194+ }
7195+ assert . strictEqual ( symbols . length , 3 ) ;
7196+ assert . notStrictEqual ( symbols [ 0 ] . escapedName , symbols [ 2 ] . escapedName ) ;
7197+ assert . strictEqual ( symbols [ 0 ] . name , symbols [ 2 ] . name ) ;
7198+ } ) ;
7199+
71747200 test ( "getExports/getMembers return a cached Map keyed by escaped name" , async ( ) => {
71757201 await using api = spawnAPI ( {
71767202 "/tsconfig.json" : JSON . stringify ( { compilerOptions : { strict : true } } ) ,
0 commit comments