This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 243140 - Navigator doesnt show keys (properties, functions, ...) inside a anonymous object.
Summary: Navigator doesnt show keys (properties, functions, ...) inside a anonymous ob...
Status: REOPENED
Alias: None
Product: javascript
Classification: Unclassified
Component: Navigation (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-21 11:31 UTC by Christian Lenz
Modified: 2016-09-16 11:51 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Not working (3.84 KB, image/png)
2014-03-21 11:31 UTC, Christian Lenz
Details
Working.png (9.21 KB, image/png)
2014-03-21 11:32 UTC, Christian Lenz
Details
idea.png (85.70 KB, image/png)
2014-03-21 11:32 UTC, Christian Lenz
Details
IntelliJ2 (63.01 KB, image/png)
2014-06-13 07:06 UTC, Christian Lenz
Details
IntelliJ foo bar right example (13.67 KB, image/png)
2014-08-05 15:02 UTC, Christian Lenz
Details
gruntfile structure idea 14 (106.29 KB, image/png)
2015-08-20 07:14 UTC, Christian Lenz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Lenz 2014-03-21 11:31:50 UTC
Created attachment 146218 [details]
Not working

As you can see here: http://pastebin.com/kQW0qDYC I use a shorter version and give the method inherit an anonymous object. This breaks the navigator for this object (See Attachment not working.png). When I use this code: http://pastebin.com/0TChxnhy all is fine (See Attachment working.png). Is it a bug or a missing behavior? It should be possible, because there are no problem with IntelliJ IDEA for this (See Attachment idea.png).


Regards

Chirs
Comment 1 Christian Lenz 2014-03-21 11:32:11 UTC
Created attachment 146219 [details]
Working.png
Comment 2 Christian Lenz 2014-03-21 11:32:33 UTC
Created attachment 146220 [details]
idea.png
Comment 3 Christian Lenz 2014-06-13 07:05:47 UTC
An other test happens with this code:

var myModule = function()
{
    return {
        foo: function()
        {
            console.log("foo");
        },
        bar: "bar"
    };
};

navigator only shows: myModule(): type. In intelliJ it can resolve the structure and shows me what you can see in intelliJ2.png
Comment 4 Christian Lenz 2014-06-13 07:06:10 UTC
Created attachment 147661 [details]
IntelliJ2
Comment 5 Christian Lenz 2014-06-13 07:06:59 UTC
And as you can see all other available functions and properties, which are supported in ES5.
Comment 6 Petr Pisl 2014-08-05 13:50:32 UTC
IMHO what you write about the simple example is wrong (it doesn't correspond to the runtime). In your example 

var myModule = function()
{
    return {
        foo: function()
        {
            console.log("foo");
        },
        bar: "bar"
    };
};

myModule is really a function. You can not write myModule.foo() or myModyle.bar.

If you write

yourModule = myModule(), 

then it's ok and NetBeans offers after the yourModule function foo() and property bar. 

If the case would be

var myModule = (function()
{
    return {
        foo: function()
        {
            console.log("foo");
        },
        bar: "bar"
    };
})();

then probably the navigator should display the property.
Comment 7 Christian Lenz 2014-08-05 15:02:05 UTC
Ok I understand it, but why is it possible that intelliJ can show me those properties?

The other thing is that your example is valid, thx for that, I figured it out sry for that :/. 

With my old example:

var fooBar = function()
{
    return {
        foo: function()
        {
            console.log("foo");
        },
        bar: "bar"
    };
};

navigator shows me fooBar();

With the new example:

var fooBar = (function()
{
    return {
        foo: function()
        {
            console.log("foo");
        },
        bar: "bar"
    };
})();

navigator shows me fooBar: Function, but nothing more. No properties.

And for the first example, when I write fooBar().bar, I can't navigate to bar, when I write your example var test = fooBar(); test.bar, I can.

It's only that I can navigate and the navigator should show me the same or similar as intelliJ structure windows shows.


If I open the same examples inside intelliJ, for the first it shows me that, what you see on the intelliJ2 screen and I can already navigate to bar. If I refactor the code to the right example, than it shows me what you can see in the screenshot intelliJFooBar.png


Regards

Chris
Comment 8 Christian Lenz 2014-08-05 15:02:45 UTC
Created attachment 148564 [details]
IntelliJ foo bar right example
Comment 9 Petr Pisl 2014-08-06 11:11:59 UTC
>Ok I understand it, but why is it possible that intelliJ can show me 
>those properties?

From my point of view, it's wrong. I can implemented in NB as well, but I think that this is not right. 

>navigator shows me fooBar: Function, but nothing more. No properties.

I'm going to fix it. At least try:)

>And for the first example, when I write fooBar().bar, 
>I can't navigate to bar, when I write your example var test = fooBar();
>test.bar, I can.

This is a problem in resolving types (my guess). I have created new issue # 246299 to track this.

Thanks
Comment 10 Christian Lenz 2014-08-07 06:53:26 UTC
Ok, sounds good :). I think you are right, an IDE should avoid you from create wrong code (a bit for my perspective). So I think it is good to not implement the wrong version.

Thx for the feedback.

Can you have a look at this ticket too please? This is a real world project, which I have to use for my daily work. https://netbeans.org/bugzilla/show_bug.cgi?id=246268


Regards

Chris
Comment 11 Petr Pisl 2014-08-08 07:58:20 UTC
At the end I implemented both cases in web-main. Unfortunately it will not be a part of NB 8.0.1, so you have to use a devbuild.

Regarding issue #246268, it will be probably more complicated. I'm going to look at this more.
Comment 12 Christian Lenz 2014-08-08 08:28:26 UTC
Big thx to you, for your work. I will test it asap after it is deployed :).
Yeah the other ticket is more compilcated, because all JS navigation support and resolving properties and so on, shouldn't be framework dependent. If the framework is correct and working, it should do the same as plain js code.
Comment 13 Quality Engineering 2014-08-09 05:02:40 UTC
Integrated into 'main-silver', will be available in build *201408090001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/6c4a5dcecd7e
User: Petr Pisl <ppisl@netbeans.org>
Log: #243140 - Navigator doesnt show keys (properties, functions, ...) inside a anonymous object.
Comment 14 Christian Lenz 2015-07-13 14:19:59 UTC
The problem with this example: http://pastebin.com/kQW0qDYC still exists in the latest nightly 201507130001.
Comment 15 Christian Lenz 2015-08-20 07:14:00 UTC
Created attachment 155483 [details]
gruntfile structure idea 14

As you can see in my screenshot (gruntfile structure idea 14) from idea 14, it shows you all properties inside the anonymous object in a gruntfile. Netbeans 8.1 beta doesn't show it.
Comment 16 Christian Lenz 2016-09-16 11:49:49 UTC
The bug still exists in 8.2 RC. This is my JS object:

var list = function() {
   return {
      restrict: 'E',
      controller: function($scope) {
         var vm = this;
         console.log($scope);

         vm.modes = listModes;
      },
      controllerAs: 'listVm',
      templateUrl: 'list.tpl.html',
      replace: true,
      bindToController: true
   };
};

and the navigator only shows: list(). Nothing more. WebStorm will show you all properties inside the anonymous object in the return statement, the same I expect for NB.
Comment 17 Christian Lenz 2016-09-16 11:51:34 UTC
This list method is a directive which will be used in an angular module:

angular.module('myModule', []).directive('list', list);