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

Invalid syntax when transpiling async methods on classes #146

Closed
sisou opened this issue Jul 23, 2018 · 4 comments
Closed

Invalid syntax when transpiling async methods on classes #146

sisou opened this issue Jul 23, 2018 · 4 comments
Labels

Comments

@sisou
Copy link

sisou commented Jul 23, 2018

There seems to be no support for async methods on classes:

class Foo {
    async bar() {
        return await something();
    }

    static async bar() {
        return await something();
    }
}

Bublé transpiles this to

var Foo = function Foo () {};

Foo.prototype.async bar = function bar () {
    return await something();
};

Foo.async bar = function bar () {
    return await something();
};

which is not valid JS.

Demo here: https://buble.surge.sh/#class%20Foo%20%7B%0A%20%20%20%20async%20bar()%20%7B%0A%20%20%20%20%20%20%20%20return%20await%20something()%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20static%20async%20bar()%20%7B%0A%20%20%20%20%20%20%20%20return%20await%20something()%3B%0A%20%20%20%20%7D%0A%7D

@sisou sisou changed the title No support for static async functions on classes No support for static async methods on classes Jul 23, 2018
@sisou
Copy link
Author

sisou commented Jul 23, 2018

Just found #125. Guess it's not allowed in Bublé... how do I switch Svelte's transpiler?

@sisou sisou closed this as completed Jul 23, 2018
@sisou
Copy link
Author

sisou commented Jul 23, 2018

I tested #125 and it does not fix this problem.

@sisou sisou reopened this Jul 23, 2018
@sisou sisou changed the title No support for static async methods on classes No support for async methods on classes Jul 23, 2018
@frozegnome
Copy link

+1, I am running into the same issue :(

@adrianheine
Copy link
Member

There are two issues here:

  1. Bublé does not transpile async functions. That's Support for async functions #90 for implementing support and There should be a CompileError if trying to transpile async functions or await expressions #113 for at least giving an error.
  2. Bublé emits invalid code when encountering async functions. This issue is about methods, Invalid output for async arrow function (expression) #109 is about arrow functions.

Both need to be fixed. Let's make this issue about invalid syntax when transpiling a class with async methods (without transpiling async functions). Head to #90 if you want to talk about implementing transpilation of async functions.

@adrianheine adrianheine added the bug label Oct 8, 2018
@adrianheine adrianheine changed the title No support for async methods on classes Invalid syntax when transpiling async methods on classes Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants