P
P
President422015-02-07 12:59:02
JavaScript
President42, 2015-02-07 12:59:02

How to make grunt-contrib-coffee compile human?

For some reason grunt-contrib-coffee compiles the following CoffeeScript code:

f = () ->
    alert()
    return

in this JavaScript:
(function() {
    var f;

    f = function () {
        alert();
    }
}).call(this);

Why everything is thrust into an anonymous function is not clear. It turns out that there is no function f in the global namespace . However, when I used the plugin to autocompile CoffeeScript in Brackets, everything compiled fine. How to make grunt-contrib-coffee compile fine too?
Here is the Gruntfile.js snippet:
coffee: {
    compile: {
        files: [{
            cwd: 'src/scripts',
            src: '**/*.coffee',
            dest: 'result/scripts',
            expand: true,
            flatten: true,
            ext: '.js',
        }]
    },
},
coffeelint: {
    app: {
        src: "src/coffee/*.coffee",
    },
    no_tabs: {
        level: "ignore"
    },
    indentation: {
        level: "warn"
    },
    no_trailing_whitespace: {
        level: "error"
    },
    no_trailing_semicolons: {
        level: "error"
    },
    no_plusplus: {
        level: "warn"
    },
    no_implicit_parens: {
        level: "ignore"
    },
    max_line_length: {
        level: "ignore"
    },
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Chernyshev, 2015-02-07
@President42

Have you tried reading the documentation?
bare
Type: boolean
Compile the JavaScript without the top-level function safety wrapper.
Therefore, put somewhere in the options:
options: {
bare: false
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question