public JsDirectivePrologue(string value, JsContext context, JsParser parser)
     : base(value, JsPrimitiveType.String, context, parser)
 {
     // this is a "use strict" directive if the source context is EXACTLY "use strict"
     // don't consider the quotes so it can be " or ' delimiters
     UseStrict = string.CompareOrdinal(Context.Code, 1, "use strict", 0, 10) == 0;
 }
示例#2
0
 private JsReorderScopeVisitor(JsParser parser)
 {
     // save the mods we care about
     m_moveVarStatements   = parser.Settings.ReorderScopeDeclarations && parser.Settings.IsModificationAllowed(JsTreeModifications.CombineVarStatementsToTopOfScope);
     m_moveFunctionDecls   = parser.Settings.ReorderScopeDeclarations && parser.Settings.IsModificationAllowed(JsTreeModifications.MoveFunctionToTopOfScope);
     m_combineAdjacentVars = parser.Settings.IsModificationAllowed(JsTreeModifications.CombineVarStatements);
 }
示例#3
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            DialogResult   result;

            do
            {
                result = ofd.ShowDialog();
            } while (result != DialogResult.OK || ofd.FileName == null);
            string fileName = ofd.FileName;

            FileInfo snakewareLogo = new FileInfo(fileName);

            MessageBox.Show("Bytes before: " + snakewareLogo.Length);

            ImageOptimizer optimizer = new ImageOptimizer();

            optimizer.LosslessCompress(snakewareLogo);

            snakewareLogo.Refresh();
            MessageBox.Show("Bytes after:  " + snakewareLogo.Length);

            //Compressor
            return;

            AntlrFileStream inputStream = new AntlrFileStream(fileName);

            IParseTree  tree  = null;
            IVocabulary names = null;
            string      typeS = fileName.Substring(fileName.LastIndexOf('.') + 1);

            switch (typeS.ToUpper())
            {
            case "CSS":
                tree  = new CssParser(new CommonTokenStream(new CssLexer(inputStream))).stylesheet();
                names = CssParser.DefaultVocabulary;
                break;

            case "HTML":
                tree  = new HtmlParser(new CommonTokenStream(new HtmlLexer(inputStream))).htmlDocument();
                names = HtmlParser.DefaultVocabulary;
                break;

            case "JS":
                tree  = new JsParser(new CommonTokenStream(new JsLexer(inputStream))).program();
                names = JsParser.DefaultVocabulary;
                break;
            }
            var node = treeView.Nodes.Add(ToText(tree, names));

            RecursFn(tree, node, (i) => ToText(i, names));

            /*var d = new CommonTokenStream(new HtmlLexer(inputStream));
             * names = HtmlParser.DefaultVocabulary;
             * d.Fill();
             * foreach(var item in d.GetTokens()) {
             *  treeView.Nodes.Add(names.GetDisplayName(item.Type) + " --- " + item.ToString());
             * }*/
        }
示例#4
0
 protected JsAstNode(JsContext context, JsParser parser)
 {
     Parser = parser;
     if (context != null)
     {
         Context = context;
     }
     else
     {
         // generate a bogus context
         Context = new JsContext(parser);
     }
 }
 public JsImportantComment(JsContext context, JsParser parser)
     : base(context, parser)
 {
     if (parser != null && parser.Settings.OutputMode == MinifierOutputMode.SingleLine)
     {
         // if we are in single-line mode, we want to replace all CRLF pairs
         // with just the LF to save output bytes.
         Comment = Context.Code.Replace("\r\n", "\n");
     }
     else
     {
         // multi-line mode, just leave it as-is
         Comment = Context.Code;
     }
 }
 public JsImportantComment(JsContext context, JsParser parser)
     : base(context, parser)
 {
     if (parser != null && parser.Settings.OutputMode == MinifierOutputMode.SingleLine)
     {
         // if we are in single-line mode, we want to replace all CRLF pairs
         // with just the LF to save output bytes.
         Comment = Context.Code.Replace("\r\n", "\n");
     }
     else
     {
         // multi-line mode, just leave it as-is
         Comment = Context.Code;
     }
 }
示例#7
0
        public virtual ITokenSource Edit(ITokenSource tokens)
        {
            CommonTokenStream s      = new CommonTokenStream(tokens);
            JsParser          parser = new JsParser(s);

            s.Fill();

            var program = parser.program();

            visitor.Visit(program, s.GetTokens());

            var source = new ListTokenSource(visitor.GetResult());

            source.TokenFactory = tokens.TokenFactory;
            return(source);
        }
