Babel 不转换装饰器

Babel not transforming decorators

如果我遗漏了一些明显的东西,请原谅我,我对 javascript、ES2015 等比较陌生

我的 Aurelia 申请有一个 gulp 任务要 运行 gulp-babel。所有 运行s 和工作,除了包含装饰器的文件(Aurelia 的 @inject

这些文件在 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"

我不太确定如何开始解决这个问题。我的任务看起来像:

 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));
 });

和我的 compilerOptions:

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

任何见解将不胜感激!

我认为这是一个 babel v6 问题。 (这由您的 presets: ['es2015'] 暗示)

如果你回到 babel v5.x(包含在骨架中)它应该可以工作。

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