Always use the native (or polyfilled) Promise in transform-async-to-generator (#5536)

* Always use the native (or polyfilled) Promise in transform-async-to-generator

Fixes #5531

* Simplify scope handling to only un-shadow the Program's Promise

Only the helper needs to see the native Promise.
This commit is contained in:
Diogo Franco
2017-04-07 00:17:31 +09:00
committed by Henry Zhu
parent c732f5e1d0
commit 452f8f150c
10 changed files with 95 additions and 0 deletions

View File

@@ -9,6 +9,13 @@ export default function () {
Function(path, state) {
if (!path.node.async || path.node.generator) return;
// Ensure any Promise bindings at the Program level are renamed
// so the asyncToGenerator helper only sees the native Promise
const programScope = path.scope.getProgramParent();
if (programScope.hasBinding("Promise", true)) {
programScope.rename("Promise");
}
remapAsyncToGenerator(path, state.file, {
wrapAsync: state.addHelper("asyncToGenerator"),
});