简体   繁体   中英

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. 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. 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

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

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? thanks

as you can find in this link to the MDN documentation: 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.

Just changing the name of the variable to another name will fix your error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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