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

Parsing error when using @babel/plugin-proposal-decorators #8758

Closed
millsp opened this issue Sep 24, 2018 · 2 comments
Closed

Parsing error when using @babel/plugin-proposal-decorators #8758

millsp opened this issue Sep 24, 2018 · 2 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@millsp
Copy link

millsp commented Sep 24, 2018

Bug Report

Current Behavior
Babel parser gets confused when using decorators.

Additional context/Screenshots

    Module parse failed: Can not use keyword 'await' outside an async function (86:8)
    You may need an appropriate loader to handle this file type.
    |       key: "t",
    |       value: function value() {
    >         await this.s();
    |       }
    |     }, {
     @ ./src/index.js 7:13-40

As you can see await this.s() is within an async so there should be no problem.
Remove the decorator then the problem is gone immediately.

Input Code

function decorator(Class) {
     return function (...args) {
          return new Class(...args);
     }
}

@decorator
class Test {
     constructor(props) {
     }

     async t() {
          await this.s()
     }

     async s() {
     }
}

new Test();

Expected behavior/code
This is supposed to compile just fine.

Babel Configuration (.babelrc, package.json, cli command)

module.exports = function (api) {
     //console.log('----------------------------test-------------------------');
     api.cache(true);

     const presets = [
          ['@babel/preset-env'],
     ];

     const plugins = [
          ['@babel/plugin-transform-runtime'],
          ['@babel/plugin-proposal-decorators', {decoratorsBeforeExport: false}],
          ['@babel/plugin-proposal-class-properties'],
     ];

     return {
          presets: presets,
          plugins: plugins,
     };

};

Environment

  • Babel version(s): 7.1.0
  • Node/npm version: [Node 8.12 / NPM 6.4.1]
  • OS: [Ubuntu 16.04 LTS]
  • How you are using Babel: ['cli', 'webpack']
@babel-bot
Copy link
Collaborator

Hey @pirix-gh! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Sep 24, 2018

Duplicated of #8737, fixed by #8742

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 24, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants