From 4ca50fdc44e8401599528c5fdb2ec5c063c275ff Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Thu, 22 Sep 2011 00:26:02 -0500 Subject: [PATCH 1/3] generate inserts into steal better --- generate/generate.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/generate/generate.js b/generate/generate.js index 47146689a..780782282 100644 --- a/generate/generate.js +++ b/generate/generate.js @@ -265,31 +265,44 @@ steal("steal/generate/ejs.js", 'steal/generate/inflector.js', tokens = [], lastToken, token, - duplicate = false; + duplicate = false, + cur; // parse until steal( while (token = parser.until(["steal", "("], [".","then","("])) { + //print("M = " + token.value, token.type, token.from, token.to) if (token) { - parser.partner("(", function(token){ - if (token.type == "name" || token.type == "string") { - lastToken = token; - } - if (token.type === "string" && token.value === newStealPath) { // duplicate + while( (cur = parser.moveNext() ) && ( cur.value === "," || cur.type === "string" ) ) { + //print("TOKEN = " + cur.value, cur.type, cur.from, cur.to); + //if (cur.type == "name" || cur.type == "string") { + // lastToken = cur; + //} + if (cur.type === "string" && cur.value === newStealPath) { // duplicate duplicate = true; } -// print("TOKEN = " + token.value, token.type, token.from, token.to) - }) + } + lastToken = cur; + break; } if (duplicate) { - throw {type: "DUPLICATE"} + throw "DUPLICATE "+newStealPath } } // insert steal if(lastToken){ - fileTxt = fileTxt.slice(0, lastToken.from) + //print("TOKEN = " + lastToken.value, lastToken.type, lastToken.from, lastToken.to); + if(lastToken.value == ")") { + + fileTxt = fileTxt.slice(0, lastToken.from) + + ", "+(newline ? "\n\t" : "")+"'" + newStealPath + "'" + fileTxt.slice(lastToken.from) + + } else { + fileTxt = fileTxt.slice(0, lastToken.from) + "'" + newStealPath + "'," +(newline ? "\n\t" : " ") + fileTxt.slice(lastToken.from) + } + } else { // no steal found fileTxt += "steal('" + newStealPath +"')" } From 2a7de0db0b9873e7a4f897ace77a012a44daa4bf Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 22 Sep 2011 04:14:59 -0500 Subject: [PATCH 2/3] steal.dev.log and warn can handle nested parens now, as described in issue #21 --- build/scripts/scripts.js | 31 ++++++++++++++++++++++++++----- build/test/dev.js | 6 ++++++ build/test/devCleaned.js | 6 ++++++ build/test/run.js | 18 ++++++++++++++++++ parse/parse.js | 3 +-- parse/parse_test.js | 10 ++++++---- parse/test/dev.js | 2 ++ parse/tokens.js | 5 ++++- 8 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 build/test/dev.js create mode 100644 build/test/devCleaned.js create mode 100644 parse/test/dev.js diff --git a/build/scripts/scripts.js b/build/scripts/scripts.js index f2c836344..1730a6b5a 100644 --- a/build/scripts/scripts.js +++ b/build/scripts/scripts.js @@ -1,4 +1,4 @@ -steal('steal/build').then(function( steal ) { +steal('steal/build', 'steal/parse').then(function( steal ) { /** * Builds JavaScripts @@ -13,6 +13,7 @@ steal('steal/build').then(function( steal ) { */ var scripts = (steal.build.builders.scripts = function( opener, options, dependencies ) { steal.print("\nBUILDING SCRIPTS --------------- "); + var start = new Date(); // get the compressor var compressor = scripts.compressors[options.compressor || "localClosure"](), @@ -33,6 +34,8 @@ steal('steal/build').then(function( steal ) { // grab the previous currentCollection and compress it, then add it to currentPackage if (currentCollection.length) { var compressed = currentCollection.join("\n"); + // clean out any remove-start style comments + compressed = scripts.clean(compressed); compressed = compressor(compressed, true); currentCollection = []; return compressed; @@ -78,9 +81,6 @@ steal('steal/build').then(function( steal ) { } currentPackage = packages[pack]; } - - // clean out any remove-start style comments - text = scripts.clean(text); // if we should compress the script, compress it if ( stl.compress !== false || options.all ) { @@ -118,6 +118,9 @@ steal('steal/build').then(function( steal ) { var compressed = packages[p].src.join("\n"); //save them new steal.File(options.to + p).save(loading+dependencyStr+compressed); + var end = new Date(), + time = (end-start) + print(time+' MS') steal.print("SCRIPT BUNDLE > " + options.to + p); } } @@ -125,7 +128,25 @@ steal('steal/build').then(function( steal ) { // removes dev comments from text scripts.clean = function( text ) { - return String(java.lang.String(text).replaceAll("(?s)\/\/@steal-remove-start(.*?)\/\/@steal-remove-end", "").replaceAll("steal[\n\s\r]*\.[\n\s\r]*dev[\n\s\r]*\.[\n\s\r]*(\\w+)[\n\s\r]*\\([^\\)]*\\)", "")); + var parsedTxt = String(java.lang.String(text) + .replaceAll("(?s)\/\/@steal-remove-start(.*?)\/\/@steal-remove-end", "")), + positions = [], + p = steal.parse(parsedTxt), + tokens, i, position; + + while (tokens = p.until(["steal", ".", "dev", ".", "log", "("], ["steal", ".", "dev", ".", "warn", "("])) { + var end = p.partner("("); + positions.push({ + start: tokens[0].from, + end: end.to + }) + } + // go through in reverse order + for (i = positions.length - 1; i >= 0; i--) { + position = positions[i]; + parsedTxt = parsedTxt.substring(0, position.start) + parsedTxt.substring(position.end) + } + return parsedTxt; }; //various compressors diff --git a/build/test/dev.js b/build/test/dev.js new file mode 100644 index 000000000..3cee80a3f --- /dev/null +++ b/build/test/dev.js @@ -0,0 +1,6 @@ +checkText = function( text, url ) { + if (!text.match(/[^\s]/) ) { + steal.dev.log("There is no template or an empty template at " + url) + throw "$.View ERROR: There is no template or an empty template at " + url; + } +}; \ No newline at end of file diff --git a/build/test/devCleaned.js b/build/test/devCleaned.js new file mode 100644 index 000000000..8a2b74af9 --- /dev/null +++ b/build/test/devCleaned.js @@ -0,0 +1,6 @@ +checkText = function( text, url ) { + if (!text.match(/[^\s]/) ) { + + throw "$.View ERROR: There is no template or an empty template at " + url; + } +}; \ No newline at end of file diff --git a/build/test/run.js b/build/test/run.js index f982509de..80f4b0ec8 100644 --- a/build/test/run.js +++ b/build/test/run.js @@ -7,6 +7,24 @@ steal('steal/test/test.js', function( s ) { STEALPRINT = false; s.test.module("steal/build") + s.test.test("steal.dev removes parens", function(){ + load('steal/rhino/rhino.js') + var dev = readFile('steal/build/test/dev.js'), + devCleaned = readFile('steal/build/test/devCleaned.js'); + steal("steal/build","steal/build/scripts").then(function(s2){ + var a = steal.build.builders.scripts.clean("var bla;var foo;steal.dev.log('hi')") + s.test.equals(a, "var bla;var foo;", "clean works") + var b = steal.build.builders.scripts.clean("var bla;steal.dev.log('hi()');var foo;steal.dev.log('onetwo(bla())')") + s.test.equals(b, "var bla;;var foo;", "clean works with parens") + var c = steal.build.builders.scripts.clean("var bla;steal.dev.warn('hi()');var foo;steal.dev.warn('onetwo(bla())')") + s.test.equals(b, "var bla;;var foo;", "clean works with warn") + var d = steal.build.builders.scripts.clean(dev); + s.test.equals(d, devCleaned, "clean really works") + }); + s.test.clear(); + }) + return; + s.test.test("less packages correctly", function(){ load('steal/rhino/rhino.js') steal("steal/build","steal/build/scripts","steal/build/styles", "steal/build/apps").then(function(s2){ diff --git a/parse/parse.js b/parse/parse.js index a2a695c9d..6c3ce3e95 100644 --- a/parse/parse.js +++ b/parse/parse.js @@ -216,8 +216,7 @@ steal.parse = function(str){ while (token = this.moveNext() ) { for(i =0; i< patterns.length; i++){ var pattern = patterns[i]; - - if( token.type !== "string" && like( pattern[patternMatchPosition[i]], token) ){ + if( token.type !== "string" && like( pattern[patternMatchPosition[i].length], token) ){ patternMatchPosition[i].push(token); if(patternMatchPosition[i].length === pattern.length){ return patternMatchPosition[i]; diff --git a/parse/parse_test.js b/parse/parse_test.js index 54d10638e..c617c905e 100644 --- a/parse/parse_test.js +++ b/parse/parse_test.js @@ -48,10 +48,10 @@ steal('steal/test','steal/parse').then( function( s ) { var parser = steal.parse(readFile('steal/parse/test/stealCode1.js')), tokens = []; - parser.until(["steal",".","plugins","("]); + parser.until(["steal","("]); parser.partner("(", function(token){ tokens.push(token); - //print("TOKEN = "+token.value, token.type) +// print("TOKEN = "+token.value, token.type) }) t.equals(tokens[0].value,"foo/bar"); @@ -64,12 +64,14 @@ steal('steal/test','steal/parse').then( function( s ) { var parser = steal.parse(readFile('steal/parse/test/dev.js')), tokens = []; - parser.until(["steal",".","dev",".","log","("]); + var tok = parser.until(["steal",".","dev",".","log","("]); parser.partner("(", function(token){ tokens.push(token); +// print("TOKEN = "+token.value, token.type) + }) - t.equals(tokens[0].value,"()"); + t.equals(tokens[0].value,"hi()"); }); diff --git a/parse/test/dev.js b/parse/test/dev.js new file mode 100644 index 000000000..c70266820 --- /dev/null +++ b/parse/test/dev.js @@ -0,0 +1,2 @@ +var foo; +steal.dev.log("hi()"); \ No newline at end of file diff --git a/parse/tokens.js b/parse/tokens.js index fa96189fa..a109f7ee7 100644 --- a/parse/tokens.js +++ b/parse/tokens.js @@ -48,7 +48,10 @@ String.prototype.tokens = function (prefix, suffix) { type: type, value: value, from: from, - to: i + to: i, + toString: function(){ + return "Type: "+type+", value: "+value+", from: "+from+", to: "+i; + } }; }; From dc958481aeefa0d634bd330d58429d3ce3b3f067 Mon Sep 17 00:00:00 2001 From: Brian Moschel Date: Thu, 22 Sep 2011 04:21:04 -0500 Subject: [PATCH 3/3] cleaning up messiness --- build/scripts/scripts.js | 4 ++-- build/test/run.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build/scripts/scripts.js b/build/scripts/scripts.js index 1730a6b5a..865a52452 100644 --- a/build/scripts/scripts.js +++ b/build/scripts/scripts.js @@ -119,8 +119,8 @@ steal('steal/build', 'steal/parse').then(function( steal ) { //save them new steal.File(options.to + p).save(loading+dependencyStr+compressed); var end = new Date(), - time = (end-start) - print(time+' MS') + time = (end-start); + steal.print(time+' MS') steal.print("SCRIPT BUNDLE > " + options.to + p); } } diff --git a/build/test/run.js b/build/test/run.js index 80f4b0ec8..96071cf7c 100644 --- a/build/test/run.js +++ b/build/test/run.js @@ -23,7 +23,6 @@ steal('steal/test/test.js', function( s ) { }); s.test.clear(); }) - return; s.test.test("less packages correctly", function(){ load('steal/rhino/rhino.js')