Skip to content

Commit

Permalink
Merge branch 'master' of github:jupiterjs/steal
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmoschel committed Sep 23, 2011
2 parents efe1de2 + dc95848 commit 0f66d77
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 22 deletions.
31 changes: 26 additions & 5 deletions build/scripts/scripts.js
@@ -1,4 +1,4 @@
steal('steal/build').then(function( steal ) {
steal('steal/build', 'steal/parse').then(function( steal ) {

/**
* Builds JavaScripts
Expand All @@ -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"](),
Expand All @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -118,14 +118,35 @@ 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);
steal.print(time+' MS')
steal.print("SCRIPT BUNDLE > " + options.to + p);
}
}
});

// 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
Expand Down
6 changes: 6 additions & 0 deletions 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;
}
};
6 changes: 6 additions & 0 deletions 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;
}
};
17 changes: 17 additions & 0 deletions build/test/run.js
Expand Up @@ -7,6 +7,23 @@ 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();
})

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){
Expand Down
33 changes: 23 additions & 10 deletions generate/generate.js
Expand Up @@ -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 +"')"
}
Expand Down
3 changes: 1 addition & 2 deletions parse/parse.js
Expand Up @@ -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];
Expand Down
10 changes: 6 additions & 4 deletions parse/parse_test.js
Expand Up @@ -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");
Expand All @@ -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()");

});

Expand Down
2 changes: 2 additions & 0 deletions parse/test/dev.js
@@ -0,0 +1,2 @@
var foo;
steal.dev.log("hi()");
5 changes: 4 additions & 1 deletion parse/tokens.js
Expand Up @@ -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;
}
};

};
Expand Down

0 comments on commit 0f66d77

Please sign in to comment.