Skip to content

Dynamic function name causes no symbol returned #33604

Closed
@octref

Description

@octref

TypeScript Version: 3.7.0-dev.20190924

Search Terms:

  • dynamic function name

Code

function createTimesFunction(factor){
	const name='times_'+factor;
	return {[name]: function(x){return x*factor;} }[name];
}

Expected behavior:
TS Server returns symbol createTimesFunction

Actual behavior:
TS Server fails with below stacks trace:

[Error - 17:34:36] Error while computing document symbols for file:///my/path/to/index.html: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at Object.unescapeLeadingUnderscores (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:13211:19)
    at tryGetName (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105875:27)
    at compareChildren (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105861:78)
    at Array.sort (native)
    at sortChildren (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105858:22)
    at endNode (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105614:17)
    at addNodeWithRecursiveChild (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105621:13)
    at addChildrenRecursively (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105704:21)
    at rootNavigationBarNode (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105580:17)
    at Object.getNavigationBarItems (d:\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\typescript.js:105535:45)

Playground Link:

N/A. TS compiles this fine but TS Server fails.

Related Issues: Nope.

Ref: microsoft/vscode#78658

Metadata

Metadata

Assignees

Labels

Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureBugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions