-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Bug in async awaits in es5 #40614
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
Comments
The cause seems to be that the generated code use the same value to init all properties (case 9): // Excluded __awaiter and __generator functions
function bar() {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, Promise.resolve(1)];
case 1: return [4 /*yield*/, Promise.resolve(2)];
case 2: return [4 /*yield*/, Promise.resolve(3)];
case 3: return [4 /*yield*/, Promise.resolve(4)];
case 4: return [4 /*yield*/, Promise.resolve(5)];
case 5: return [4 /*yield*/, Promise.resolve(6)];
case 6: return [4 /*yield*/, Promise.resolve(7)];
case 7: return [4 /*yield*/, Promise.resolve(8)];
case 8: return [4 /*yield*/, Promise.resolve(9)];
case 9: return [2 /*return*/, (_a = {},
_a.a = _b.sent(),
_a.b = _b.sent(),
_a.c = _b.sent(),
_a.d = _b.sent(),
_a.e = _b.sent(),
_a.f = _b.sent(),
_a.g = _b.sent(),
_a.h = _b.sent(),
_a.i = _b.sent(),
_a)];
}
});
});
}
bar().then(console.log); |
At first I thought that this is problem with generator transformations, but looks like version where Also original problem is not reproducible in 3.9.7. |
The nightly have the same problem. As a reference for the typescript team, in version 3.9.7 it generates: // Excluded __awaiter and __generator functions
function bar() {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = {};
return [4 /*yield*/, Promise.resolve(1)];
case 1:
_a.a = _b.sent();
return [4 /*yield*/, Promise.resolve(2)];
case 2:
_a.b = _b.sent();
return [4 /*yield*/, Promise.resolve(3)];
case 3:
_a.c = _b.sent();
return [4 /*yield*/, Promise.resolve(4)];
case 4:
_a.d = _b.sent();
return [4 /*yield*/, Promise.resolve(5)];
case 5:
_a.e = _b.sent();
return [4 /*yield*/, Promise.resolve(6)];
case 6:
_a.f = _b.sent();
return [4 /*yield*/, Promise.resolve(7)];
case 7:
_a.g = _b.sent();
return [4 /*yield*/, Promise.resolve(8)];
case 8:
_a.h = _b.sent();
return [4 /*yield*/, Promise.resolve(9)];
case 9: return [2 /*return*/, (_a.i = _b.sent(),
_a)];
}
});
});
}
bar().then(console.log); |
Thanks for the investigation, everyone! 🌟 |
Would it be possible to backport a fix for this to 4.0.x? We unfortunately had to revert our 4.0.x upgrade because this issue was causing our apps to crash, and we'd love to upgrade to 4.0.x before November :) |
Yes, I think we can packport the eventual fix to TypeScript 4.0.4. @elibarzilay do you think you'd be able to prioritize this issue? |
Seems like @elibarzilay is having hardware issues. @rbuckton can you take a look at this? |
I'm back, kind of. Trying to find it now. |
Uses essentially the same code as `visitCommaExpression` (which was moved, to keep both together and close to `visit{Right,Left}AssociativeBinaryExpression`). Fixes microsoft#40614.
Uses essentially the same code as `visitCommaExpression` (which was moved, to keep both together and close to `visit{Right,Left}AssociativeBinaryExpression`). Fixes microsoft#40614.
Uses essentially the same code as `visitCommaExpression` (which was moved, to keep both together and close to `visit{Right,Left}AssociativeBinaryExpression`). Fixes #40614.
If folks can try out the next nightly version of TypeScript to validate that the fix works for them, we'd appreciate that a ton! |
@DanielRosenwasser I tried the nightly out in our repo and it seems to have fixed the issue! |
@DanielRosenwasser sorry to bother, but what's the timeline for 4.0.4? We're super eager to upgrade to 4.0.x :) |
Component commits: 6fa32ba `transformGenerators`: handle `CommaListExpression` Uses essentially the same code as `visitCommaExpression` (which was moved, to keep both together and close to `visit{Right,Left}AssociativeBinaryExpression`). Fixes microsoft#40614.
* Cherry-pick PR #41079 into release-4.0 Component commits: 6fa32ba `transformGenerators`: handle `CommaListExpression` Uses essentially the same code as `visitCommaExpression` (which was moved, to keep both together and close to `visit{Right,Left}AssociativeBinaryExpression`). Fixes #40614. * Accepted baselines. Co-authored-by: Eli Barzilay <[email protected]>
TypeScript Version: 4.1.0-dev.20200917
Search Terms: is:issue is:open async label:bug change
Code
tsconfig.json
Expected behavior:
Actual behavior:
Playground Link:
https://www.typescriptlang.org/play?target=1#code/IYZwngdgxgBAZgV2gFwJYHsIwEbAE4wAUAlDAN4BQMMeApsgnlpddcAFwzADuwqyMAAp50AW1QhaAOjoh0AGwButQgEZiAGiqtsnHnwHCxE6bIXLCAJk3bqUPb35CR4yTNpylKgMw3WMABMHA2djNzMvQgAWP1ZaYKcjV1MPcxUAVljqOATDFxN3TwsANiyYAHNc0OTCtMIAdjKACyqkgoiLAA4y1Fb88NTIgE5YgF8KcYpcPBIpZCbaCEIoTE9peXRy4iA
Related Issues:
#40047
The text was updated successfully, but these errors were encountered: