Debian Codegraph @

test/com/google/javascript/jscomp/OptimizeCallsTest.java

raw symbols SCIP
1 /*
2 * Copyright 2011 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package com.google.javascript.jscomp;
19
20 import com.google.javascript.rhino.Node;
21
22 /**
23 * Unit tests for {#link {@link OptimizeCalls}
24 *
25 */
26 public class OptimizeCallsTest extends CompilerTestCase {
27
28 @Override
29 protected CompilerPass getProcessor(final Compiler compiler) {
30 final OptimizeCalls passes = new OptimizeCalls(compiler);
31 passes.addPass(new OptimizeReturns(compiler));
32 passes.addPass(new OptimizeParameters(compiler));
33 passes.addPass(new RemoveUnusedVars(compiler, true, false, true));
34 return new CompilerPass() {
35
36 @Override
37 public void process(Node externs, Node root) {
38 new PureFunctionIdentifier(compiler,
39 new SimpleDefinitionFinder(compiler)).process(externs, root);
40 passes.process(externs, root);
41 }
42 };
43 }
44
45 public void testRemovingReturnCallToFunctionWithUnusedParams() {
46 test("function foo() {var x; return x = bar(1)} foo(); function bar(x) {}",
47 "function foo() { bar(); return;} foo(); function bar() {}");
48 }
49
50 public void testNestingFunctionCallWithUnsedParams() {
51 test("function f1(x) { } function f2(x) { }" +
52 "function f3(x) { } function f4(x) { }" +
53 "f3(f1(f2()));",
54 "function f1() {f2()} function f2() { }" +
55 "function f3() {f1()} " +
56 "f3();"
57 );
58 }
59
60 public void testUnusedAssignOnFunctionWithUnusedParams() {
61 test("var foo = function(a){}; function bar(){var x;x = foo} bar(); foo(1)",
62 "var foo = function( ){}; function bar(){ } bar(); foo()");
63 }
64 }