Issue 1:
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']

Issue 2:
Bug Report

Hello, first let me thank the Babel contributors for your hard work. Unfortunately, I had an issue using the @babel/plugin-proposal-decorators plugin.

Current Behavior

The async keyword will be stripped of a class' method if the class has a decorator. The erroneous behavior is not reproduced while the plugin is active if the class is not decorated.

Input Code

Here is a repo with a minimal reproducible example.

Summary of the issue follows

Given the following code

function Decorator ({ property } = {}) {
return function ClassDecorator (classDescriptor) {
console.log(property)
return classDescriptor
}
}

@Decorator({
property: true
})
class GenericClass {
async method () {
await Promise.resolve()

return true
}
}

This code will then become (when stripped of babel internal functions):

function Decorator({
property
} = {}) {
return function ClassDecorator(classDescriptor) {
console.log(property);
return classDescriptor;
};
}

let GenericClass = _decorate([Decorator({
property: true
})], function (_initialize) {
class GenericClass {
constructor() {
_initialize(this);
}

}

return {
F: GenericClass,
d: [{
kind: "method",
key: "method",

value() {
await Promise.resolve();
return true;
}

}]
};
});

Note the lack of an async keyword on the value function. This causes browser or linters to correctly point out the syntax error.

Expected behavior/code

// ...

return {
F: GenericClass,
d: [{
kind: "method",
key: "method",

async value() {
await Promise.resolve();
return true;
}

}]
};

// ...

or maybe

// ...

return {
F: GenericClass,
d: [{
kind: "method",
key: "method",

value() {
return (async () => {
await Promise.resolve();
return true;
})();
}

}]
};

// ...

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

{
"plugins": [
[ "@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true } ]
]
}

Environment

Babel version: v7.1.0

Node/npm version: Node 10/NPM 6

OS: Windows 10

Monorepo: yes

How you are using Babel: cli, loader

Note: This issue was first discovered using the loader along with Webpack but was reproduced later with the CLI.

Additional context

I have tried to search for similar issues on Google and this repo's issue tracker but could not find someone with the same experience. My apologies if this is already known and/or was already posted.

Please do not hesitate to ask if you need more details.

Thanks in advance for your time. Have a nice day.