aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rennie2013-12-17 11:56:13 (EST)
committerGerrit Code Review @ Eclipse.org2013-12-17 15:15:31 (EST)
commitefeda9cf56118608612e255f0f48d08f4583acb2 (patch)
treec67da0e2a4c05cbcdbbdceac9109ffd2093b840c
parentfb57b4fa63d6fab03552b235e8a058aaf7a0a29c (diff)
downloadorg.eclipse.orion.client-efeda9cf56118608612e255f0f48d08f4583acb2.zip
org.eclipse.orion.client-efeda9cf56118608612e255f0f48d08f4583acb2.tar.gz
org.eclipse.orion.client-efeda9cf56118608612e255f0f48d08f4583acb2.tar.bz2
Bug 424202 - Improve naming of return statementsv20131217-2015refs/changes/13/19913/2
Change-Id: If218a8bb3efc7d1fc4558eff3a12776e488e6979 Signed-off-by: Mike Rennie <Michael_Rennie@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js8
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js12
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js184
3 files changed, 204 insertions, 0 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 964c374..bf1c409 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js
@@ -94,6 +94,14 @@ define([
}
}
}
+ else if(node.type === Estraverse.Syntax.ReturnStatement) {
+ if(node.argument) {
+ if(node.argument.type === Estraverse.Syntax.ObjectExpression ||
+ node.argument.type === Estraverse.Syntax.FunctionExpression) {
+ node.argument.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 94ed9cc..f6cdd94 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js
@@ -202,6 +202,14 @@ define([
}
}
}
+ else if(astnode.type === 'ReturnStatement') {
+ if(astnode.argument) {
+ if(astnode.argument.type === 'ObjectExpression' ||
+ astnode.argument.type === 'FunctionExpression') {
+ name = 'return {...}';
+ }
+ }
+ }
}
return name;
},
@@ -258,6 +266,10 @@ define([
range = astnode.key.range;
}
}
+ else if(astnode.type === 'ReturnStatement') {
+ range[0] = astnode.range[0];
+ range[1] = range[0] + 6;
+ }
else if(astnode.id && astnode.id.range) {
range = astnode.id.range;
}
diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
index 42b53a6..1330be6 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
@@ -196,6 +196,190 @@ define([
}
});
};
+
+ /**
+ * Tests an object property that is a literal wwhose value is a function
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
+ */
+ Tests.test_objproperty_literal1 = function() {
+ context.text = "var obj = {\n"+
+ "\t\"item\": function(p1, p2) {}\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "item(p1, p2)", 13, 19);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests an object property that is a literal whose value has not been set
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
+ */
+ Tests.test_objproperty_literal2 = function() {
+ context.text = "var obj = {\n"+
+ "\t\"item\": null\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "item", 13, 19);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests an object property that is a literal whose value is another object expression
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
+ */
+ Tests.test_objproperty_literal3 = function() {
+ context.text = "var obj = {\n"+
+ "\t\"item\": {}\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "item {...}", 13, 19);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests a return statement that is an object expression
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
+ */
+ Tests.test_returnobj1 = function() {
+ context.text = "function f1() {\n"+
+ "\t return {};\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "return {...}", 18, 24);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests a return statement that is an function expression
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
+ */
+ Tests.test_returnobj2 = function() {
+ context.text = "function f1() {\n"+
+ "\t return function() {};\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "return {...}", 18, 24);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests a return statement that is an object expression
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
+ */
+ Tests.test_returnobj3 = function() {
+ context.text = "function f1() {\n"+
+ "\t return {\n"+
+ "\t\tf1: function() {return {};}"+
+ "\t};"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one level one child outline element");
+ }
+ if(!outline[0].children[0].children || outline[0].children[0].children.length < 1) {
+ Assert.fail("There should be one level two child outline element");
+ }
+ if(!outline[0].children[0].children[0].children || outline[0].children[0].children[0].children.length < 1) {
+ Assert.fail("There should be one level three child outline element");
+ }
+ assertElement(outline[0].children[0].children[0].children[0], "return {...}", 45, 51);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests a return statement that is an object expression
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
+ */
+ Tests.test_returnobj4 = function() {
+ context.text = "function f1() {\n"+
+ "\t return {\n"+
+ "\t\tf1: function() {return function() {};}"+
+ "\t};"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one level one child outline element");
+ }
+ if(!outline[0].children[0].children || outline[0].children[0].children.length < 1) {
+ Assert.fail("There should be one level two child outline element");
+ }
+ if(!outline[0].children[0].children[0].children || outline[0].children[0].children[0].children.length < 1) {
+ Assert.fail("There should be one level three child outline element");
+ }
+ assertElement(outline[0].children[0].children[0].children[0], "return {...}", 45, 51);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
return Tests;
}); \ No newline at end of file