Additional source using fixed.
This commit is contained in:
parent
a91ec70cfa
commit
53df087ee9
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@ tmp/
|
|||
node_modules/
|
||||
sugar.min.js
|
||||
demo.cola.js
|
||||
npm-debug.log
|
||||
|
|
|
|||
2
bin/cola
2
bin/cola
|
|
@ -294,8 +294,8 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||
|
||||
if (!ARGS.j) TOPLEVEL = TOPLEVEL.toJavaScript({
|
||||
main_binding: !ARGS.n,
|
||||
path: path.dirname(file),
|
||||
parser: {
|
||||
filename : file,
|
||||
expression : ARGS.expr,
|
||||
is_js : ARGS.j
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// `main` functions may binding to a onload event
|
||||
// Functions can defined without `function` keyword, with and without `type`
|
||||
@require '../sugar.min.js'
|
||||
@require './sugar.min.js'
|
||||
|
||||
main(){
|
||||
// Unary operators
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
window.addEventListener("DOMContentLoaded", Cola.bootstrap, false);
|
||||
window.addEventListener("load", Cola.bootstrap, false);
|
||||
|
|
@ -46,7 +46,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
|||
main_event : 'DOMContentLoaded',
|
||||
parser : {},
|
||||
std : true,
|
||||
path_prefix : ""
|
||||
path : ""
|
||||
});
|
||||
|
||||
var $_cola_ast = Cola.parse(Cola.$_cola, { is_js : true }),
|
||||
|
|
@ -1533,7 +1533,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
|||
} else
|
||||
|
||||
/*
|
||||
var o = if(a) 'start'; else 'finish';
|
||||
var o = if(a) 'start' else 'finish';
|
||||
|
||||
to
|
||||
|
||||
|
|
@ -1781,13 +1781,14 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
|||
node.args.forEach(function(file){
|
||||
|
||||
options.parser.is_js = /\.js$/.test(file);
|
||||
options.parser.filename = file;
|
||||
options.parser.filename = Cola.notRoot(file) ? options.path + "/" + file : file;
|
||||
|
||||
var tl = Cola.parse(Cola.getSource(options.path_prefix + file, options.path_prefix != ""), options.parser);
|
||||
if (options.parser.is_js) tl = tl.toJavaScript({
|
||||
var tl = Cola.parse(Cola.getSource(options.parser.filename), options.parser);
|
||||
if (!options.parser.is_js) tl = tl.toJavaScript({
|
||||
main_binding : options.main_binding,
|
||||
main_event : options.main_event,
|
||||
parser : options.parser,
|
||||
path : Cola.dirname(options.parser.filename),
|
||||
std : false
|
||||
});
|
||||
|
||||
|
|
@ -1804,13 +1805,14 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
|||
required_hash[file] = true;
|
||||
|
||||
options.parser.is_js = /\.js$/.test(file);
|
||||
options.parser.filename = file;
|
||||
options.parser.filename = Cola.notRoot(file) ? options.path + "/" + file : file;
|
||||
|
||||
var tl = Cola.parse(Cola.getSource(options.path_prefix + file, options.path_prefix != ""), options.parser);
|
||||
if (options.parser.is_js) tl = tl.toJavaScript({
|
||||
var tl = Cola.parse(Cola.getSource(options.parser.filename), options.parser);
|
||||
if (!options.parser.is_js) tl = tl.toJavaScript({
|
||||
main_binding : options.main_binding,
|
||||
main_event : options.main_event,
|
||||
parser : options.parser,
|
||||
path : Cola.dirname(options.parser.filename),
|
||||
std : false
|
||||
});
|
||||
|
||||
|
|
|
|||
33
lib/utils.js
33
lib/utils.js
|
|
@ -50,8 +50,16 @@ Cola.getSource = function (url) {
|
|||
return xhr.responseText;
|
||||
};
|
||||
|
||||
Cola.dirname = function (dir) {
|
||||
return dir.replace(/\/[^\/]*$/, "");
|
||||
};
|
||||
|
||||
Cola.notRoot = function (path) {
|
||||
return path[0] != "/" && !/^http/.test(path);
|
||||
};
|
||||
|
||||
Cola.translate = function (source, opts) {
|
||||
var stream = new Cola.OutputStream(),
|
||||
var stream = new Cola.OutputStream({ beautify : true }),
|
||||
ast;
|
||||
|
||||
try {
|
||||
|
|
@ -70,21 +78,30 @@ Cola.translate = function (source, opts) {
|
|||
};
|
||||
|
||||
Cola.eval = function (source, opts) {
|
||||
return eval(Cola.translate(source, opts));
|
||||
return eval.call(this, Cola.translate(source, opts));
|
||||
};
|
||||
|
||||
Cola.bootstraped = false;
|
||||
Cola.bootstrap = function () {
|
||||
var source = "";
|
||||
if (Cola.bootstraped) return;
|
||||
Cola.bootstraped = true;
|
||||
|
||||
//var source = "";
|
||||
Array.prototype.forEach.call(document.querySelectorAll('script[type="text/colascript"][src]'),
|
||||
function(script){
|
||||
var path_prefix = script.src.split("/"); path_prefix.pop();
|
||||
path_prefix = path_prefix.join("/") + "/";
|
||||
Cola.eval(Cola.getSource(script.src), { main_event : "ColaScriptMain", path_prefix : path_prefix });
|
||||
if (/\.js$/.test(script.src)) eval.call(window, Cola.getSource(script.src));
|
||||
else Cola.eval.call(window, Cola.getSource(script.src), { path: Cola.dirname(script.src) });
|
||||
});
|
||||
|
||||
var event = document.createEvent("HTMLEvents");
|
||||
event.initEvent("ColaScriptMain", true, true);
|
||||
event.eventName = "ColaScriptMain";
|
||||
event.initEvent("DOMContentLoaded", true, true);
|
||||
event.eventName = "DOMContentLoaded";
|
||||
|
||||
window.dispatchEvent(event);
|
||||
|
||||
event = document.createEvent("HTMLEvents");
|
||||
event.initEvent("load", true, true);
|
||||
event.eventName = "load";
|
||||
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"description": "ColaScript translator / parser / mangler / compressor / beautifier toolkit",
|
||||
"homepage": "https://github.com/TrigenSoftware/ColaScript",
|
||||
"main": "tools/node.js",
|
||||
"version": "0.5.4",
|
||||
"version": "0.5.5",
|
||||
"engines": { "node" : ">=0.4.0" },
|
||||
"maintainers": [{
|
||||
"name": "Dan Onoshko (dangreen)",
|
||||
|
|
|
|||
|
|
@ -40,10 +40,12 @@ Cola.AST_Node.warn_function = function(txt) {
|
|||
sys.error("WARN: " + txt);
|
||||
};
|
||||
|
||||
Cola.getSource = function(file, not_cwd) {
|
||||
return fs.readFileSync(not_cwd ? file : path.join(process.cwd(), file), "utf8");
|
||||
Cola.getSource = function(file) {
|
||||
return fs.readFileSync(Cola.notRoot(file) ? path.join(process.cwd(), file) : file, "utf8");
|
||||
};
|
||||
|
||||
Cola.dirname = path.dirname;
|
||||
|
||||
// XXX: perhaps we shouldn't export everything but heck, I'm lazy.
|
||||
for (var i in Cola) {
|
||||
if (Cola.hasOwnProperty(i)) {
|
||||
|
|
@ -64,7 +66,7 @@ exports.translate = function(files, options) {
|
|||
compress : {},
|
||||
is_js : false,
|
||||
main_binding : true,
|
||||
path_prefix : ""
|
||||
path : false
|
||||
});
|
||||
Cola.base54.reset();
|
||||
|
||||
|
|
@ -90,9 +92,8 @@ exports.translate = function(files, options) {
|
|||
|
||||
if (!options.is_js) toplevel = toplevel.toJavaScript({
|
||||
main_binding: options.main_binding,
|
||||
path_prefix : options.path_prefix,
|
||||
path: options.path || path.dirname(file),
|
||||
parser: {
|
||||
filename: options.fromString ? "?" : file,
|
||||
is_js : options.is_js
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user