symbol.js
来自「JsDoc Toolkit 是一个把js描述格式化成文档的工具。开发者只需按Js」· JavaScript 代码 · 共 601 行 · 第 1/2 页
JS
601 行
sym = new JSDOC.Symbol("foo", [], "FUNCTION", new JSDOC.DocComment("/**Description.\n@param {array} pages The pages description.*"+"/")); is(sym.params.length, 1, "user defined param with description is found."); is(sym.params[0].desc, "The pages description.", "user defined param description is found."); */ // @constructor if (this.comment.getTag("constructor").length) { this.isa = "CONSTRUCTOR"; } /*t: var sym = new JSDOC.Symbol("foo", [], "OBJECT", new JSDOC.DocComment("/**@constructor*"+"/")); is(sym.isa, "CONSTRUCTOR", "@constructor tag, makes symbol a constructor."); */ // @static if (this.comment.getTag("static").length) { this.isStatic = true; if (this.isa == "CONSTRUCTOR") { this.isNamespace = true; } } /*t: var sym = new JSDOC.Symbol("foo", [], "OBJECT", new JSDOC.DocComment("/**@static\n@constructor*"+"/")); is(sym.isStatic, true, "@static tag, makes isStatic true."); is(sym.isNamespace, true, "@static and @constructor tag, makes isNamespace true."); */ // @inner if (this.comment.getTag("inner").length) { this.isInner = true; this.isStatic = false; } /*t: var sym = new JSDOC.Symbol("foo", [], "OBJECT", new JSDOC.DocComment("/**@inner*"+"/")); is(sym.isStatic, false, "@inner tag, makes isStatic false."); is(sym.isInner, true, "@inner makes isInner true."); */ // @field if (this.comment.getTag("field").length) { this.isa = "OBJECT"; } /*t: var sym = new JSDOC.Symbol("foo", [], "FUNCTION", new JSDOC.DocComment("/**@field*"+"/")); is(sym.isa, "OBJECT", "@field tag, makes symbol an object."); */ // @function if (this.comment.getTag("function").length) { this.isa = "FUNCTION"; } /*t: var sym = new JSDOC.Symbol("foo", [], "OBJECT", new JSDOC.DocComment("/**@function*"+"/")); is(sym.isa, "FUNCTION", "@function tag, makes symbol a function."); */ // @event var events = this.comment.getTag("event"); if (events.length) { this.isa = "FUNCTION"; this.isEvent = true; } /*t: var sym = new JSDOC.Symbol("foo", [], "OBJECT", new JSDOC.DocComment("/**@event*"+"/")); is(sym.isa, "FUNCTION", "@event tag, makes symbol a function."); is(sym.isEvent, true, "@event makes isEvent true."); */ // @name var names = this.comment.getTag("name"); if (names.length) { this.name = names[0].desc; } /*t: // todo */ // @property var properties = this.comment.getTag("property"); if (properties.length) { thisProperties = this.properties; for (var i = 0; i < properties.length; i++) { var property = new JSDOC.Symbol(this.alias+"#"+properties[i].name, [], "OBJECT", new JSDOC.DocComment("/**"+properties[i].desc+"\n@name "+properties[i].name+"\n@memberOf "+this.alias+"#*/")); // TODO: shouldn't the following happen in the addProperty method of Symbol? property.name = properties[i].name; property.memberOf = this.alias; if (properties[i].type) property.type = properties[i].type; if (properties[i].defaultValue) property.defaultValue = properties[i].defaultValue; this.addProperty(property); JSDOC.Parser.addSymbol(property); } } /*t: // todo */ // @return var returns = this.comment.getTag("return"); if (returns.length) { // there can be many return tags in a single doclet this.returns = returns; this.type = returns.map(function($){return $.type}).join(", "); } /*t: // todo */ // @exception this.exceptions = this.comment.getTag("throws"); /*t: // todo */ // @requires var requires = this.comment.getTag("requires"); if (requires.length) { this.requires = requires.map(function($){return $.desc}); } /*t: // todo */ // @type var types = this.comment.getTag("type"); if (types.length) { this.type = types[0].desc; //multiple type tags are ignored } /*t: // todo */ // @private if (this.comment.getTag("private").length || this.isInner) { this.isPrivate = true; } // @ignore if (this.comment.getTag("ignore").length) { this.isIgnored = true; } /*t: // todo */ // @inherits ... as ... var inherits = this.comment.getTag("inherits"); if (inherits.length) { for (var i = 0; i < inherits.length; i++) { if (/^\s*([a-z$0-9_.#-]+)(?:\s+as\s+([a-z$0-9_.#]+))?/i.test(inherits[i].desc)) { var inAlias = RegExp.$1; var inAs = RegExp.$2 || inAlias; if (inAlias) inAlias = inAlias.replace(/\.prototype\.?/g, "#"); if (inAs) { inAs = inAs.replace(/\.prototype\.?/g, "#"); inAs = inAs.replace(/^this\.?/, "#"); } if (inAs.indexOf(inAlias) != 0) { //not a full namepath var joiner = "."; if (this.alias.charAt(this.alias.length-1) == "#" || inAs.charAt(0) == "#") { joiner = ""; } inAs = this.alias + joiner + inAs; } } this.inherits.push({alias: inAlias, as: inAs}); } } /*t: // todo */ // @augments this.augments = this.comment.getTag("augments"); // @default var defaults = this.comment.getTag("default"); if (defaults.length) { if (this.is("OBJECT")) { this.defaultValue = defaults[0].desc; } } /*t: // todo */ // @memberOf var memberOfs = this.comment.getTag("memberOf"); if (memberOfs.length) { this.memberOf = memberOfs[0].desc; this.memberOf = this.memberOf.replace(/\.prototype\.?/g, "#"); } /*t: // todo */ // @public if (this.comment.getTag("public").length) { this.isPrivate = false; } /*t: // todo */}JSDOC.Symbol.prototype.is = function(what) { return this.isa === what;}JSDOC.Symbol.prototype.isBuiltin = function() { return JSDOC.Lang.isBuiltin(this.alias);}JSDOC.Symbol.prototype.setType = function(/**String*/comment, /**Boolean*/overwrite) { if (!overwrite && this.type) return; var typeComment = JSDOC.DocComment.unwrapComment(comment); this.type = typeComment;}JSDOC.Symbol.prototype.inherit = function(symbol) { if (!this.hasMember(symbol.name) && !symbol.isInner) { if (symbol.is("FUNCTION")) this.methods.push(symbol); else if (symbol.is("OBJECT")) this.properties.push(symbol); }}JSDOC.Symbol.prototype.hasMember = function(name) { return (this.hasMethod(name) || this.hasProperty(name));}JSDOC.Symbol.prototype.addMember = function(symbol) { if (symbol.is("FUNCTION")) { this.addMethod(symbol); } else if (symbol.is("OBJECT")) { this.addProperty(symbol); }}JSDOC.Symbol.prototype.hasMethod = function(name) { var thisMethods = this.methods; for (var i = 0, l = thisMethods.length; i < l; i++) { if (thisMethods[i].name == name) return true; if (thisMethods[i].alias == name) return true; } return false;}JSDOC.Symbol.prototype.addMethod = function(symbol) { var methodAlias = symbol.alias; var thisMethods = this.methods; for (var i = 0, l = thisMethods.length; i < l; i++) { if (thisMethods[i].alias == methodAlias) { thisMethods[i] = symbol; // overwriting previous method return; } } thisMethods.push(symbol); // new method with this alias}JSDOC.Symbol.prototype.hasProperty = function(name) { var thisProperties = this.properties; for (var i = 0, l = thisProperties.length; i < l; i++) { if (thisProperties[i].name == name) return true; if (thisProperties[i].alias == name) return true; } return false;}JSDOC.Symbol.prototype.addProperty = function(symbol) { var propertyAlias = symbol.alias; var thisProperties = this.properties; for (var i = 0, l = thisProperties.length; i < l; i++) { if (thisProperties[i].alias == propertyAlias) { thisProperties[i] = symbol; // overwriting previous property return; } } thisProperties.push(symbol); // new property with this alias}JSDOC.Symbol.srcFile = ""; //running reference to the current file being parsed
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?