Skip to content
Browse files

Attempt to locate define or require call even if its buried in a cond…

…itional expression when using esprima for the AST parser. Also change zazlnodejs to use esprima instead of uglifyjs for AST parsing
  • Loading branch information...
1 parent d195c73 commit 8d20110e20b1e61f826f7d19434cf1587e780b23 @rbackhouse rbackhouse committed Oct 28, 2012
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.4.3
+Bundle-Version: 0.4.6
View
17 org.dojotoolkit.optimizer.amd/optimizer/amd/astwalker.js
@@ -190,7 +190,7 @@ function getDependencies(src, expression, scanCJSRequires) {
var args = expression.arguments;
for (var j = 0; j < args.length; j++) {
if (j === 0 && args[j].type !== "Literal") {
- nameIndex = expression.callee.range[0] + (src.substring(expression.callee.range[0]).indexOf('(')+1);
+ nameIndex = args[j].range[0];
}
if (args[j].type === "ArrayExpression" && expression.callee.name === "define") {
var elements = args[j].elements;
@@ -216,8 +216,16 @@ function findDefine(ast) {
for (var p in ast) {
if (p === "type" && ast[p] === "ExpressionStatement") {
var expression = ast["expression"];
- if (expression.type === "CallExpression" && expression.callee.name === "define") {
- return expression;
+ if (expression.type === "CallExpression") {
+ if (expression.callee.name === "define") {
+ return expression;
+ } else if (expression.callee.type === "ConditionalExpression") {
+ left = {type : expression.callee.consequent.type, name : expression.callee.consequent.name === undefined ? "" : expression.callee.consequent.name};
+ right = {type : expression.callee.alternate.type, name : expression.callee.alternate.name === undefined ? "" : expression.callee.alternate.name};
+ if ((left.type === "Identifier" && left.name === "defined") || (right.type === "Identifier" && right.name === "define")) {
+ return {arguments: expression.arguments, callee: {name: "define"}};
+ }
+ }
}
} else {
if (isArray(ast[p])) {
@@ -431,6 +439,9 @@ function uglifyjsWalker(uri, exclude, moduleMap, pluginRefList, missingNamesList
moduleMap.add(uri, module);
w.with_walkers({
"call": function(expr, args) {
+ if (expr[0] == "conditional") {
+ print(expr[1]+" : "+expr[2]+" : "+expr[3]+" : "+JSON.stringify(w.parent()[1][2][0], null, " "));
+ }
if (expr[0] === "name" && (expr[1] === "define" || expr[1] === "require")) {
var dependencyArg;
if (expr[1] === "define" && args[0][0].name !== "string") {
View
2 org.dojotoolkit.optimizer.servlet/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Dojo Toolkit Optimizer Servlet
Bundle-SymbolicName: org.dojotoolkit.optimizer.servlet
-Bundle-Version: 0.3.2
+Bundle-Version: 0.4.6
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.servlet,
javax.servlet.http,
View
3 org.dojotoolkit.optimizer.servlet/zazl.json
@@ -24,7 +24,8 @@
"defval": "dojox/gfx/svg"
}
},
- "i18nPluginId" : "dojo/i18n"
+ "i18nPluginId" : "dojo/i18n",
+ "astparser": "uglifyjs"
},
"type" : "amd",
"astCache" : false
View
3 org.dojotoolkit.optimizer.servlet/zazlUsingESPrima.json
@@ -27,5 +27,6 @@
"i18nPluginId" : "dojo/i18n",
"astparser": "esprima"
},
- "type" : "amd"
+ "type" : "amd",
+ "astCache" : false
}

0 comments on commit 8d20110

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