-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Template string expression statement leading with object literal gives incorrect emit #4912
Comments
Note this also applies to arrow functions, function expressions, and class expressions. |
Interestingly, we also output extra parenthesis when doing a destructuring assignment within a template expression: let x,y;
`${ {x,y} = {x: 2, y: 3} }HELLO` emits as: var x, y;
((_a = { x: 2, y: 3 }, x = _a.x, y = _a.y, _a)) + "HELLO";
var _a; Additionally, the declaration of the temporary variable is placed after the expression - there's nothing expressly wrong with that, but it seems like bad form. |
I might have a fix for this, so let's leave it assigned to me for now. |
Is this still open? If yes, I would like to attempt a fix. :) |
It doesn't appear to be. `${{ hello: 10, world: 20 }}HELLO`; ...emits... ({ hello: 10, world: 20 } + "HELLO"); Both result in the same string of:
So ultimately this issue should be closed as the ES6+ behaviour matches the down-emit behaviour. |
@DanielRosenwasser This can be closed, is solved since minimum September 2017. `${{ hello: 10, world: 20 }}HELLO`;
`${() => 0}HELLO`;
`${function () { }}HELLO`;
`${class a { }}HELLO`; is compiled to (comments are the result running it on firefox console): ({ hello: 10, world: 20 } + "HELLO"); // [object Object]HELLO
(function () { return 0; } + "HELLO"); // function () { return 0; }HELLO
(function () { } + "HELLO"); // function () { }HELLO
/** @class */ (function () {
function a() {
}
return a;
}()) + "HELLO"; /* function a() {
}HELLO */ |
Something like
will get emitted as
As an expresssion statement, the former evaluates to
"[object Object]HELLO"
while the latter evaluates toNaN
.This is because the former gets parsed as:
The text was updated successfully, but these errors were encountered: