rpetrich / babel-plugin-transform-async-to-promises

Transform async/await to somewhat idiomatic JavaScript promise chains
MIT License
246 stars 17 forks source link

Async methods should always return a Promise when using inlineHelpers #41

Closed edoardocavazza closed 5 years ago

edoardocavazza commented 5 years ago

When using this plugin with inlineHelpers: true, async methods should always return a Promise also if not using the await keyword.

Example:

class MyClass {
    static async check() {
        return true;
    }
};

console.log(MyClass.check() instanceof Promise); // -> true

is transpiled to:

class MyClass {
    static check() {
         try {
             return true;
         } catch (e) {
             return Promise.reject(e);
         }
     }
}

console.log(MyClass.check() instanceof Promise); // -> false