TypeScript Version: 3.8.2, 3.9.0-dev.20200229
Search Terms:
Code
const ts = require ( 'typescript' ) ;
const content = 'const x = function y() { y }' ;
const host = ts . createCompilerHost ( { } ) ;
const originalReadFile = host . readFile ;
host . readFile = fileName => ( fileName === 'main.ts' ? content : originalReadFile ( fileName ) ) ;
const program = ts . createProgram ( { host, rootNames : [ 'main.ts' ] , options : { types : [ ] } } ) ;
program . getSemanticDiagnostics ( ) ;
const typeChecker = program . getDiagnosticsProducingTypeChecker ( ) ;
const sourceFile = program . getSourceFile ( 'main.ts' ) ;
const fn = sourceFile . statements [ 0 ] . declarationList . declarations [ 0 ] . initializer ;
const y = fn . name ;
const yInBody = fn . body . statements [ 0 ] . expression . expression ;
const ySymbol = typeChecker . getSymbolAtLocation ( y ) ;
const yInBodySymbol = typeChecker . getSymbolAtLocation ( yInBody ) ;
console . log ( ySymbol === yInBodySymbol ) ;
Expected behavior:
y identifier in function name and y reference in it's body to have the same symbol
Actual behavior:
They have different symbols.
Few notes:
Playground Link:
Related Issues:
Reactions are currently unavailable
TypeScript Version: 3.8.2, 3.9.0-dev.20200229
Search Terms:
Code
Expected behavior:
yidentifier in function name andyreference in it's body to have the same symbolActual behavior:
They have different symbols.
Few notes:
program.getSemanticDiagnostics()is not called or a non-diagnostics-producing type checker is used (ref getTypeChecker returns the same checker manufactured for diagnostics … #28584)const content = 'function y() { y }'works as expectedPlayground Link:
Related Issues: