aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2013-11-27 11:45:01 (EST)
committerMike Rennie2013-11-27 11:45:01 (EST)
commit03a03dff7c3bd4dfbe4aa51bb0938fe7459bc88c (patch)
treeb69752fb1029621ccea03356759a1ce83115e597
parent18e38939013ab1d99f0b79b440750a92374ae622 (diff)
downloadorg.eclipse.orion.client-03a03dff7c3bd4dfbe4aa51bb0938fe7459bc88c.zip
org.eclipse.orion.client-03a03dff7c3bd4dfbe4aa51bb0938fe7459bc88c.tar.gz
org.eclipse.orion.client-03a03dff7c3bd4dfbe4aa51bb0938fe7459bc88c.tar.bz2
Bug 422495 - Improve outlining of object and function assignmentsv20131127-1645refs/changes/86/18986/1
Change-Id: Id7659dc14ee95a3b3d5831d6e0f6786e3f48ed6e Signed-off-by: Mike Rennie <Michael_Rennie@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js7
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js76
2 files changed, 81 insertions, 2 deletions
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
index 542cf07..d0a8265 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
@@ -85,6 +85,13 @@ define([
});
}
}
+ else if(node.type === 'AssignmentExpression') {
+ if(node.left && node.right) {
+ if(node.right.type === 'ObjectExpression' || node.right.type === 'FunctionExpression') {
+ node.right.sig = Signatures.computeSignature(node);
+ }
+ }
+ }
},
/**
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js
index 4f7764f..0b3ac56 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js
@@ -142,13 +142,80 @@ define([
name = 'var '+astnode.id.name+ ' = {...}';
}
}
- else if(astnode.init.type === 'FunctionDeclaration') {
+ else if(astnode.init.type === 'FunctionExpression') {
if(astnode.id && astnode.id.name) {
+ name = astnode.id.name + '(';
+ var vparams = this.getParamsFrom(astnode.init);
+ if(vparams) {
+ name += vparams;
+ }
+ name += ')';
+ }
+ else {
name = this.getNameFrom(astnode.init);
}
}
}
}
+ else if(astnode.type === 'AssignmentExpression') {
+ if(astnode.left && astnode.right) {
+ var isobject = astnode.right.type === 'ObjectExpression';
+ if(isobject || astnode.right.type === 'FunctionExpression') {
+ if(astnode.left.name) {
+ name = astnode.left.name;
+ }
+ else if(astnode.left.type === 'MemberExpression') {
+ name = this.expandMemberExpression(astnode.left, '');
+ }
+ if(name) {
+ //append the right stuff
+ if(isobject) {
+ name += ' {...}';
+ }
+ else {
+ name += '(';
+ var aparams = this.getParamsFrom(astnode.right);
+ if(aparams) {
+ name += aparams;
+ }
+ name += ')';
+ }
+ }
+ else {
+ name = this.getNameFrom(astnode.right);
+ }
+ }
+ }
+ }
+ }
+ return name;
+ },
+
+ /**
+ * @name expandMemberExpression
+ * @description Given a MemberExpression node this function will recursively compute the complete name from the node
+ * by visiting all of the child MemberExpressions, if any
+ * @function
+ * @private
+ * @memberof javascript.Signatures.prototype
+ * @param {Object} astnode The MemberExpression AST node
+ * @returns {String} The name to use for the node
+ */
+ expandMemberExpression: function(astnode, name) {
+ if(astnode.type === 'MemberExpression') {
+ if(astnode.property && astnode.property.name) {
+ if(name && name.length > 0) {
+ name = astnode.property.name+'.' + name;
+ }
+ else {
+ name = astnode.property.name;
+ }
+ }
+ if(astnode.object && astnode.object.name) {
+ name = astnode.object.name +'.'+ name;
+ }
+ //TODO recursion
+ return this.expandMemberExpression(astnode.object, name);
}
return name;
},
@@ -166,7 +233,12 @@ define([
getSignatureSourceRangeFrom: function(astnode) {
var range = [0, 0];
if(astnode) {
- if(astnode.type === 'Property') {
+ if(astnode.type === 'AssignmentExpression') {
+ if(astnode.left && astnode.left.range) {
+ range = astnode.left.range;
+ }
+ }
+ else if(astnode.type === 'Property') {
if(astnode.key && astnode.key.range) {
range = astnode.key.range;
}