示例#8
0
        public ITokenSource Edit(ITokenSource tokens)
        {
            CommonTokenStream s      = new CommonTokenStream(tokens);
            JsParser          parser = new JsParser(s);

            s.Fill();
            IVisitorTree v = new JsVisitorChangeLiteralString(factoryNames, tokens.TokenFactory);

            var program = parser.program();

            v.Visit(program, s.GetTokens());

            var source = new ListTokenSource(v.GetResult());

            source.TokenFactory = tokens.TokenFactory;
            return(source);
        }
 public JsParameterDeclaration(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#10
0
 public JsFunctionObject(JsContext functionContext, JsParser parser)
     : base(functionContext, parser)
 {
 }
示例#11
0
 public JsThisLiteral(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#12
0
 public JsConditionalCompilationElse(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#13
0
 public JsGroupingOperator(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#14
0
 protected JsConditionalCompilationStatement(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#15
0
 public JsVar(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#16
0
 public JsContinueNode(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
 public JsDebuggerNode(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
 public JsConditionalCompilationEnd(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
 protected JsConditionalCompilationStatement(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#20
0
 public JsThisLiteral(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#21
0
        public static void Apply(JsBlock block, JsParser parser)
        {
            // create a new instance of the visitor and apply it to the block
            var visitor = new JsReorderScopeVisitor(parser);

            block.Accept(visitor);

            // if there were any module directive prologues we need to promote, do them first
            var insertAt = 0;

            if (visitor.m_moduleDirectives != null)
            {
                foreach (var directivePrologue in visitor.m_moduleDirectives)
                {
                    insertAt = RelocateDirectivePrologue(block, insertAt, directivePrologue);
                }
            }

            // Make sure that we skip over any remaining comments and directive prologues.
            // we do NOT want to insert anything between the start of the scope and any directive prologues.
            while (insertAt < block.Count &&
                   (block[insertAt] is JsDirectivePrologue || block[insertAt] is JsImportantComment))
            {
                ++insertAt;
            }

            // first, we want to move all function declarations to the top of this block
            if (visitor.m_functionDeclarations != null)
            {
                foreach (var funcDecl in visitor.m_functionDeclarations)
                {
                    insertAt = RelocateFunction(block, insertAt, funcDecl);
                }
            }

            // special case: if there is only one var statement in the entire scope,
            // then just leave it alone because we will only add bytes by moving it around,
            // or be byte-neutral at best (no initializers and not in a for-statement).
            if (visitor.m_varStatements != null && visitor.m_varStatements.Count > 1)
            {
                // then we want to move all variable declarations after to the top (after the functions)
                foreach (var varStatement in visitor.m_varStatements)
                {
                    insertAt = RelocateVar(block, insertAt, varStatement);
                }
            }

            // then we want to do the same thing for all child functions (declarations AND other)
            if (visitor.m_functionDeclarations != null)
            {
                foreach (var funcDecl in visitor.m_functionDeclarations)
                {
                    Apply(funcDecl.Body, parser);
                }
            }

            if (visitor.m_functionExpressions != null)
            {
                foreach (var funcExpr in visitor.m_functionExpressions)
                {
                    Apply(funcExpr.Body, parser);
                }
            }
        }
 public JsDocumentContext(JsParser parser)
 {
     m_parser    = parser;
     IsGenerated = true;
     Source      = "[generated code]";
 }
 public JsObjectLiteral(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
 public JsDocumentContext(JsParser parser, string source)
 {
     m_parser = parser;
     Source   = source;
 }
示例#25
0
 public JsSwitchCase(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#26
0
 public JsLogicalNot(JsAstNode node, JsParser parser)
 {
     m_expression = node;
     m_parser     = parser;
 }
示例#27
0
 public JsRegExpLiteral(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#28
0
        public static void Apply(JsAstNode node, JsParser parser)
        {
            var logicalNot = new JsLogicalNot(node, parser);

            logicalNot.Apply();
        }
示例#29
0
 public JsDoWhile(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#30
0
 public JsMember(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#31
0
 public JsBreak(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#32
0
 public JsContext(JsParser parser)
     : this(new JsDocumentContext(parser))
 {
 }
示例#33
0
 public JsConstantWrapperPP(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#34
0
 public JsReturnNode(JsContext context, JsParser parser)
     : base(context, parser)
 {
 }
示例#35
0
 public JsGetterSetter(String identifier, bool isGetter, JsContext context, JsParser parser)
     : base(identifier, JsPrimitiveType.String, context, parser)
 {
     IsGetter = isGetter;
 }
示例#36
0
 public JsBlock(JsContext context, JsParser parser)
     : base(context, parser)
 {
     m_list = new List <JsAstNode>();
 }