mozilla / doctorjs

A set of static analysis tools for JavaScript
Other
739 stars 67 forks source link

jsctags does not work with nodejs 0.10.0 #52

Closed sangwook-kim closed 11 years ago

sangwook-kim commented 11 years ago

Hi. I'm on Ubuntu. and I found a problem yesterday. Ubuntu package manager provides nodejs 0.6.x. I'm trying grunt 0.4.* and grunt 0.4.x needs nodejs >= 0.8. So I've downloaded and built nodejs 0.10.x (which is official new stable version.)

Then, jsctags has broke and issued some error message complaining about

Array.prototype.push called on null or undefined

/usr/local/bin/jsctags:195 throw e; ^ TypeError: Array.prototype.push called on null or undefined at Object.exports.Tags.Object.create.Trait.compose.Trait.add (/usr/local/lib/jsctags/ctags/index.js:71:30) at Object.exports.Tags.Object.create.Trait.compose.Trait.scan (/usr/local/lib/jsctags/ctags/index.js:105:14) at processPath (/usr/local/bin/jsctags:189:18) at Object. (/usr/local/bin/jsctags:207:5) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)

at startup (node.js:119:16)

I figured a workaround for this situation.

  1. sudo -H npm install -g n : Install 'n' to use as node version management tool.
  2. sudo n 0.10.0 : to recognize 0.10.x that i've already installed
  3. sudo n 0.8.22 : to install 0.8.x, which works fine for jsctags and grunt.

maybe you need to sudo n use 0.8.22 to make 0.8.22 default. I'm not quite familiar with 'n'.

and when you get "node -v" "0.8.22". All problem solved for me.

Still, I think it would be better for jsctags work with node 0.10.x.

Thank you.

sangwook-kim commented 11 years ago

sorry, that I'm not familiar with markdown yet...

tiantian20007 commented 11 years ago

After downgrade to 0.8.22, tag show up. However, the scope of object and function is lost. This issue continue: https://github.com/mozilla/doctorjs/issues/5

chilkari commented 11 years ago

Not sure if this will help you, but I was having the same issue. Without knowing much about the doctorjs code, it appears to be assuming this.tags is an array: [] when it hasn't been initialized.

I modified /usr/local/lib/jsctags/ctags/index.js as follows:

Modified the constructor for Tags to simply init: exports.Tags = function(initialTags) { this.init(); }

Added a tags list to the prototype setup, around lines 53-55 (may be slightly less for you due to comments):

exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({

tags: [],    // <--  added this

_search: function (id, pred) {

And it appears to work for me with node:0.10.0

Nek commented 11 years ago

Thanks a lot! That worked for me too.

sangwook-kim commented 11 years ago

Thanks, chilkari!

Works fine for me. Maybe there could be some performance issue, or not. But I'm satisfied with your patch.

demizer commented 11 years ago

I don't think this issue should have been closed. The solution worked for me as well.

dmitrym0 commented 11 years ago

This worked for me as well.

pacuna commented 10 years ago

thanks!

nishantvarma commented 10 years ago

Good patch though @chilkari -Thanks

bbrink68 commented 10 years ago

Confirmed, this works. I agree this probably shouldn't have been closed quite yet.

For anyone interested, the precise changes made to the file: sudo vim /usr/local/lib/jsctags/ctags/index.js

On line 51

exports.Tags.prototype = Object.create(Object.prototype, Trait.compose(Trait({
    tags: [], // Added This
    _search: function (id, pred) {
        var shadowTag = { name: id };
        var tags = this.tags;
        var index = _(tags).sortedIndex(shadowTag, function (tag) {
            return tag.name;
        });
        ...
        ...

Here is a sed insert if you'd rather not bother editing yourself:

sudo sed -i '51i tags: [],' /usr/local/lib/jsctags/ctags/index.js
mmolhoek commented 10 years ago

work for me aswell :) now searching for a good vim plugin...

haibzhong commented 9 years ago

it works. thanks.