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

Cleaned up return logic

- ReturnNodes are explicitly added during compilation
 - ReturnNode is used instead of scattering "return" throughout
   code compilation snippets
 - nodes gain a make_return method in order to do the most useful
   thing when a return is requested
This commit is contained in:
gfxmonk 2010-03-21 22:17:58 +11:00
parent 8553a89af2
commit cc3c314988
11 changed files with 458 additions and 145 deletions

View file

@ -74,6 +74,7 @@
_a.push(compile(source));
}
return _a;
return null;
};
// Compile a single source script, containing the given code, according to the
// requested options. Both compile_scripts and watch_scripts share this method
@ -99,14 +100,18 @@
} else if (o.lint) {
return lint(js);
}
return null;
}
return null;
} catch (err) {
if (o.watch) {
return puts(err.message);
} else {
throw err;
}
return null;
}
return null;
};
// Attach the appropriate listeners to compile scripts incoming over **stdin**,
// and write them back to **stdout**.
@ -118,6 +123,7 @@
if (string) {
return code += string;
}
return null;
});
return process.stdio.addListener('close', function() {
return compile_script('stdio', code);
@ -147,6 +153,7 @@
_a.push(watch(source));
}
return _a;
return null;
};
// Write out a JavaScript source file with the compiled code. By default, files
// are written out in `cwd` as `.js` files with the same name, but the output
@ -167,11 +174,13 @@
if (result) {
return puts(result.replace(/\n/g, ''));
}
return null;
});
jsl.addListener('error', function(result) {
if (result) {
return puts(result);
}
return null;
});
jsl.write(js);
return jsl.close();
@ -191,6 +200,7 @@
}).call(this));
}
return _a;
return null;
}).call(this);
return puts(strings.join(' '));
};
@ -202,7 +212,8 @@
o = (options = option_parser.parse(process.argv));
options.run = !(o.compile || o.print || o.lint);
options.print = !!(o.print || (o.eval || o.stdio && o.compile));
return sources = options.arguments.slice(2, options.arguments.length);
sources = options.arguments.slice(2, options.arguments.length);
return sources;
};
// The compile-time options to pass to the CoffeeScript compiler.
compile_options = function compile_options(source) {