tern icon indicating copy to clipboard operation
tern copied to clipboard

Find Refs with requirejs

Open navch opened this issue 8 years ago • 1 comments
trafficstars

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 avatar Nov 15 '17 18:11 navch

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.

navch avatar Nov 16 '17 06:11 navch