Open
Description
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:
- It wasn't the case in 3.7.5
- It's not the case when
program.getSemanticDiagnostics()
is not called or a non-diagnostics-producing type checker is used (ref getTypeChecker returns the same checker manufactured for diagnostics … #28584) - It happens only with function expression, i.e.
const content = 'function y() { y }'
works as expected
Playground Link:
Related Issues: