Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 424202
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/outliner.js (+8 lines)
Lines 94-99 Link Here
94
					}
94
					}
95
 				}
95
 				}
96
 			}
96
 			}
97
 			else if(node.type === Estraverse.Syntax.ReturnStatement) {
98
 				if(node.argument) {
99
 					if(node.argument.type === Estraverse.Syntax.ObjectExpression ||
100
 						node.argument.type === Estraverse.Syntax.FunctionExpression) {
101
 						node.argument.sig = Signatures.computeSignature(node);
102
 					}
103
 				}
104
 			}
97
		},
105
		},
98
		
106
		
99
		/**
107
		/**
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/signatures.js (+12 lines)
Lines 202-207 Link Here
202
						}
202
						}
203
					}
203
					}
204
				}
204
				}
205
				else if(astnode.type === 'ReturnStatement') {
206
					if(astnode.argument) {
207
						if(astnode.argument.type === 'ObjectExpression' ||
208
							astnode.argument.type === 'FunctionExpression') {
209
								name = 'return {...}';
210
						}
211
					}
212
				}
205
			}
213
			}
206
			return name;
214
			return name;
207
		},
215
		},
Lines 258-263 Link Here
258
						range = astnode.key.range;
266
						range = astnode.key.range;
259
					}
267
					}
260
				}
268
				}
269
				else if(astnode.type === 'ReturnStatement') {
270
					range[0] = astnode.range[0];
271
					range[1] = range[0] + 6;
272
				}
261
				else if(astnode.id && astnode.id.range) {
273
				else if(astnode.id && astnode.id.range) {
262
					range = astnode.id.range;
274
					range = astnode.id.range;
263
				}
275
				}
(-)a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js (+184 lines)
Lines 196-201 Link Here
196
			}
196
			}
197
		});
197
		});
198
	};
198
	};
199
	
200
	/**
201
	 * Tests an object property that is a literal wwhose value is a function
202
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
203
	 */
204
	Tests.test_objproperty_literal1 = function() {
205
		context.text = "var obj = {\n"+
206
			"\t\"item\": function(p1, p2) {}\n"+
207
			"};";
208
		return outliner.computeOutline(context).then(function(outline) {
209
			try {
210
				if(!outline || outline.length < 1) {
211
					Assert.fail("There should be one outline element");
212
				}
213
				if(!outline[0].children || outline[0].children.length < 1) {
214
					Assert.fail("There should be one child outline element");
215
				}
216
				assertElement(outline[0].children[0], "item(p1, p2)", 13, 19);
217
			}
218
			finally {
219
				tearDown();
220
			}
221
		});
222
	};
223
	
224
	/**
225
	 * Tests an object property that is a literal whose value has not been set
226
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
227
	 */
228
	Tests.test_objproperty_literal2 = function() {
229
		context.text = "var obj = {\n"+
230
			"\t\"item\": null\n"+
231
			"};";
232
		return outliner.computeOutline(context).then(function(outline) {
233
			try {
234
				if(!outline || outline.length < 1) {
235
					Assert.fail("There should be one outline element");
236
				}
237
				if(!outline[0].children || outline[0].children.length < 1) {
238
					Assert.fail("There should be one child outline element");
239
				}
240
				assertElement(outline[0].children[0], "item", 13, 19);
241
			}
242
			finally {
243
				tearDown();
244
			}
245
		});
246
	};
247
	
248
	/**
249
	 * Tests an object property that is a literal whose value is another object expression
250
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424149
251
	 */
252
	Tests.test_objproperty_literal3 = function() {
253
		context.text = "var obj = {\n"+
254
			"\t\"item\": {}\n"+
255
			"};";
256
		return outliner.computeOutline(context).then(function(outline) {
257
			try {
258
				if(!outline || outline.length < 1) {
259
					Assert.fail("There should be one outline element");
260
				}
261
				if(!outline[0].children || outline[0].children.length < 1) {
262
					Assert.fail("There should be one child outline element");
263
				}
264
				assertElement(outline[0].children[0], "item {...}", 13, 19);
265
			}
266
			finally {
267
				tearDown();
268
			}
269
		});
270
	};
271
	
272
	/**
273
	 * Tests a return statement that is an object expression
274
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
275
	 */
276
	Tests.test_returnobj1 = function() {
277
		context.text = "function f1() {\n"+
278
			"\t return {};\n"+
279
			"};";
280
		return outliner.computeOutline(context).then(function(outline) {
281
			try {
282
				if(!outline || outline.length < 1) {
283
					Assert.fail("There should be one outline element");
284
				}
285
				if(!outline[0].children || outline[0].children.length < 1) {
286
					Assert.fail("There should be one child outline element");
287
				}
288
				assertElement(outline[0].children[0], "return {...}", 18, 24);
289
			}
290
			finally {
291
				tearDown();
292
			}
293
		});
294
	};
295
	
296
	/**
297
	 * Tests a return statement that is an function expression
298
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
299
	 */
300
	Tests.test_returnobj2 = function() {
301
		context.text = "function f1() {\n"+
302
			"\t return function() {};\n"+
303
			"};";
304
		return outliner.computeOutline(context).then(function(outline) {
305
			try {
306
				if(!outline || outline.length < 1) {
307
					Assert.fail("There should be one outline element");
308
				}
309
				if(!outline[0].children || outline[0].children.length < 1) {
310
					Assert.fail("There should be one child outline element");
311
				}
312
				assertElement(outline[0].children[0], "return {...}", 18, 24);
313
			}
314
			finally {
315
				tearDown();
316
			}
317
		});
318
	};
319
	
320
	/**
321
	 * Tests a return statement that is an object expression
322
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
323
	 */
324
	Tests.test_returnobj3 = function() {
325
		context.text = "function f1() {\n"+
326
			"\t return {\n"+
327
			"\t\tf1: function() {return {};}"+
328
			"\t};"+
329
			"};";
330
		return outliner.computeOutline(context).then(function(outline) {
331
			try {
332
				if(!outline || outline.length < 1) {
333
					Assert.fail("There should be one outline element");
334
				}
335
				if(!outline[0].children || outline[0].children.length < 1) {
336
					Assert.fail("There should be one level one child outline element");
337
				}
338
				if(!outline[0].children[0].children || outline[0].children[0].children.length < 1) {
339
					Assert.fail("There should be one level two child outline element");
340
				}
341
				if(!outline[0].children[0].children[0].children || outline[0].children[0].children[0].children.length < 1) {
342
					Assert.fail("There should be one level three child outline element");
343
				}
344
				assertElement(outline[0].children[0].children[0].children[0], "return {...}", 45, 51);
345
			}
346
			finally {
347
				tearDown();
348
			}
349
		});
350
	};
351
	
352
	/**
353
	 * Tests a return statement that is an object expression
354
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=424202
355
	 */
356
	Tests.test_returnobj4 = function() {
357
		context.text = "function f1() {\n"+
358
			"\t return {\n"+
359
			"\t\tf1: function() {return function() {};}"+
360
			"\t};"+
361
			"};";
362
		return outliner.computeOutline(context).then(function(outline) {
363
			try {
364
				if(!outline || outline.length < 1) {
365
					Assert.fail("There should be one outline element");
366
				}
367
				if(!outline[0].children || outline[0].children.length < 1) {
368
					Assert.fail("There should be one level one child outline element");
369
				}
370
				if(!outline[0].children[0].children || outline[0].children[0].children.length < 1) {
371
					Assert.fail("There should be one level two child outline element");
372
				}
373
				if(!outline[0].children[0].children[0].children || outline[0].children[0].children[0].children.length < 1) {
374
					Assert.fail("There should be one level three child outline element");
375
				}
376
				assertElement(outline[0].children[0].children[0].children[0], "return {...}", 45, 51);
377
			}
378
			finally {
379
				tearDown();
380
			}
381
		});
382
	};
199
		
383
		
200
	return Tests;
384
	return Tests;
201
});
385
});

Return to bug 424202