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

Reference to the function expression identifier in it's body has different symbol #37131

Copy link
Copy link
@ark120202

Description

@ark120202
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScriptDomain: BinderGenerally crashes in, or caused by, the binder not doing something rightGenerally crashes in, or caused by, the binder not doing something right

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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