This commit is contained in:
Onoshko Dan 2014-05-24 01:13:43 +07:00
parent 9a72bc48d0
commit a91ec70cfa
4 changed files with 16 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -74,6 +74,9 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
*/ */
if(options.main_binding && parent instanceof Cola.AST_Toplevel && node instanceof Cola.AST_Defun && node.name instanceof Cola.AST_SymbolDefun && node.name.name == "main"){ if(options.main_binding && parent instanceof Cola.AST_Toplevel && node instanceof Cola.AST_Defun && node.name instanceof Cola.AST_SymbolDefun && node.name.name == "main"){
node.name = new Cola.AST_SymbolLambda(node.name);
node = new Cola.AST_Function(node);
props = { props = {
args : [new Cola.AST_String({ value : options.main_event }), node, new Cola.AST_False()], args : [new Cola.AST_String({ value : options.main_event }), node, new Cola.AST_False()],
expression : new Cola.AST_Dot({ expression : new Cola.AST_Dot({
@ -1780,7 +1783,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
options.parser.is_js = /\.js$/.test(file); options.parser.is_js = /\.js$/.test(file);
options.parser.filename = file; options.parser.filename = file;
var tl = Cola.parse(Cola.getSource(options.path_prefix + file), options.parser); var tl = Cola.parse(Cola.getSource(options.path_prefix + file, options.path_prefix != ""), options.parser);
if (options.parser.is_js) tl = tl.toJavaScript({ if (options.parser.is_js) tl = tl.toJavaScript({
main_binding : options.main_binding, main_binding : options.main_binding,
main_event : options.main_event, main_event : options.main_event,
@ -1803,7 +1806,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
options.parser.is_js = /\.js$/.test(file); options.parser.is_js = /\.js$/.test(file);
options.parser.filename = file; options.parser.filename = file;
var tl = Cola.parse(Cola.getSource(options.path_prefix + file), options.parser); var tl = Cola.parse(Cola.getSource(options.path_prefix + file, options.path_prefix != ""), options.parser);
if (options.parser.is_js) tl = tl.toJavaScript({ if (options.parser.is_js) tl = tl.toJavaScript({
main_binding : options.main_binding, main_binding : options.main_binding,
main_event : options.main_event, main_event : options.main_event,

View File

@ -3,7 +3,7 @@
"description": "ColaScript translator / parser / mangler / compressor / beautifier toolkit", "description": "ColaScript translator / parser / mangler / compressor / beautifier toolkit",
"homepage": "https://github.com/TrigenSoftware/ColaScript", "homepage": "https://github.com/TrigenSoftware/ColaScript",
"main": "tools/node.js", "main": "tools/node.js",
"version": "0.5.0", "version": "0.5.4",
"engines": { "node" : ">=0.4.0" }, "engines": { "node" : ">=0.4.0" },
"maintainers": [{ "maintainers": [{
"name": "Dan Onoshko (dangreen)", "name": "Dan Onoshko (dangreen)",

View File

@ -40,8 +40,8 @@ Cola.AST_Node.warn_function = function(txt) {
sys.error("WARN: " + txt); sys.error("WARN: " + txt);
}; };
Cola.getSource = function(file) { Cola.getSource = function(file, not_cwd) {
return fs.readFileSync(path.join(process.cwd(), file), "utf8"); return fs.readFileSync(not_cwd ? file : path.join(process.cwd(), file), "utf8");
}; };
// XXX: perhaps we shouldn't export everything but heck, I'm lazy. // XXX: perhaps we shouldn't export everything but heck, I'm lazy.
@ -63,7 +63,8 @@ exports.translate = function(files, options) {
output : null, output : null,
compress : {}, compress : {},
is_js : false, is_js : false,
main_binding : true main_binding : true,
path_prefix : ""
}); });
Cola.base54.reset(); Cola.base54.reset();
@ -89,6 +90,7 @@ exports.translate = function(files, options) {
if (!options.is_js) toplevel = toplevel.toJavaScript({ if (!options.is_js) toplevel = toplevel.toJavaScript({
main_binding: options.main_binding, main_binding: options.main_binding,
path_prefix : options.path_prefix,
parser: { parser: {
filename: options.fromString ? "?" : file, filename: options.fromString ? "?" : file,
is_js : options.is_js is_js : options.is_js