JSDOC/ScopeNamer.js
[app.jsdoc] / JSDOC / ScopeNamer.js
index ec25973..f82421a 100644 (file)
@@ -7,6 +7,7 @@ Symbol = imports.Symbol.Symbol;
 
 /**
  * @class ScopeNamer
+ * @extends Collapse
  * @namespace JSDOC
  * The point of this class is to iterate through the Collapsed tree
  * and add the property 'scopedName' to the tokens.
@@ -98,7 +99,10 @@ ScopeNamer = XObject.define(
          * add/remove ';' after return to configure at present..
          * @param {String} str String to output
          */
-        debugCall : function(str)  { return print(str); }, 
+        debugCall : function(str)  {
+            if (!this.filename.match(/BuildDocs\.js/)) return;
+            return   print(str);
+        }, 
         
         collapseTop : true,
         
@@ -131,9 +135,18 @@ ScopeNamer = XObject.define(
             this.debugCall("walkStatements :" + scope ) ;            
             var _this = this;
             var res = false;
-            
-            
-            statements.forEach(function(st ) {
+            var isGlobal = scope == '_global_';
+           
+            statements.some(function(st ) {
+                // handle change of scope..
+                if (isGlobal &&
+                        st[0].jsdoc &&
+                        st[0].jsdoc.getTag('scope').length
+                   ) {
+                    scope = st[0].jsdoc.getTag('scope');
+                }
+                
+                
                 res = _this.walkStatement(scope, st);
                 if (res === true) {
                     return true;
@@ -154,15 +167,31 @@ ScopeNamer = XObject.define(
             var isGlobal = scope == '_global_';
             
             
-            while (null != (token = this.next())) {
             
+            //if (this.filename.match(/pack\.js/) && isGlobal) {
+            //    print(JSON.stringify(stmt , null,4));
+            //}
+            // @ignore stops the parser..
+            if (isGlobal &&
+                    stmt[0].jsdoc &&
+                    stmt[0].jsdoc.getTag('ignore').length
+               ) {
+                this.debugCall("walkStatement : ignore found - " + scope + '@' + this.tokens[0].line );
+                print("GOT ignore?");
+                return true;
+            }
+           
+            
+            while (null != (token = this.next())) {
+                
                 //'function' 
                 //walkFunction(scope, name , args,  stmts  )
                 //
                 if (token.name == "FUNCTION") {
                     // function a() { .... } << scope is a  $this$={a}
                     if (this.lookTok(1).is('NAME')) {
-                        name = this.lookTok(2).data;
+                        name = isGlobal ? this.lookTok(1).data : '';
+                        
                         this.walkFunctionDef(scope, name, this.lookTok(2).args, this.lookTok(3).items, token);
                         continue;
                     }
@@ -213,7 +242,7 @@ ScopeNamer = XObject.define(
                     var name = this.lookTok(-2).data;
                     name = !isGlobal && isVar ? false : name;
                     name = !isGlobal && name && !name.match(/^this\./) ? false : name;
-                    print(JSON.stringify(token,null,4));
+                    //print(JSON.stringify(token,null,4));
                     this.walkObject(scope, name, token.props, jd);
                     continue;
                 }
@@ -240,12 +269,12 @@ ScopeNamer = XObject.define(
         walkFunctionDef : function (inscope, name, args, stmts, jsdocTok)
         {
             this.debugCall("wallkFuncDef: " + inscope + '@' + this.look(0).line );
-            var scope = inscope + '.' + name;
-            
-            
-            var symbol = new Symbol( scope , args || [] , "FUNCTION" ,  jsdocTok.jsdoc);
-            symbol._token = jsdocTok;
-            this.addSymbol(symbol, jsdocTok.jsdoc);
+            var scope = name.length ? (inscope + '.' + name) : inscope;
+            if (name.length) { 
+                var symbol = new Symbol( scope , args || [] , "FUNCTION" ,  jsdocTok.jsdoc);
+                symbol._token = jsdocTok;
+                this.addSymbol(symbol, jsdocTok.jsdoc);
+            }
             var sn = new ScopeNamer(this);
             sn.walkStatements(scope, stmts);
             
@@ -287,7 +316,7 @@ ScopeNamer = XObject.define(
                     var sn = new ScopeNamer(this);
                     
                     //print(JSON.stringify(items,null,4));
-                    sn.walkObject(scope + '.prototype', false, items[1][0].props, jsdocTok );
+                    sn.walkObject(scope , false, items[1][0].props, jsdocTok );
                     
                     return;
                 
@@ -303,10 +332,12 @@ ScopeNamer = XObject.define(
                     
                     this.addSymbol(symbol, jsdocTok.jsdoc);
                     var sn = new ScopeNamer(this);
+                    //print(JSON.stringify(items, null,4));
+                    // ctr statements.
+                    sn.walkStatements(scope + '.prototype', items[0][2].items);
                     
                     
-                    sn.walkStatements(scope, items[0][2].items);
-                    sn.walkObject(scope + '.prototype', false, items[2].props );
+                    sn.walkObject(scope + '.prototype', false, items[2][0].props );
                     return;
                 
                 
@@ -376,8 +407,15 @@ ScopeNamer = XObject.define(
         {
               //print("ADD symbol: " + JSON.stringify( symbol, null, 4));
               //print("PARSER addSYMBOL : " + symbol.alias);
-            ScopeNamer.prototype.debugCall("addSymbol : " + symbol.alias );       
+            
             // if a symbol alias is documented more than once the last one with the user docs wins
+            
+            // dumpe some invalid symbols..
+            if (symbol.alias.split(/[#.]/).length > 2) {
+                return;
+            }
+            ScopeNamer.prototype.debugCall("addSymbol : " + symbol.alias );       
+            
             if (ScopeNamer.symbols.hasSymbol(symbol.alias)) {
                 
                 if (!comment) { // we do not have a comment, and it's registered.