ternjs / tern

A JavaScript code analyzer for deep, cross-editor language support
https://ternjs.net/
MIT License
4.25k stars 378 forks source link

Router in express module burps "No Definition found" #469

Open ghost opened 9 years ago

ghost commented 9 years ago

i am using express module in my node application. here is the code flow from usage to the place where it is defined inside node_modules folder:::::

@app.js
var express = require('express')
var ro = express.Router()
//i call tern#go-todefinition from the 'Router' token in above line
//express module doesnt define main property in package.json, so entry point is index.js
//@node_modules/express/index.js
module.exports = require('./lib/express')

//@node_modules/express/lib/express.js
export.modules.Router = require('./router')

//@node_modules/express/lib/router/index.js
//returns Router function
var proto = module.exports = function(){
//Alt + . in Tern mode must come here...
}

Tern in this case is not working. But i can see, there are many module layers involved making it tough for tern to resolve. But where does the chain get broken here? If more inputs on why tern didn't work in this case can be given, it will help me to use Tern better.... thanks marinjh.

angelozerr commented 9 years ago

@madhavan020985 I don't know how to fix your problem, but if you wish to benefit with express completion with tern, I suggest you that you use https://github.com/angelozerr/tern-node-express

ghost commented 9 years ago

debugging the above issue, i noticed in "require('express').Router", Router is a MemberExpression (a parsed structure of the code) and it belongs to the object 'express'. now, the object 'express' gets its value as

var express = require('express')

Since this logic is node specific, i am not sure how ternjs handles the properties that percolates down from module files. However, during execution inside tern.js#findDef, 'expr.state.props.express' object has the keys,

types,forward,maxWeight,propertyOf,originNode,origin

and obviously, this is missing 'Router' property. this leads to the error 'No Definition found'.

i found out 'expr.state.props.express' object is built through acorn.js & node plugin. i am not able to figure out which block in nodejs plugin handles this however? any help, please?

marijnh commented 9 years ago

The properties you listed indicate that this is an infer.AVal object, so you should not expect Router to show up in there. The plugin Angelo linked appears to be a regular Tern plugin, so it should work with Emacs just fine.