Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object initializer creates unused variable #6488

Closed
SamuelMarks opened this issue Jan 14, 2016 · 5 comments
Closed

Object initializer creates unused variable #6488

SamuelMarks opened this issue Jan 14, 2016 · 5 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@SamuelMarks
Copy link

#1082 called for [Object initializer](the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) ES6 syntax.

Using tsc/typescript 1.7.5 with Node 5.3.0.

Input:
const x = {['c']: 'b'};
Output [tsc input.ts]:
var x = (_a = {}, _a['c'] = 'b', _a);
var _a;
@RyanCavanaugh
Copy link
Member

I'm confused by which variable you think is unused? _a is used as a temporary during object initialization and cannot be removed. What do you expect the emit to be?

@SamuelMarks
Copy link
Author

What's with line 2?

@RyanCavanaugh
Copy link
Member

Again, what do you expect the emit to be?

@SamuelMarks
Copy link
Author

Either the _a being declared before its use, or not declared with var at all.

@DanielRosenwasser
Copy link
Member

var declarations are hoisted. We take advantage of this at emit-time and aggregate all temporaries we determine we need as we build up the output. Then, at the end of an appropriate scope, we emit the declaration for all temporaries. There's nothing wrong with this semantically, and the variables are not unused.

@DanielRosenwasser DanielRosenwasser added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Jan 15, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

3 participants