Examples of JsProgram


Examples of com.google.gwt.dev.js.ast.JsProgram

    PermProps props = new PermProps(Arrays.asList(
        new BindingProps(new BindingProperty[]{stackMode}, new String[]{"EMULATED"}, config)
    ));

    JsProgram jsProgram = new JsProgram();
    JavaToJavaScriptMap jjsmap = GenerateJavaScriptAST.exec(
        logger, jProgram, jsProgram, context, typeMapper,
        symbolTable, props).getLeft();

    // Finally, run the pass we care about.
View Full Code Here

Examples of com.google.gwt.dev.js.ast.JsProgram

    assertEquals("function a(){}\n;a();a();",
        optimize("function a(){};function b(){} a(); b();"));
  }

  public void testVirtualRemoveDuplicates() throws Exception {
    JsProgram program = new JsProgram();
    String js = "_.method1=function(){};_.method2=function(){};_.method1();_.method2();";
    List<JsStatement> input = JsParser.parse(SourceOrigin.UNKNOWN,
      program.getScope(), new StringReader(js));
    program.getGlobalBlock().getStatements().addAll(input);

    // Mark all functions as if they were translated from Java sources.
    setAllFromJava(program);

    String firstName = new MockNameGenerator().getFreshName();
View Full Code Here

Examples of com.google.gwt.dev.js.ast.JsProgram

  /**
   * Test for one of the bugs causing issue 8284. JsObfuscateNamer was reassigning the same names
   * across different fragments.
   */
  public void testDuplicateNamesWithCodeSplitterError() throws Exception {
    JsProgram program = new JsProgram();
    // Reference to a in .b is to the top level scope a function where the one in _.c is to the
    // local a definition.
    //
    // After deduping _.b and _.c the identifier a in the deduped function points to the top level
    // scope a function and runing a namer afterwards makes the deduping invalid.
    String fragment0js = "_.a=function (){return _.a;}; _.b=function (){return _.a}; _.a();_.b();";
    String fragment1js = "_.c=function (){return _.c;}; _.d=function (){return _.c}; _.c();_.d();";

    List<JsStatement> fragment0 = JsParser.parse(SourceOrigin.UNKNOWN,
        program.getScope(), new StringReader(fragment0js));
    List<JsStatement> fragment1 = JsParser.parse(SourceOrigin.UNKNOWN,
        program.getScope(), new StringReader(fragment1js));
    program.setFragmentCount(2);
    program.getFragmentBlock(0).getStatements().addAll(fragment0);
    program.getFragmentBlock(1).getStatements().addAll(fragment1);

    // Mark all functions as if they were translated from Java sources.
    setAllFromJava(program);

    optimize(program, JsSymbolResolver.class, JsDuplicateFunctionRemoverProxy.class);

    // There should be two distinct dedupped functions here.
    MockNameGenerator tempFreshNameGenerator = new MockNameGenerator();
    String firstName = tempFreshNameGenerator.getFreshName();
    String secondName = tempFreshNameGenerator.getFreshName();

    assertNotNull(program.getScope().findExistingName(secondName));
  }
View Full Code Here

Examples of com.google.gwt.dev.js.ast.JsProgram

   * Test for one of the bugs causing issue 8284. JsObfuscateNamer was used to assign
   * obfuscated names to deduped functions and as a result it might have modified the other names
   * that had been assigned invalidating the irrevocable decision made by the deduper.
   */
  public void testRerunNamerError() throws Exception {
    JsProgram program = new JsProgram();
    // Reference to a in _.b is to the top level scope a function where the one in _.c is to the
    // local a definition.
    //
    // After deduping _.b and _.c the identifier a in the deduped function points to the top level
    // scope a function and runing a namer afterwards makes the deduping invalid.

    // CAVEAT: The two functions that have {return a;} as their bodies are not actually duplicates
    // but we use them to model functions that refer to names at different scopes. Because this
    // optimization only runs on JsFunctions that come from Java source this situation does not
    // happen.
    String js = "var c; function a(){return f1;}; function f1() {_.b = function() {return a;} }; "
        + "function f2() { var a = null; _.c = function() {return a;} };f1();f2();_.b();_.c();";
    List<JsStatement> input = JsParser.parse(SourceOrigin.UNKNOWN,
        program.getScope(), new StringReader(js));
    program.getGlobalBlock().getStatements().addAll(input);

    // Mark all functions as if they were translated from Java sources.
    setAllFromJava(program);

    // Get the JsNames for the top level a and the f2() scoped a.
    JsName topScope_a = program.getScope().findExistingName("a");
    JsName f2_a = null;
    for (JsScope scope : program.getScope().getChildren()) {
      if (scope.toString().startsWith("function f2->")) {
        f2_a = scope.findExistingName("a");
      }
    }

View Full Code Here

Examples of com.google.gwt.dev.js.ast.JsProgram

    assertEquals("function fooLogger(){return 42}\n",
        rename("function fooLogger() { return 42; }"));
  }

  public void testAvoidDuplicatesSameScope() throws Exception {
    JsProgram program = parseJs(
        "function f1(){ return 1 }\n" +
        "function f2(){ return 2 }\n");

    program.getScope().findExistingName("f1").setShortIdent("thing");
    program.getScope().findExistingName("f2").setShortIdent("thing");

    assertEquals(
        "function thing(){return 1}\n" +
        "function thing_0(){return 2}\n",
        rename(program));
View Full Code Here

Examples of com.google.gwt.dev.js.ast.JsProgram

        "function thing_0(){return 2}\n",
        rename(program));
  }

  public void testAvoidDuplicatesChildScope() throws Exception {
    JsProgram program = parseJs(
        "function f1(){\n" +
        "  function f2(){ return 2 }\n" +
        "  return 1\n" +
        "}\n");

    program.getScope().findExistingName("f1").setShortIdent("thing");
    program.getScope().getChildren().get(0).findExistingName("f2").setShortIdent("thing");

    assertEquals("function thing_0(){function thing(){return 2}\nreturn 1}\n",
        rename(program));
  }
