google / tern-closure

A Tern plugin adding Closure support.
Apache License 2.0
33 stars 18 forks source link

tern-closure and atom-tern #42

Open lucasvw opened 9 years ago

lucasvw commented 9 years ago

So I tried to setup tern-closure in atom on top of the atom-tern.

Since there is no package available I npm install tern-closure in ~/.atom/packages/atom-ternjs/node-modules/tern/ This installs the tern-closure into ~/.atom/packages/atom-ternjs/node-modules/tern/node-modules/tern-closure

My tern-project looks like this:

{ "ecmaVersion": 6, "libs": [ "browser", "jquery" ], "loadEagerly": [ "./src/vcs/vcm/*/.js" ], "plugins": { "complete_strings": {}, "node": {}, "lint": {}, "angular": {}, "requirejs": {}, "es_modules": {}, "doc_comment": false, "closure" : {} } }

However, immediately the errors are thrown:

atom-ternjs C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:292 return node.right.body.scope.fnType; ^

TypeError: Cannot read property 'fnType' of undefined at getFnType (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:292:33) at interpretComments (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:216:18) at walk.simple.AssignmentExpression (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:172:7) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:30:18) at Object.skipThrough (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\acorn\dist\walk.js:168:3) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:29:17) at Object.base.ExpressionStatement.base.ParenthesizedExpression (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\acorn\dist\walk.js:185:10) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:29:17) at Object.exports.searchVisitor.walk.make.Statement (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\lib\infer.js:1929:7) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:29:17)

AND

tern exited with code: 1. Restart the server via Packages -> Atom Ternjs -> Restart server

Any ideas?

angelozerr commented 9 years ago

I think it's same problem than https://github.com/google/tern-closure/issues/37#issuecomment-147779864

lucasvw commented 9 years ago

Hi and thanks for your answer.

So as I understood it the current version of tern: 0.15.1 is not yet supported by tern-closure. So I went to .atom/packages/atom-ternjs/node_modules and deleted tern from there. Next I npm install tern@0.13.0 in that directory. However, tern-lint requires: ^0.15.0 So I set this manually to 0.13.0 as well.

This still results in the following error:

atom-ternjs C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\lib\infer.js:307 this.construct.apply(this, arguments); ^

TypeError: Cannot read property 'apply' of undefined at Object.ctor (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\lib\infer.js:307:21) at applyFnTypeInfo (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:266:33) at interpretComments (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:234:5) at walk.simple.AssignmentExpression (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\closure.js:172:7) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:30:18) at Object.skipThrough (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\acorn\dist\walk.js:168:3) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:29:17) at Object.base.ExpressionStatement.base.ParenthesizedExpression (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\acorn\dist\walk.js:185:10) at c (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\node_modules\acorn\util\walk.js:29:17) at Object.skipThrough (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\acorn\dist\walk.js:168:3)

Any ideas?

jpsmith1981 commented 9 years ago

I am having similar issues.

bfricka commented 9 years ago

I submitted a PR for this fix. Please try using that version and see if it fixes your issue.

Hopefully this will fix these issues and get merged.

jpsmith1981 commented 9 years ago

@bfricka using the code from the pull request I no longer get the errors above. However getting a new error:

/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/lib/infer.js:535 var c0 = str.charCodeAt(0) ^ TypeError: Cannot read property 'charCodeAt' of undefined at isInteger (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/lib/infer.js:535:17) at extend.hasProp (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/lib/infer.js:569:11) at extend.getProp (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/lib/infer.js:601:24) at walk.simple.ObjectExpression (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern-closure/closure.js:182:53) at c (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern-closure/node_modules/acorn/dist/walk.js:39:16) at Object.skipThrough (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/node_modules/acorn/dist/walk.js:169:3) at c (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern-closure/node_modules/acorn/dist/walk.js:38:15) at Object.base.VariableDeclarator (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/node_modules/acorn/dist/walk.js:255:18) at c (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern-closure/node_modules/acorn/dist/walk.js:38:15) at Object.base.VariableDeclaration (/Users/joshua.smith/.atom/packages/atom-ternjs/node_modules/tern/node_modules/acorn/dist/walk.js:250:5)

bfricka commented 9 years ago

Looks like more acorn stuff (walk.simple), etc. I'll take a look tonight and see why it's also not getting picked up in the unit tests.

bfricka commented 9 years ago

@jpsmith1981 Hmmm... I'm using tern_for_sublime running tern 0.16.0 and the latest PR of tern-closure. I've tried a bunch of things, and I cannot reproduce your error at all. I get zero errors, and all the usual stuff works. Extends / subclassing picks up all the right stuff. All the right types are present.

Are you sure you have all the correct versions?

lucasvw commented 9 years ago

@bfricka. So I have cloned your repo and switched to the tcl-fix branch into

~/.atom/packages/atom-ternjs/node-modules/tern/node-modules/tern-closure

Also, I have copied

~/.atom/packages/atom-ternjs/node-modules/tern/node-modules/tern-closure/closure.js

to the

~/.atom/packages/atom-ternjs/node-modules/tern/plugin folder.

However, I get the following error message:

atom-ternjs module.js:339 throw err; ^

Error: Cannot find module 'doctrine' at Function.Module._resolveFilename (module.js:337:15) at Function.Module._load (module.js:287:25) at Module.require (module.js:366:17) at require (module.js:385:17) at Object. (C:\Users\lvanwalstijn.atom\packages\atom-ternjs\node_modules\tern\node_modules\tern-closure\lib\comment.js:20:16) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Module.require (module.js:366:17)

Any ideas?

jpsmith1981 commented 9 years ago

@bfricka this is actually working for me. Thanks man...

There seems to a be problem with the loadEagerly but once removed everything is working as expected.

angelozerr commented 9 years ago

@bfricka I have tried with Eclipse (tern.java) and I have the same error than @jpsmith1981

var c0 = str.charCodeAt(0)
^
TypeError: Cannot read property 'charCodeAt' of undefined

To avoid this error, I had to change https://github.com/google/tern-closure/blob/master/closure.js#L178 with:

ObjectExpression: function(node) {
      for (var i = 0; i < node.properties.length; ++i) {
        var prop = node.properties[i], key = prop.key, propName = key && (key.name || key.value);
        if (propName) interpretComments(
            prop, key._closureComment, node.objType.getProp(propName));
      }
    }

Problem comes from goog\dom\dom.js

goog.dom.DIRECT_ATTRIBUTE_MAP_ = {
  'cellpadding': 'cellPadding',

After that loadEagerly should work. But it seems that there are other bugs (when I hover cellpadding, it throws error.

bfricka commented 9 years ago

@angelozerr Thanks for that. I tried your fix for loadEagerly, and it does work. I'll look into any additional errors this weekend. Hopefully we can get a fix merged soon.