Skip to content

Commit

Permalink
Version 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rbackhouse committed Jul 11, 2012
1 parent dc31e8c commit 729bf78
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Rhinoast
Bundle-SymbolicName: org.dojotoolkit.optimizer.amd.rhinoast
Bundle-Version: 0.3.3
Bundle-Version: 0.3.6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.dojotoolkit.optimizer
Import-Package: org.dojotoolkit.json,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[]
cfg.put(key, fullConfig.get(key));
}
}
boolean scanCJSRequires = cfg.get("scanCJSRequires") == null ? false : (Boolean)cfg.get("scanCJSRequires");

StringWriter sw = new StringWriter();
String pageConfigString = "";
try {
Expand Down Expand Up @@ -137,7 +139,7 @@ protected JSAnalysisDataImpl _getAnalysisData(String[] modules, JSAnalysisData[]

for (String moduleId : modules) {
logger.logp(Level.INFO, getClass().getName(), "_getAnalysisData", "AST parsing ["+moduleId+"] using the Rhino AST API");
AstVisitor visitor = new AstVisitor(moduleId, moduleMap, pluginRefs, missingNamesList, cfg, new Stack<String>(), excludeList, pageConfigString);
AstVisitor visitor = new AstVisitor(moduleId, moduleMap, pluginRefs, missingNamesList, cfg, new Stack<String>(), excludeList, pageConfigString, scanCJSRequires);
if (visitor.getError() != null) {
logger.logp(Level.INFO, getClass().getName(), "_getAnalysisData", "AST parsing error for ["+moduleId+"] error : "+visitor.getError());
throw new IOException("AST parsing error for ["+moduleId+"] error : "+visitor.getError());
Expand Down Expand Up @@ -310,6 +312,7 @@ private class AstVisitor implements NodeVisitor {
private String baseUrl = null;
private String pageConfigString = null;
private String error = null;
private boolean scanCJSRequires = false;

public AstVisitor(String moduleId,
Map<String, Module> moduleMap,
Expand All @@ -318,7 +321,8 @@ public AstVisitor(String moduleId,
Map<String, Object> config,
Stack<String> pathStack,
List<String> excludeList,
String pageConfigString) {
String pageConfigString,
boolean scanCJSRequires) {

if (moduleId.equals("require") || moduleId.equals("exports") || moduleId.equals("module")) {
moduleMap.put(moduleId, new Module(moduleId, moduleId));
Expand All @@ -333,6 +337,7 @@ public AstVisitor(String moduleId,
this.pathStack = pathStack;
this.excludeList = excludeList;
this.pageConfigString = pageConfigString;
this.scanCJSRequires = scanCJSRequires;

this.baseUrl = (String)config.get("baseUrl");

Expand Down Expand Up @@ -362,7 +367,7 @@ public AstVisitor(String moduleId,
if (addDep) {
Stack<String> s = new Stack<String>();
s.push(this.moduleId);
AstVisitor visitor = new AstVisitor(pluginDep, moduleMap, pluginRefList, missingNamesList, config, s, excludeList, pageConfigString);
AstVisitor visitor = new AstVisitor(pluginDep, moduleMap, pluginRefList, missingNamesList, config, s, excludeList, pageConfigString, scanCJSRequires);
if (visitor.getError() != null) {
error = visitor.getError();
return;
Expand Down Expand Up @@ -427,7 +432,10 @@ public boolean visit(AstNode astNode) {
}
List<String> dependencies = new ArrayList<String>();
if (callName.equals("require") && args.get(0) instanceof StringLiteral) {
dependencies.add(((StringLiteral)args.get(0)).getValue());
if (scanCJSRequires) {
System.out.println("require:"+((StringLiteral)args.get(0)).getValue());
dependencies.add(((StringLiteral)args.get(0)).getValue());
}
} else if (args.get(0) instanceof StringLiteral && args.get(1) instanceof ArrayLiteral) {
ArrayLiteral al = (ArrayLiteral) args.get(1);
for (AstNode dependency : al.getElements()) {
Expand Down Expand Up @@ -473,7 +481,7 @@ public boolean visit(AstNode astNode) {
}
if (addDep) {
module.dependencies.add(pluginDep);
AstVisitor visitor = new AstVisitor(pluginDep, moduleMap, pluginRefList, missingNamesList, config, pathStack, excludeList, pageConfigString);
AstVisitor visitor = new AstVisitor(pluginDep, moduleMap, pluginRefList, missingNamesList, config, pathStack, excludeList, pageConfigString, scanCJSRequires);
if (visitor.getError() != null) {
error = visitor.getError();
return false;
Expand Down Expand Up @@ -506,7 +514,7 @@ public boolean visit(AstNode astNode) {
}
if (addDep) {
module.dependencies.add(dependencyId);
AstVisitor visitor = new AstVisitor(dependencyId, moduleMap, pluginRefList, missingNamesList, config, pathStack, excludeList, pageConfigString);
AstVisitor visitor = new AstVisitor(dependencyId, moduleMap, pluginRefList, missingNamesList, config, pathStack, excludeList, pageConfigString, scanCJSRequires);
if (visitor.getError() != null) {
error = visitor.getError();
return false;
Expand Down
2 changes: 1 addition & 1 deletion org.dojotoolkit.optimizer.amd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AMD Optimizer
Bundle-SymbolicName: org.dojotoolkit.optimizer.amd;singleton:=true
Bundle-Version: 0.3.5
Bundle-Version: 0.3.6
12 changes: 9 additions & 3 deletions org.dojotoolkit.optimizer.amd/loader/amd/zazl.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,12 @@ var define;
}
modules[id] = {id: id, exports: {}, args: args, deploaded: {}, dependencies: dependencies};
if (isFunction(factory)) {
factory.toString().replace(commentRegExp, "").replace(cjsRequireRegExp, function (match, dep) {
modules[id].dependencies.push("~#"+dep);
});
var scancjs = cfg ? cfg.scanCJSRequires : false;
if (scancjs) {
factory.toString().replace(commentRegExp, "").replace(cjsRequireRegExp, function (match, dep) {
modules[id].dependencies.push("~#"+dep);
});
}
modules[id].factory = factory;
} else {
modules[id].literal = factory;
Expand Down Expand Up @@ -485,6 +488,8 @@ var define;
}

cfg.injectUrl = cfg.injectUrl || "_javascript";
cfg.scanCJSRequires = cfg.scanCJSRequires || false;
cfg.debug = cfg.debug || false;
}
};

Expand Down Expand Up @@ -651,6 +656,7 @@ var define;
cbiterate(modules[mid].exports, new Iterator(cblist[mid]));
}
}
if (cfg.debug) {console.log("Page load complete");}
pageLoaded = true;
for (var i = 0; i < readyCallbacks.length; i++) {
readyCallbacks[i]();
Expand Down
1 change: 1 addition & 0 deletions org.dojotoolkit.optimizer.amd/optimizer/amd/AMDAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ AMDAnalyzer = function(cfg) {
this.config[p] = cfg[p];
}
}
this.config.scanCJSRequires = cfg.scanCJSRequires || false;
}
};

Expand Down
16 changes: 9 additions & 7 deletions org.dojotoolkit.optimizer.amd/optimizer/amd/astwalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function scanForRequires(ast, requires) {
}
};

function getDependencies(src, expression) {
function getDependencies(src, expression, scanCJSRequires) {
var dependencies = [];
var nameIndex;

Expand All @@ -156,10 +156,12 @@ function getDependencies(src, expression) {
dependencies.push({value: elements[k].value, type: elements[k].type});
}
} else if (args[j].type === "FunctionExpression" && expression.callee.name === "define") {
var requires = [];
scanForRequires(args[j].body, requires);
for (var x = 0; x < requires.length; x++) {
dependencies.push({value: requires[x], type: "Literal"});
if (scanCJSRequires) {
var requires = [];
scanForRequires(args[j].body, requires);
for (var x = 0; x < requires.length; x++) {
dependencies.push({value: requires[x], type: "Literal"});
}
}
}
}
Expand Down Expand Up @@ -251,7 +253,7 @@ function esprimaWalker(uri, exclude, moduleMap, pluginRefList, missingNamesList,
var id = uri;
var module = moduleCreator.createModule(id, url);
moduleMap.add(uri, module);
var depInfo = getDependencies(src, defineExpr);
var depInfo = getDependencies(src, defineExpr, config.scanCJSRequires);
if (depInfo.nameIndex) {
missingNamesList.push({uri: url, id: id, nameIndex: depInfo.nameIndex});
}
Expand Down Expand Up @@ -395,7 +397,7 @@ function uglifyjsWalker(uri, exclude, moduleMap, pluginRefList, missingNamesList
missingNamesList.push({uri: url, id: id, nameIndex: nameIndex});
}
if (expr[1] === "require") {
if (args[0][0].name === "string") {
if (args[0][0].name === "string" && config.scanCJSRequires) {
dependencyArg = [args[0][1]];
} else {
dependencyArg = undefined;
Expand Down

0 comments on commit 729bf78

Please sign in to comment.