Cannot use decorators in Node / BabelJS application

I have a Node application that specifies babel with conversion options and registers in the main file, for example:

require('babel').transform('code', { stage: 1 });
require('babel/register')({ ignore: false });
require('../src/index');

Which is great work allowing me to use ES6 in ../src/indexand all subsequent files, but it doesn't seem to allow me to use Decorators, as it should be, declaring a level 1 conversion. I get a syntax error instead. Why does this not support the decorator? The actual decorator I'm trying to use is:

@test1
test Class() {
    constructor() {
        this.test = 'test';
    }
}

function test1(obj) {
    obj.test1 = 'test1';
}
+4
source share
2 answers

, , . JavaScript code .

require('babel/register')({
    ignore: false,
    stage: 1
});
require('../src/index');

ignore: false - , .

Update

Babel 6, babel-plugin-transform-decorators-legacy stage: 1.

+3

, babel (v6) ( 1 ) , babeljs , -

https://twitter.com/sebmck/status/661501967412301824

@jdanyow , , , Babeljs v6, , v6 .

@loganfsmyth , , babel-plugin-transform-decorators-legacy, , , .

0

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


All Articles