Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find Refs with requirejs #950

Open
navch opened this issue Nov 15, 2017 · 1 comment
Open

Find Refs with requirejs #950

navch opened this issue Nov 15, 2017 · 1 comment

Comments

@navch
Copy link

navch commented Nov 15, 2017

I am trying to find all references of a symbol.
For Example-
file1.js -

define(function (require, exports, module) {
    "use strict";
     **var some = require("some");**
    function doSome() {
      //do something
    }
    exports.doSome             = doSome;
});

file2.js -

define(function (require, exports, module) {
    "use strict";
    var file1 = require("file1");
	file1.doSome();
});

So when I find refs of "doSome" from file2.js It will give me refs of this file only.

But if I remove/comment third line from file1.js then it will return correct references.

So its seems like there is something wrong with requirejs. I am passing this plugin value plugins: {requirejs: {}, doc_comment: true, angular: true}
I tried to pass baseUrl as well. But its still not working.

I tried to debug tern code, So I am providing some more info. Hope that may help in investigating this issue.

In infer.js

    function isObjTypeProto(type) {
      // Check whether the found type has objType in its hierarchy
      while (type && type != objType) {
        // Ff property is overriden higher in the hierarchy, return false

        if (type.props[name] || (type.maybeProps && type.maybeProps[name])) {
          return false;
        }
        type = type.proto;
      }
      return type;
    }

Here the value of type is different in both cases.
With require statementin file1, value of type is -
maybeProps: null
name: undefined
origin: "file1.js"
props: Object
proto: undefined

objType value is -
maybeProps: null
name: "exports"
origin: "TestingFileForRefs.js"
props: Object
proto: Object

If we remove that require statement from file1 then type and objType are same.

Please help me to find out whats going wrong ?

@navch
Copy link
Author

navch commented Nov 16, 2017

I have same issue In case of below example

define(function (require, exports, module) {
    "use strict";
     **var SomeManager = require("SomeManager");**
    function doSome() {
      //do something
    }
    doSome();
    SomeManager.on("someEvent", doSome);
});

In this case when I do findRefs this return only last 2 references. But If i remove 3rd line then It will return all three refs.
Note :- This work fine in tern demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant