Menu

#49 Support for JavaScript aliases

open
None
5
2008-12-13
2008-10-09
No

Currently Exuberant Ctags won't handle JavaScript aliases correctly. Here's some example code:

// A namespace
var mynamespace = {};
// A class within the namespace
mynamespace.o = function(){};
// An alias to the prototype
var _op = mynamespace.o.prototype;
_op.f = function()
{
alert("Hi!");
};
_op = undefined;

// A namespace within a namespace
mynamespace.subnamespace = {};
// An alias for the subnamespace
var _mysub = mynamespace.subnamespace;
_mysub.prop1 = "Hi!";
_mysub = undefined;

It is fairly common to use aliases in these situations since de-referencing can be expensive in JavaScript.

I built the source in svn today and used the following command line:

ctags --format=2 --excmd=pattern --fields=nks --sort=no --language-force=javascript --javascript-types=cfvmp test.js

The resulting tag file looks like:

!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.6b1 //
mynamespace.o t.js /^mynamespace.o = function(){};$/;" f line:5
_op t.js /^var _op = mynamespace.o.prototype;$/;" v line:8
_op.f t.js /^_op.f = function()$/;" f line:9
_mysub t.js /^var _mysub = mynamespace.subnamespace;$/;" v line:18

The second tag in the list isn't very helpful but doesn't hurt. The third tag I would expect to be "mynamespace.o.f". I also expect to see a tag for mynamespace.subnamespace as well as mynamespace.subnamespace.prop1.

Discussion

  • David Fishburn

    David Fishburn - 2008-12-13
    • assigned_to: nobody --> dfishburn
     
  • David Fishburn

    David Fishburn - 2008-12-13

    Assigned to maintainer.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.