Skip to content
Browse files

Version 0.3.6

  • Loading branch information...
1 parent dc31e8c commit 729bf78bc9d05dbb6d216bb8ce6e1a7575f58e6a @rbackhouse rbackhouse committed Jul 11, 2012
View
2 org.dojotoolkit.optimizer.amd.rhinoast/META-INF/MANIFEST.MF
@@ -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,
View
BIN ...mizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$AstVisitor.class
Binary file not shown.
View
BIN ...optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer$Module.class
Binary file not shown.
View
BIN ...oolkit.optimizer.amd.rhinoast/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.class
Binary file not shown.
View
20 ...kit.optimizer.amd.rhinoast/src/org/dojotoolkit/optimizer/amd/rhinoast/AMDJSOptimizer.java
@@ -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 {
@@ -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());
@@ -310,6 +312,7 @@ private void scanForCircularDependencies(Module module, Stack<String> check, Map
private String baseUrl = null;
private String pageConfigString = null;
private String error = null;
+ private boolean scanCJSRequires = false;
public AstVisitor(String moduleId,
Map<String, Module> moduleMap,
@@ -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));
@@ -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");
@@ -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;
@@ -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()) {
@@ -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;
@@ -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;
View
2 org.dojotoolkit.optimizer.amd/META-INF/MANIFEST.MF
@@ -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
View
12 org.dojotoolkit.optimizer.amd/loader/amd/zazl.js
@@ -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;
@@ -485,6 +488,8 @@ var define;
}
cfg.injectUrl = cfg.injectUrl || "_javascript";
+ cfg.scanCJSRequires = cfg.scanCJSRequires || false;
+ cfg.debug = cfg.debug || false;
}
};
@@ -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]();
View
1 org.dojotoolkit.optimizer.amd/optimizer/amd/AMDAnalyzer.js
@@ -37,6 +37,7 @@ AMDAnalyzer = function(cfg) {
this.config[p] = cfg[p];
}
}
+ this.config.scanCJSRequires = cfg.scanCJSRequires || false;
}
};
View
16 org.dojotoolkit.optimizer.amd/optimizer/amd/astwalker.js
@@ -141,7 +141,7 @@ function scanForRequires(ast, requires) {
}
};
-function getDependencies(src, expression) {
+function getDependencies(src, expression, scanCJSRequires) {
var dependencies = [];
var nameIndex;
@@ -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"});
+ }
}
}
}
@@ -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});
}
@@ -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;

0 comments on commit 729bf78

Please sign in to comment.
Something went wrong with that request. Please try again.