The keyword "super" unexpectedly inside the generator

When I try to use the super keyword inside the generator, I get the following error

base_model.js:82
        yield super.$beforeInsert(context);
              ^^^^^
SyntaxError: 'super' keyword unexpected here

Here's the source code (Transpiled via Babel)

class BaseModel extends Model {
    $beforeInsert(context) {
        var _this = this;

        return _asyncToGenerator(function* () {
            yield super.$beforeInsert(context);
            if (_this.timestamps) {
                _this.created_at = new Date();
            }
        })();
    }
}

Here is the source code

class BaseModel extends Model {
    async $beforeInsert(context) {
        await super.$beforeInsert(context);
        if (this.timestamps) {
            this.created_at = new Date();
        }
    }
}

I am using node v6.3.1

+4
source share

Source: https://habr.com/ru/post/1651860/


All Articles