gulp - Babel 不会改变装饰器

标签 gulp ecmascript-6 babeljs aurelia

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

我有一个 gulp 任务要运行 gulp-babel在我的 Aurelia应用。一切正常,除了包含装饰器的文件(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在 Babel Phabricator 实例中。基于 this reply,它可能需要一段时间才能修复.

关于gulp - Babel 不会改变装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33536380/

相关文章:

javascript - 在 Promise 中访问模板变量。 [ meteor +烈焰]

javascript - 如何在 React 中将数组作为 props 传递而不转换为字符串

javascript - 导入 react-native-fetch-blob 时出现意外 token

node.js - 以非 root 身份运行 Gulp 时出现 EPERM 错误

Gulp:如何自动替换 html 中的缩小文件?

javascript - 在 TypeScript 中克隆对象数组

javascript - Object.assign 保留对原始对象的引用

node.js - 通过 gulp-nodemon 传递 CLI 参数

javascript - 如何将这两个 Gulp 任务合并为一个任务?

javascript - 为什么在下面的示例中我必须同时使用剩余参数和扩展运算符?