javascriptangularjsgruntjsgrunt-plugins

grunt-closure-tools : ERROR - Parse error. identifier is a reserved word


I'm using "grunt-closure-tools".

When I try to minify simple JS file, everything works well. But when I try to minify AngularJS library or Bootstrap library, I got next exception:

Error: Command failed: build\lib\angular.js:9040 WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in otion.

build\lib\angular.js:256: ERROR - Parse error. identifier is a reserved word */

build\lib\angular.js:258: ERROR - Parse error. identifier is a reserved word if (isNaN(msie)) {

...................

Gruntfile.js:

module.exports = function(grunt) {

    grunt.initConfig({

        pkg : grunt.file.readJSON('package.json'),

        closureCompiler:  {
            options: {
                compilerFile: 'lib/google-closure-tools/compiler.jar'
            },
            minify: {
                files: [
                    {
                        expand: true,
                        src: ['build/**/*.js', '!build/**/*.min.js'],
                        ext: '.min.js'
                    }
                ]
            }
        }

    });

    grunt.loadNpmTasks('grunt-closure-tools');

    grunt.registerTask('closure', ['closureCompiler']);
};

Thanks for any help.


Solution

  • The solution is using ( language_in: "ECMASCRIPT5" ) during minification.

    Gruntfile.js:

    module.exports = function(grunt) {
    
        grunt.initConfig({
    
            pkg : grunt.file.readJSON('package.json'),
    
            closureCompiler:  {
                options: {
                    compilerFile: 'lib/google-closure-tools/compiler.jar',
                    compilerOpts: {
                        language_in: "ECMASCRIPT5"
                    }
                },
                minify: {
                    files: [
                        {
                            expand: true,
                            src: ['build/**/*.js', '!build/**/*.min.js'],
                            ext: '.min.js'
                        }
                    ]
                }
            }
    
        });
    
        grunt.loadNpmTasks('grunt-closure-tools');
    
        grunt.registerTask('closure', ['closureCompiler']);
    };