简体   繁体   English

grunt-babel 警告在严格模式下绑定“参数”

[英]grunt-babel warning Binding 'arguments' in strict mode

when I want to compress my javascript code with grunt and uglifyjs,but uglifyjs is not support es6,so I use grunt-babel, but I have meet some truble, it warning Binding 'arguments' in strict mode, so I write some simple code test it.当我想用 grunt 和 uglifyjs 压缩我的 javascript 代码,但 uglifyjs 不支持 es6,所以我使用 grunt-babel,但我遇到了一些麻烦,它警告在严格模式下绑定“参数”,所以我写了一些简单的代码测试一下。 In this file, the arguments is just a common local variable, is not call(arguments) or apply ,I don't understand how it happend and how to fix it.在这个文件中,参数只是一个常见的局部变量,不是 call(arguments) 或 apply ,我不明白它是如何发生的以及如何修复它。 here is the sample code:这是示例代码:

'use strict';
let a = 1;
async function test() {
    return new Promise(resolve, reject => {
        let b = 1;
        let c = a + b;
        resolve(c);
    })
}

function no(arguments) {
    console.log(arguments);
}

then gruntfile.js然后 gruntfile.js

module.exports = function(grunt) {  
  require("load-grunt-tasks")(grunt); 
  grunt.initConfig({  
      pkg: grunt.file.readJSON('package.json'),       
      clean: {
        src: 'dist/'
      },
      copy: {
        main: {
          expand: true,
          cwd: 'test',
          src: '**',
          dest: 'dist/',
        },
      },
      babel: {
          options: {
              sourceMap: false,
              presets: ["@babel/preset-env"],
              ignore: ["/node_modules","./resources/vendor/**"],
              plugins: [
                  "@babel/plugin-transform-runtime",
                  ["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]
                ]
          },
          dist: {
              files: [{
                 expand:true,
                 cwd:'test/',
                 src:['**/*.js'],
                 dest:'dist/'
               }] 
          }
      },
      uglify: {  
          options: {
           mangle: true,
           comments: 'some'
          },  
          my_target: {
               files: [{
                 expand:true,
                 cwd:'dist/',
                 src:['**/*.js'],
                 dest:'dist/'
               }] 
          } 
      }
  });  

    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-babel');
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-usemin');

    grunt.registerTask('default', ['clean','copy','babel','uglify']);
  }

then excute grunt console log然后执行grunt控制台日志

Warning: F:\project\grunttest\test\test.js: Binding 'arguments' in strict mode (11:12)

I tried to configure babel options ["@babel/plugin-transform-modules-commonjs", { "strictMode": false }] but it doesn't work,how can I fix it?我试图配置 babel 选项["@babel/plugin-transform-modules-commonjs", { "strictMode": false }]但它不起作用,我该如何解决? thanks谢谢

as you can find in this link to the MDN documentation: https://developer.mozilla.org/ca/docs/Web/JavaScript/Reference/Functions/arguments您可以在 MDN 文档的链接中找到: https : //developer.mozilla.org/ca/docs/Web/JavaScript/Reference/Functions/arguments

arguments is a reserved keyword within functions in javascript, which when you try to define it as the internal variable within the function no it is not able to bind it correctly, because arguments is this special object that contains all arguments to a function. arguments是JavaScript函数,当您尝试这将其定义为函数内的内部变量中的一个保留关键字no它不能正确绑定,因为arguments是包含所有参数的函数这个特殊的对象。

Just changing the name of the variable to another name will fix your error.只需将变量的名称更改为另一个名称即可修复您的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM