コード例 #1
0
 public CommentParamArg(string extType, string variable, bool isOptional, string defaultValue, Dictionary <string, jsduck.Class> jsClassMap)
 {
     this.IsRest       = false;
     this.IsOptional   = isOptional;
     this.Variable     = NormalizeVariableName(variable);
     this.DefaultValue = defaultValue;
     this.Type         = JsDoc.ExtTypeToTS(extType, ref this.IsOptional, ref this.IsRest, jsClassMap);
 }
コード例 #2
0
        public static string ExtTypeToTS(string extType, ref bool isOptional, ref bool isRest, Dictionary <string, jsduck.Class> jsClassMap)
        {
            if (extType[0] == ' ' || extType[extType.Length - 1] == ' ')
            {
                extType = extType.Trim();
            }
            if (extType.IndexOfAny(EXTTYPESEP) < 0)
            {
                return(JsDoc.ExtTypeToTSMap(extType, ref isOptional, ref isRest, jsClassMap) ?? "any");
            }
            var list = new List <string>();

            foreach (var singeType in extType.Split(EXTTYPESEP))
            {
                var tsType = JsDoc.ExtTypeToTSMap(singeType, ref isOptional, ref isRest, jsClassMap);
                if (tsType != null)
                {
                    list.Add(tsType);
                }
            }
            return(String.Join("|", !isRest ? list.Distinct() : list.Select(i => i.EndsWith("[]") ? i : (i + "[]")).Distinct()));
        }
コード例 #3
0
        public static string[] ExtractComments(string spanID, string itemID, Dictionary <string, HtmlDocument> docs, out Dictionary <string, HashSet <string> > jsHtmlParams)
        {
            var htmlParams   = jsHtmlParams = new Dictionary <string, HashSet <string> >();
            var htmlComments = JsDoc.ExtractComments(spanID, itemID, docs,
                                                     (string type, string data, string commentLine) =>
            {
                if (IgnoredParams.Contains(type))
                {
                    commentLine = null;
                }
                else if (ExtractableParams.Contains(type) || ExtractableButKeepCommentParams.Contains(type))
                {
                    var sep1 = data == null || data.Length <= 0 ? -1 : data[0] != '{' ? data.IndexOf(' ') : (data.IndexOf('}') + 1);
                    if (sep1 <= 0 || sep1 >= data.Length)
                    {
                        commentLine = null;
                        if (sep1 > 0 && data[sep1 - 1] == '}' && data[0] == '{')
                        {
                            data = data.Substring(1, data.Length - 2);
                        }
                    }
                    else
                    {
                        var start = sep1 + 1;
                        for (; data[start] == ' ' && start < data.Length; start++)
                        {
                            ;
                        }
                        var sep2 = data[start] == '[' ? (data.IndexOf(']', start) + 1) : data.IndexOf(' ', start);
                        if (sep2 <= 0)
                        {
                            commentLine = null;
                        }
                        else
                        {
                            if (ExtractableParams.Contains(type))
                            {
                                if (data.Length <= sep2)
                                {
                                    commentLine = null;
                                }
                                else
                                {
                                    commentLine = data.Substring(sep2 + 1).TrimStart();
                                    if (commentLine.Length <= 0)
                                    {
                                        commentLine = null;
                                    }
                                    else
                                    {
                                        commentLine = "* " + commentLine;
                                    }
                                }
                            }
                            data = data.Substring(0, sep2);
                        }
                    }
                }
                if (!htmlParams.ContainsKey(type))
                {
                    htmlParams.Add(type, new HashSet <string>()
                    {
                        data
                    });
                }
                else
                {
                    htmlParams[type].Add(data);
                }
                return(commentLine);
            }
                                                     );

            return(htmlComments);
        }