diff --git a/lib/command.js b/lib/command.js index 7b081da5..3e1608cb 100644 --- a/lib/command.js +++ b/lib/command.js @@ -95,7 +95,7 @@ return _d; }; compileScript = function(source, code, base) { - var _d, _e, _f, codeOpts, file, js, o; + var _d, _e, _f, _g, _h, codeOpts, file, js, o, task; o = options; codeOpts = compileOptions(source); if (o.require) { @@ -106,12 +106,21 @@ } } try { - CoffeeScript.emit('compile', { + CoffeeScript.emit('compile', (task = { source: source, code: code, base: base, - options: options - }); + options: options, + codeOpts: codeOpts + })); + if (CoffeeScript.listeners('compile')) { + _g = task; + source = _g.source; + code = _g.code; + base = _g.base; + options = _g.options; + codeOpts = _g.codeOpts; + } if (o.tokens) { return printTokens(CoffeeScript.tokens(code)); } else if (o.nodes) { @@ -119,8 +128,12 @@ } else if (o.run) { return CoffeeScript.run(code, codeOpts); } else { - js = CoffeeScript.compile(code, codeOpts); - CoffeeScript.emit('success', js); + js = (task.js = CoffeeScript.compile(code, codeOpts)); + CoffeeScript.emit('success', task); + if (CoffeeScript.listeners('success')) { + _h = task; + js = _h.js; + } if (o.print) { return print(js); } else if (o.compile) { @@ -130,7 +143,7 @@ } } } catch (err) { - CoffeeScript.emit('failure', err); + CoffeeScript.emit('failure', err, task); if (CoffeeScript.listeners('failure').length) { return null; } diff --git a/src/command.coffee b/src/command.coffee index 2b2acaee..804b8ed5 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -98,20 +98,22 @@ compileScript = (source, code, base) -> if o.require require fs.realpathSync file for file in o.require try - CoffeeScript.emit 'compile', {source, code, base, options} + CoffeeScript.emit 'compile', task = {source, code, base, options, codeOpts} + {source, code, base, options, codeOpts} = task if CoffeeScript.listeners 'compile' if o.tokens then printTokens CoffeeScript.tokens code else if o.nodes then puts CoffeeScript.nodes(code).toString() else if o.run then CoffeeScript.run code, codeOpts else - js = CoffeeScript.compile code, codeOpts - CoffeeScript.emit 'success', js + js = task.js = CoffeeScript.compile code, codeOpts + CoffeeScript.emit 'success', task + {js} = task if CoffeeScript.listeners 'success' if o.print then print js else if o.compile then writeJs source, js, base else if o.lint then lint js catch err # Avoid using 'error' as it is a special event -- if there is no handler, # node will print a stack trace and exit the program. - CoffeeScript.emit 'failure', err + CoffeeScript.emit 'failure', err, task return if CoffeeScript.listeners('failure').length error(err.stack) and process.exit 1 unless o.watch puts err.message