View Full Code Here

Examples of org.hisrc.jscm.codemodel.JSProgram

  @Test
  public void programsFactorial() throws IOException {
    // Instantiate the code model
    JSCodeModel codeModel = new CodeModelImpl();
    // Create the program
    JSProgram program = codeModel.program();
    // Add a function declaration
    JSFunctionDeclaration factorial = program
        .functionDeclaration("factorial");
    // Add a function parameter
    JSVariable x = factorial.parameter("x");
    // Create an integer literal
    JSDecimalIntegerLiteral one = codeModel.integer(1);
View Full Code Here

Examples of org.hisrc.jscm.codemodel.JSProgram

  public void allExpressions() throws IOException {

    final CodeWriter out = new CodeWriter(System.out);
    JSCodeModel codeModel = new CodeModelImpl();

    JSProgram program = codeModel.program();
   
    program._if(codeModel._boolean(true))._then().block()._return();
    program._if(codeModel._boolean(false))._then().block()._return();
   
    out.program(program);
  }
View Full Code Here

Examples of org.hisrc.jscm.codemodel.JSProgram

  public void allExpressions() throws IOException {

    final CodeWriter out = new CodeWriter(System.out);
    JSCodeModel codeModel = new CodeModelImpl();

    JSProgram program = codeModel.program();
    JSFunctionDeclaration f = program.functionDeclaration("f");

    JSVariable x = f.parameter("x");
    JSVariable y = f.parameter("y");

    JSFunctionBody body = f.getBody();
View Full Code Here

Examples of org.hisrc.jscm.codemodel.JSProgram

  public void allExpressions() throws IOException {

    final CodeWriter out = new CodeWriter(System.out);
    JSCodeModel codeModel = new CodeModelImpl();

    JSProgram program = codeModel.program();
    program.empty();
    JSGlobalVariable window = codeModel.globalVariable("window");
    JSGlobalVariable window1 = codeModel.globalVariable("window");
    Assert.assertSame(window, window1);

    JSFunctionDeclaration f = program.functionDeclaration("f");

    JSVariable x = f.parameter("x");
    JSVariable y = f.parameter("y");

    JSFunctionBody body = f.getBody();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.