Exemplo n.º 1
0
 public string Process(List <string> PreDefinedFlags)
 {
     if (MainSourceFile is not null)
     {
         info = new JSInfo();
         if (PreDefinedFlags is not null)
         {
             this.info.Flags = PreDefinedFlags;
         }
         return(Process(MainSourceFile, true));
     }
     else if (ScriptContent is not null)
     {
         info = new JSInfo();
         if (PreDefinedFlags is not null)
         {
             this.info.Flags = PreDefinedFlags;
         }
         return(Process(ScriptContent, true));
     }
     else
     {
         throw new Exception("No input");
     }
 }
Exemplo n.º 2
0
        internal string RealProcess(string[] lines, bool isMainFile)
        {
            StringBuilder stringBuilder = new StringBuilder();
            bool          isIgnore      = false;
            JSInfo        info;

            if (isMainFile)
            {
                info = this.info;
            }
            else
            {
                info = new JSInfo();
            }
            for (int i = 0; i < lines.Length; i++)
            {
                var item = lines[i];
                if (item.Trim().StartsWith("///") || item.Trim().StartsWith("#"))
                {
                    //Macro

                    var macro = item.Trim();
                    if (item.Trim().StartsWith("///"))
                    {
                        macro = macro.Substring(3).Trim();
                    }
                    else
                    {
                        macro = macro.Substring(1).Trim();
                    }
                    if (macro == "")
                    {
                        continue;
                    }
                    var  m0 = CommandLineTool.Analyze(macro);
                    bool willDisposeLine = false;
                    switch (m0.RealParameter[0].EntireArgument.ToUpper())
                    {
                    case "DEFINE":
                    {
                        if (isIgnore is not true)
                        {
                            if (settings.RemoveDefineMacro)
                            {
                                willDisposeLine = true;
                            }
                            var Key = m0.RealParameter[1].EntireArgument;
                            switch (Key.ToUpper())
                            {
                            case "NAME":
                            {
                                if (settings.PreserveModuleInfoMacro && isMainFile)
                                {
                                    willDisposeLine = false;
                                }
                                info.Name = m0.RealParameter[2].EntireArgument;
                            }
                            break;

                            case "AUTHOR":
                            {
                                if (settings.PreserveModuleInfoMacro && isMainFile)
                                {
                                    willDisposeLine = false;
                                }
                                info.Author = m0.RealParameter[2].EntireArgument;
                            }
                            break;

                            case "VERSION":
                            {
                                if (settings.PreserveModuleInfoMacro && isMainFile)
                                {
                                    willDisposeLine = false;
                                }
                                info.Version = new Version(m0.RealParameter[2].EntireArgument);
                            }
                            break;

                            default:
                            {
                                this.info.Flags.Add(Key);
                            }
                            break;
                            }
                        }
                    }
                    break;

                    case "USING":
                    {
                        if (isIgnore is not true)
                        {
                            if (m0.RealParameter[1].EntireArgument.ToUpper() == "JS")
                            {
                                if (settings.RemoveUsingJSMacro)
                                {
                                    willDisposeLine = true;
                                }
                                var f = FindJS(m0.RealParameter[2].EntireArgument);
                                if (f is not null)
                                {
                                    item = Process(f, false);
                                    stringBuilder.Append(item);
                                    continue;        // Force skip this to avoid duplicate code.
                                }
                                else
                                {
                                    throw new Exception("Target JS file not found:" + m0.RealParameter[2].EntireArgument);
                                }
                                //Pre-Combine JavaScript Codes.
                            }
                            else
                            if (m0.RealParameter[1].EntireArgument.ToUpper() == "DLL")
                            {
                                info.UsingDLLs.Add(m0.RealParameter[2]);
                            }
                        }
                    }
                    break;

                    case "INCLUDE":
                    {
                        if (isIgnore is not true)
                        {
                            var f = FindJS(m0.RealParameter[1].EntireArgument);
                            if (f is not null)
                            {
                                item = Process(f, false);
                                stringBuilder.Append(item);
                                continue;        // Force skip this to avoid duplicate code.
                            }
                            else
                            {
                                throw new Exception("Target JS file not found:" + m0.RealParameter[2].EntireArgument);
                            }
                        }
                    }
                    break;

                    case "IFDEF":
                    {
                        isIgnore = true;
                        foreach (var flag in this.info.Flags)
                        {
                            if (m0.RealParameter[1].EntireArgument == flag)
                            {
                                isIgnore = false;
                                break;
                            }
                        }
                    }
                    break;

                    case "ENDIF":
                    {
                        isIgnore = false;
                    }
                    break;

                    case "IFNDEF":
                    {
                        isIgnore = false;
                        foreach (var flag in this.info.Flags)
                        {
                            if (m0.RealParameter[1].EntireArgument == flag)
                            {
                                isIgnore = true;
                                break;
                            }
                        }
                    }
                    break;

                    case "EXPOSETYPE":
                    {
                        if (isIgnore is not true)
                        {
                            var Name = m0.RealParameter[1].EntireArgument;
                            var Path = m0.RealParameter[2].EntireArgument;
                            if (settings.PreserveExposeTypeMacro == true)
                            {
                                willDisposeLine = false;
                            }
                            if (!info.ExposedTypes.ContainsKey(Name))
                            {
                                info.ExposedTypes.Add(Name, Path);
                            }
                            else
                            {
                                info.ExposedTypes[Name] = Path;
                            }
                        }
                    }
                    break;

                    default:
                        break;
                    }
                    if (settings.RemoveAllMacros is true)
                    {
                        willDisposeLine = true;
                    }
                    if (willDisposeLine)
                    {
                        continue;
                    }
                }
                else if (item.Trim().StartsWith("//"))
                {
                    //isIgnore = settings.DisposeSingleLineComment && (!settings.PreserveSingleLineCommentInMainFile || isMainFile ==false);
                    continue;
                }
                if (isIgnore is not true)
                {
                    if (item.Trim().StartsWith("#"))
                    {
                        stringBuilder.Append("///");
                        stringBuilder.Append(item.Trim().Substring(1));
                    }
                    else
                    {
                        stringBuilder.Append(item);
                    }
                    stringBuilder.Append(Environment.NewLine);
                }
            }
            if (!isMainFile)
            {
                this.info.SubModules.Add(info);
            }
            return(stringBuilder.ToString());
        }