Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel not transforming decorators

Forgive me if I'm missing something obvious, I'm relatively new to javascript, ES2015, etc.

I have a gulp task to run gulp-babel over my Aurelia application. Everything runs and works, except the files containing decorators (Aurelia's @inject)

those files spit out the same error in gulp-notify:

Error: (path-to-file)/nav-bar.js: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got "Decorator"

I'm not really sure how to begin resolving this. My task looks like:

 gulp.task('build-system', function () {
    return gulp.src(paths.source)
          .pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
          .pipe(changed(paths.output, {extension: '.js'}))
          .pipe(sourcemaps.init({loadMaps: true}))
          .pipe(babel(compilerOptions))
          .pipe(sourcemaps.write({includeContent: true}))
          .pipe(gulp.dest(paths.output));
 });

and my compilerOptions:

 module.exports = {
   moduleIds: false,
   comments: false,
   compact: false,
   presets: ['es2015'],
   plugins: ['syntax-decorators', 'transform-decorators']
 };

any insight would be greatly appreciated!

like image 506
Jonesopolis Avatar asked Nov 05 '15 03:11

Jonesopolis


1 Answers

I believe this is a babel v6 issue. (which is implied by your presets: ['es2015'])

If you drop back to babel v5.x (as included with the skeleton) it should work.

Here's the decorator issue in the Babel Phabricator instance. It may be some time before it's fixed based on this reply.

like image 172
Michael Malone Avatar answered Sep 28 '22 13:09

Michael Malone