Ben Kilah
Ben Kilah

Reputation: 3475

Angularjs and Closure Compiler

I have this script in one of my controllers:

function AdIssueListCtrl($scope, $http, $rootScope, $compile) {
    $rootScope.nav = {
        adsSideNav: true
    };
    //datasource for kendoui interface
    $scope.kendo_adissues = new kendo.data.DataSource({
        pageSize: 10,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true,
        transport: {
            read: {
                url: "/ads/adissue/kendo/?template=ads/ajax/json/list_adissue_kendo.html",
                dataType: "json"
            }
        },
        schema: {
            total: "count",
            data: 'fields'
        },
        sort: {'field': 'name', dir: 'asc'}
    });
    //delete
    $scope.delete = function (id) {
        var deleteuser = confirm("Are you sure you wish to delete this issue and all it's ads?");
        if (deleteuser) {
            $http.get("/ads/adissue/delete/" + id + "/").success(function (data) {
                if (data.result == 'success') {
                    $scope.kendo_adissues.read();
                }
            });
        }
    };

    //bind data
    $scope.cdb = function (e) {
        var grid = $("#adissues_grid");
        $compile(grid.contents())($scope);
    };
}
AdIssueListCtrl.$inject = ['$scope', '$compile', '$rootScope', '$http'];

I'm using a filewatcher in jetbrains PHPStorm for closure, it basically runs the following on code change.

compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js $FileName$

where the $FileName$ is the currently open file. For some reason I'm getting the following errors.

ERROR - Parse error. missing name after . operator
    $scope.delete = function (id) {
           ^

controllers.js:47: ERROR - Parse error. syntax error
}
^

controllers.js:48: ERROR - Parse error. syntax error
AdIssueListCtrl.$inject = ['$scope', '$compile', '$rootScope', '$http'];

The script works fine non minified, but I'm at a loss as to why it's throwing up those parser errors? Any ideas?

Upvotes: 0

Views: 1763

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

In emcascript3 (older javascript), keywords like delete cannot be used as property names unless they are quoted. Just use the compiler's --language_in option to set the language to either ECMASCRIPT5 or to ECMASCRIPT5_STRICT. The other workaround is to quote the property, but that has renaming implications.

Upvotes: 4

Related Questions