| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
|
| 20 |
public class RemoveTryCatchTest extends CompilerTestCase { |
| 21 |
|
| 22 |
public RemoveTryCatchTest() { |
| 23 |
|
| 24 |
super("", false); |
| 25 |
} |
| 26 |
|
| 27 |
@Override public CompilerPass getProcessor(Compiler compiler) { |
| 28 |
return new RemoveTryCatch(compiler); |
| 29 |
} |
| 30 |
|
| 31 |
@Override public int getNumRepetitions() { |
| 32 |
|
| 33 |
return 1; |
| 34 |
} |
| 35 |
|
| 36 |
public void testRemoveTryCatch() { |
| 37 |
test("try{var a=1;}catch(ex){var b=2;}", |
| 38 |
"var b;var a=1"); |
| 39 |
test("try{var a=1;var b=2}catch(ex){var c=3;var d=4;}", |
| 40 |
"var d;var c;var a=1;var b=2"); |
| 41 |
test("try{var a=1;var b=2}catch(ex){}", |
| 42 |
"var a=1;var b=2"); |
| 43 |
} |
| 44 |
|
| 45 |
public void testRemoveTryFinally() { |
| 46 |
test("try{var a=1;}finally{var c=3;}", |
| 47 |
"var a=1;var c=3"); |
| 48 |
test("try{var a=1;var b=2}finally{var e=5;var f=6;}", |
| 49 |
"var a=1;var b=2;var e=5;var f=6"); |
| 50 |
} |
| 51 |
|
| 52 |
public void testRemoveTryCatchFinally() { |
| 53 |
test("try{var a=1;}catch(ex){var b=2;}finally{var c=3;}", |
| 54 |
"var b;var a=1;var c=3"); |
| 55 |
test("try{var a=1;var b=2}catch(ex){var c=3;var d=4;}finally{var e=5;" + |
| 56 |
"var f=6;}", |
| 57 |
"var d;var c;var a=1;var b=2;var e=5;var f=6"); |
| 58 |
} |
| 59 |
|
| 60 |
public void testPreserveTryBlockContainingReturnStatement() { |
| 61 |
testSame("function f(){var a;try{a=1;return}finally{a=2}}"); |
| 62 |
} |
| 63 |
|
| 64 |
public void testPreserveAnnotatedTryBlock() { |
| 65 |
test("/** @preserveTry */try{var a=1;}catch(ex){var b=2;}", |
| 66 |
"try{var a=1}catch(ex){var b=2}"); |
| 67 |
} |
| 68 |
|
| 69 |
public void testIfTryFinally() { |
| 70 |
test("if(x)try{y}finally{z}", "if(x){y;z}"); |
| 71 |
} |
| 72 |
|
| 73 |
public void testIfTryCatch() { |
| 74 |
test("if(x)try{y;z}catch(e){}", "if(x){y;z}"); |
| 75 |
} |
| 76 |
} |