|
10 | 10 | import org.junit.jupiter.api.Test; |
11 | 11 | import org.mozilla.javascript.Parser; |
12 | 12 | import org.mozilla.javascript.ast.AstNode; |
| 13 | +import org.mozilla.javascript.ast.Block; |
13 | 14 | import org.mozilla.javascript.ast.FunctionNode; |
14 | 15 | import org.mozilla.javascript.ast.NodeVisitor; |
15 | 16 | import org.mozilla.javascript.ast.ReturnStatement; |
@@ -77,4 +78,60 @@ public void arrowFnEvalToString() { |
77 | 78 | String source = "eval(\"()=>this\").toString()"; |
78 | 79 | Utils.assertWithAllModes("()=>this", source); |
79 | 80 | } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testArrowRhinoWithLineEndingOnlyThis() { |
| 84 | + FunctionNode arrowFn = parseAndExtractArrowFn("()=>this"); |
| 85 | + |
| 86 | + assertEquals(0, arrowFn.getPosition()); |
| 87 | + assertEquals(0, arrowFn.getAbsolutePosition()); |
| 88 | + assertEquals(8, arrowFn.getLength()); |
| 89 | + |
| 90 | + Block body = (Block) arrowFn.getBody(); |
| 91 | + assertEquals(4, body.getPosition()); |
| 92 | + assertEquals(4, body.getAbsolutePosition()); |
| 93 | + assertEquals(4, body.getLength()); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testArrowRhinoWithLineEndingOnlyThisNl() { |
| 98 | + FunctionNode arrowFn = parseAndExtractArrowFn("()=>this\n"); |
| 99 | + |
| 100 | + assertEquals(0, arrowFn.getPosition()); |
| 101 | + assertEquals(0, arrowFn.getAbsolutePosition()); |
| 102 | + assertEquals(8, arrowFn.getLength()); |
| 103 | + |
| 104 | + Block body = (Block) arrowFn.getBody(); |
| 105 | + assertEquals(4, body.getPosition()); |
| 106 | + assertEquals(4, body.getAbsolutePosition()); |
| 107 | + assertEquals(4, body.getLength()); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testArrowRhinoWithLineEndingThisWithProperty() { |
| 112 | + FunctionNode arrowFn = parseAndExtractArrowFn("()=>this.xs"); |
| 113 | + |
| 114 | + assertEquals(0, arrowFn.getPosition()); |
| 115 | + assertEquals(0, arrowFn.getAbsolutePosition()); |
| 116 | + assertEquals(11, arrowFn.getLength()); |
| 117 | + |
| 118 | + Block body = (Block) arrowFn.getBody(); |
| 119 | + assertEquals(4, body.getPosition()); |
| 120 | + assertEquals(4, body.getAbsolutePosition()); |
| 121 | + assertEquals(7, body.getLength()); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void testArrowRhinoWithLineEndingThisWithPropertyNl() { |
| 126 | + FunctionNode arrowFn = parseAndExtractArrowFn("()=>this.xs\n"); |
| 127 | + |
| 128 | + assertEquals(0, arrowFn.getPosition()); |
| 129 | + assertEquals(0, arrowFn.getAbsolutePosition()); |
| 130 | + assertEquals(11, arrowFn.getLength()); |
| 131 | + |
| 132 | + Block body = (Block) arrowFn.getBody(); |
| 133 | + assertEquals(4, body.getPosition()); |
| 134 | + assertEquals(4, body.getAbsolutePosition()); |
| 135 | + assertEquals(7, body.getLength()); |
| 136 | + } |
80 | 137 | } |
0 commit comments