使用 Gulp-babel 并获得 "Argument name clash in strict mode"

Using Gulp-babel and getting "Argument name clash in strict mode"

我正在尝试使用 gulp-babel 以便我可以开始在我的 ES5 应用程序中编写一些 ES6 / ES2015 代码。

var gulp          = require('gulp'),
    gutil         = require('gulp-util'),
    gulpif        = require('gulp-if'),
    uglify        = require('gulp-uglify'),
    concat        = require('gulp-concat'),
    sass          = require('gulp-ruby-sass'),
    streamqueue   = require('streamqueue'),
    sourcemaps    = require('gulp-sourcemaps'),
    templateCache = require('gulp-angular-templatecache'),
    htmlReplace   = require('gulp-html-replace'),
    runSequence   = require('run-sequence'),
    stripDebug    = require('gulp-strip-debug'),
    del           = require('del'),
    es            = require('event-stream'),
    webpack       = require('webpack-stream'),
    babel         = require('gulp-babel'),
    browserSync   = require('browser-sync').create();

在我的代码中,问题就在这里:

gulp.task('build-min-bundle', function() {
    gutil.log(gutil.colors.blue.bold(' Compiled bundle file contains these modules:'));
    for (var i=0; i<paths.scripts.length; i++) {
        gutil.log(gutil.colors.yellow.bold('  '+paths.scripts[i]));
    }
    return gulp.src(paths.bundle)
    .pipe(stripDebug())
    .pipe(concat(dist))
    .pipe(babel()) // <--
    .pipe(uglify())
    .on('error', errorlog)
    .pipe(gulp.dest('app/assets/js'));
});

我最初尝试过这个:

.pipe(babel({
    presets: ['es2015']
}))

Argument name clash in strict mode (2774:5)

错误不在您引用的代码中,它在 tickertags.bundle.min.js 的第 2774 行。问题不是 Babel,问题是 Babel 报告

在严格模式下,这是一个错误:

function foo(a, a) {
}

请注意 a 已被用作参数名称两次。这是有效的松散代码,但不是有效的严格代码。这就是错误消息告诉您的内容。

Here's the error 在 Babel 的 REPL 中复制。

如果您的浏览器正确支持严格模式,以下是您浏览器中复制的错误:

"use strict";
function foo(a, a) {
}

在Chrome,错误是

Uncaught SyntaxError: Duplicate parameter name not allowed in this context