使用Gulp-babel并在严格模式下获得"参数名称冲突"

时间:2016-03-24 14:57:21

标签: javascript gulp ecmascript-6 babeljs gulp-babel

enter image description here

我尝试使用 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']
}))
  

严格模式下的参数名称冲突(2774:5)

1 个答案:

答案 0 :(得分:18)

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

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

function foo(a, a) {
}

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

Here's the error在巴贝尔的REPL中复制。

如果浏览器正确支持严格模式,则会在浏览器中复制错误:

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

在Chrome上,错误是

  

未捕获的SyntaxError:此上下文中不允许使用重复的参数名称

相关问题