使用Gulp-babel并获得“严格模式下的参数名称冲突” [英] Using Gulp-babel and getting "Argument name clash in strict mode"

查看:746
本文介绍了使用Gulp-babel并获得“严格模式下的参数名称冲突”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use gulp-babel so I can start writing some ES6 / ES2015 code inside of my ES5 app.

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

在我的代码中降低,这就是问题所在:

And lower down in my code, here is where the problem lies:

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)

Argument name clash in strict mode (2774:5)


推荐答案

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

The error isn't in your quoted code, it's on line 2774 of tickertags.bundle.min.js. Babel isn't the problem, Babel is reporting the problem.

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

In strict mode, this is an error:

function foo(a, a) {
}

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

Note that a has been used as an argument name twice. That's valid loose code, but not valid strict code. That's what the error message is telling you about.

这里的错误在Babel的REPL中复制。

Here's the error replicated in Babel's REPL.

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

Here's the error replicated in your browser, if your browser correctly supports strict mode:

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

在Chrome上,错误是

On Chrome, the error is


未捕获的SyntaxError:不允许重复的参数名称在这种情况下

Uncaught SyntaxError: Duplicate parameter name not allowed in this context

这篇关于使用Gulp-babel并获得“严格模式下的参数名称冲突”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