Package org.mozilla.javascript.ast

Examples of org.mozilla.javascript.ast.AstRoot


    @Test
    public void shouldIncludeBranchLogicForProcessSourceEvenIfIncludeBranchCoverageIsFalse() throws IOException {
        given(ioUtils.loadFromClassPath("/header.js")).willReturn("<header>");
        given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("<common>");
        given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("<branch>");
        given(parser.parse(anyString(), anyString(), anyInt())).willReturn(new AstRoot());

        assertThat(sourceProcessor.processSource("test.js", "x;"), startsWith("<branch><common><header>"));
        verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-branch.js");
    }
View Full Code Here


    public void shouldIncludeBranchLogicForProcessSource() throws IOException {
        ReflectionUtils.setField(sourceProcessor, "includeBranchCoverage", true);
        given(ioUtils.loadFromClassPath("/header.js")).willReturn("<header>");
        given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("<common>");
        given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("<branch>");
        given(parser.parse(anyString(), anyString(), anyInt())).willReturn(new AstRoot());

        assertThat(sourceProcessor.processSource("test.js", "x;"), startsWith("<branch><common><header>"));
        verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-branch.js");
    }
View Full Code Here

        ReflectionUtils.setField(sourceProcessor, "localStorage", true);
        given(ioUtils.loadFromClassPath("/header.js")).willReturn("<header>");
        given(ioUtils.loadFromClassPath("/jscoverage-common.js")).willReturn("<common>");
        given(ioUtils.loadFromClassPath("/jscoverage-branch.js")).willReturn("<branch>");
        given(ioUtils.loadFromClassPath("/jscoverage-localstorage.js")).willReturn("<localStorage>");
        given(parser.parse(anyString(), anyString(), anyInt())).willReturn(new AstRoot());

        assertThat(sourceProcessor.processSource("test.js", "x;"), startsWith("<branch><common><localStorage><header>"));
        verify(ioUtils, times(1)).loadFromClassPath("/jscoverage-localstorage.js");
    }
View Full Code Here

        String source = ioUtils.loadFromClassPath("/test.js");
//        String source = "let ({x: x0, y: y0} = point) {\n  print(x0);\n  print(y0);\n}";
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
        Parser parser = new Parser(compilerEnv);
        AstRoot astRoot = parser.parse(new StringReader(source), null, 1);
        astRoot.visitAll(new InstrumentVisitor());
        System.out.println(astRoot.toSource());
//        System.out.println("****************************");
//
//        source = "label:{\nx++;\nwhile (x) {\n  if (x) {\n    continue label;\n  }\n}}";
//        parser = new Parser();
//        astRoot = parser.parse(new StringReader(source), null, 1);
View Full Code Here

    private static void parseAndPrintSource(String source) throws IOException {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
//        compilerEnv.setStrictMode(false);
        Parser parser = new Parser(compilerEnv);
        AstRoot astRoot = parser.parse(new StringReader(source), null, 1);
        System.out.println(astRoot.toSource());
    }
View Full Code Here

    return w;
  }

  @Override
  public AstNode root(Iterable<AstNode> children) {
    AstRoot r = new AstRoot();
    for (AstNode c : children) {
      if (c != null) {
        r.addChild(c);
      }
    }
    return r;
  }
View Full Code Here

      }
      if (compilationErrorReporter == null) {
        compilationErrorReporter = compilerEnv.getErrorReporter();
      }
      Parser p = new Parser(compilerEnv, compilationErrorReporter);
      AstRoot ast = p.parse(in, file.toString(), 1);
      IRFactory irf = new IRFactory(compilerEnv, compilationErrorReporter);
      ScriptNode tree = irf.transformTree(ast);
      Object[] nameBytesPair = (Object[]) (Object[]) compiler.compile(
          compilerEnv, tree, tree.getEncodedSource(), false);
      String className = (String) nameBytesPair[0];
View Full Code Here

            CompilerEnvirons compilerEnv = new CompilerEnvirons();
            compilerEnv.initFromContext(cx);
            ErrorReporter compilationErrorReporter = compilerEnv
                    .getErrorReporter();
            Parser p = new Parser(compilerEnv, compilationErrorReporter);
            AstRoot ast = p.parse(source.toString(), "<eval>", 1);
            IRFactory irf = new IRFactory(compilerEnv);
            ScriptNode tree = irf.transformTree(ast);

            Codegen codegen = new Codegen();
            codegen.setMainMethodClass(mainMethodClassName);
View Full Code Here

    private void assertSource(String source, String expectedOutput)
    {
        CompilerEnvirons env = new CompilerEnvirons();
        env.setLanguageVersion(Context.VERSION_1_7);
        Parser parser = new Parser(env);
        AstRoot root = parser.parse(source, null, 0);
        Assert.assertEquals(expectedOutput, root.toSource());
    }
View Full Code Here

        Parser p = new Parser(compilerEnv, compilationErrorReporter);
        if (returnFunction) {
            p.calledByCompileFunction = true;
        }
        AstRoot ast;
        if (sourceString != null) {
            ast = p.parse(sourceString, sourceName, lineno);
        } else {
            ast = p.parse(sourceReader, sourceName, lineno);
        }
        if (returnFunction) {
            // parser no longer adds function to script node
            if (!(ast.getFirstChild() != null
                  && ast.getFirstChild().getType() == Token.FUNCTION))
            {
                // XXX: the check just looks for the first child
                // and allows for more nodes after it for compatibility
                // with sources like function() {};;;
                throw new IllegalArgumentException(
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ast.AstRoot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.