1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Allow required files to change the input and output of compiled files.

This commit is contained in:
Stan Angeloff 2010-08-13 01:28:38 +03:00
parent 083500fc0e
commit d30c8b321c
2 changed files with 26 additions and 11 deletions

View file

@ -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;
}

View file

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