| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import com.google.common.collect.Lists; |
| 20 |
import com.google.common.collect.Sets; |
| 21 |
import com.google.javascript.jscomp.AbstractCompiler.LifeCycleStage; |
| 22 |
import com.google.javascript.jscomp.FunctionInjector.CanInlineResult; |
| 23 |
import com.google.javascript.jscomp.FunctionInjector.InliningMode; |
| 24 |
import com.google.javascript.jscomp.NodeTraversal.Callback; |
| 25 |
import com.google.javascript.rhino.Node; |
| 26 |
import junit.framework.TestCase; |
| 27 |
|
| 28 |
import java.util.List; |
| 29 |
import java.util.Set; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class FunctionInjectorTest extends TestCase { |
| 37 |
static final InliningMode INLINE_DIRECT = InliningMode.DIRECT; |
| 38 |
static final InliningMode INLINE_BLOCK = InliningMode.BLOCK; |
| 39 |
private boolean assumeStrictThis = false; |
| 40 |
private boolean assumeMinimumCapture = false; |
| 41 |
|
| 42 |
@Override |
| 43 |
protected void setUp() throws Exception { |
| 44 |
super.setUp(); |
| 45 |
assumeStrictThis = false; |
| 46 |
} |
| 47 |
|
| 48 |
private FunctionInjector getInjector() { |
| 49 |
Compiler compiler = new Compiler(); |
| 50 |
return new FunctionInjector( |
| 51 |
compiler, compiler.getUniqueNameIdSupplier(), true, |
| 52 |
assumeStrictThis, assumeMinimumCapture); |
| 53 |
} |
| 54 |
|
| 55 |
public void testIsSimpleFunction1() { |
| 56 |
assertTrue(getInjector().isDirectCallNodeReplacementPossible( |
| 57 |
prep("function f(){}"))); |
| 58 |
} |
| 59 |
|
| 60 |
public void testIsSimpleFunction2() { |
| 61 |
assertTrue(getInjector().isDirectCallNodeReplacementPossible( |
| 62 |
prep("function f(){return 0;}"))); |
| 63 |
} |
| 64 |
|
| 65 |
public void testIsSimpleFunction3() { |
| 66 |
assertTrue(getInjector().isDirectCallNodeReplacementPossible( |
| 67 |
prep("function f(){return x ? 0 : 1}"))); |
| 68 |
} |
| 69 |
|
| 70 |
public void testIsSimpleFunction4() { |
| 71 |
assertFalse(getInjector().isDirectCallNodeReplacementPossible( |
| 72 |
prep("function f(){return;}"))); |
| 73 |
} |
| 74 |
|
| 75 |
public void testIsSimpleFunction5() { |
| 76 |
assertFalse(getInjector().isDirectCallNodeReplacementPossible( |
| 77 |
prep("function f(){return 0; return 0;}"))); |
| 78 |
} |
| 79 |
|
| 80 |
public void testIsSimpleFunction6() { |
| 81 |
assertFalse(getInjector().isDirectCallNodeReplacementPossible( |
| 82 |
prep("function f(){var x=true;return x ? 0 : 1}"))); |
| 83 |
} |
| 84 |
|
| 85 |
public void testIsSimpleFunction7() { |
| 86 |
assertFalse(getInjector().isDirectCallNodeReplacementPossible( |
| 87 |
prep("function f(){if (x) return 0; else return 1}"))); |
| 88 |
} |
| 89 |
|
| 90 |
public void testCanInlineReferenceToFunction1() { |
| 91 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 92 |
"function foo(){}; foo();", "foo", INLINE_DIRECT); |
| 93 |
} |
| 94 |
|
| 95 |
public void testCanInlineReferenceToFunction2() { |
| 96 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 97 |
"function foo(){}; foo();", "foo", INLINE_BLOCK); |
| 98 |
} |
| 99 |
|
| 100 |
public void testCanInlineReferenceToFunction3() { |
| 101 |
|
| 102 |
|
| 103 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 104 |
"function foo(){return;}; foo();", "foo", INLINE_DIRECT); |
| 105 |
} |
| 106 |
|
| 107 |
public void testCanInlineReferenceToFunction4() { |
| 108 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 109 |
"function foo(){return;}; foo();", "foo", INLINE_BLOCK); |
| 110 |
} |
| 111 |
|
| 112 |
public void testCanInlineReferenceToFunction5() { |
| 113 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 114 |
"function foo(){return true;}; foo();", "foo", INLINE_DIRECT); |
| 115 |
} |
| 116 |
|
| 117 |
public void testCanInlineReferenceToFunction6() { |
| 118 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 119 |
"function foo(){return true;}; foo();", "foo", INLINE_BLOCK); |
| 120 |
} |
| 121 |
|
| 122 |
public void testCanInlineReferenceToFunction7() { |
| 123 |
|
| 124 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 125 |
"function foo(){return true;}; var x=foo();", "foo", INLINE_DIRECT); |
| 126 |
} |
| 127 |
|
| 128 |
public void testCanInlineReferenceToFunction8() { |
| 129 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 130 |
"function foo(){return true;}; var x=foo();", "foo", INLINE_BLOCK); |
| 131 |
} |
| 132 |
|
| 133 |
public void testCanInlineReferenceToFunction9() { |
| 134 |
|
| 135 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 136 |
"function foo(){return true;}; var x; x=foo();", "foo", INLINE_DIRECT); |
| 137 |
} |
| 138 |
|
| 139 |
public void testCanInlineReferenceToFunction10() { |
| 140 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 141 |
"function foo(){return true;}; var x; x=foo();", "foo", INLINE_BLOCK); |
| 142 |
} |
| 143 |
|
| 144 |
public void testCanInlineReferenceToFunction11() { |
| 145 |
|
| 146 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 147 |
"function foo(){return true;}; var x; x=x+foo();", "foo", |
| 148 |
INLINE_DIRECT); |
| 149 |
} |
| 150 |
|
| 151 |
public void testCanInlineReferenceToFunction12() { |
| 152 |
|
| 153 |
|
| 154 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 155 |
"function foo(){return true;}; var x; x=x+foo();", "foo", INLINE_BLOCK); |
| 156 |
} |
| 157 |
|
| 158 |
public void testCanInlineReferenceToFunction12b() { |
| 159 |
|
| 160 |
|
| 161 |
helperCanInlineReferenceToFunction( |
| 162 |
CanInlineResult.AFTER_PREPARATION, |
| 163 |
"function foo(){return true;}; var x; x=x+foo();", |
| 164 |
"foo", INLINE_BLOCK, true); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public void testCanInlineReferenceToFunction14() { |
| 176 |
|
| 177 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 178 |
"function foo(a){return true;}; foo(x);", "foo", INLINE_DIRECT); |
| 179 |
} |
| 180 |
|
| 181 |
public void testCanInlineReferenceToFunction15() { |
| 182 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 183 |
"function foo(a){return true;}; foo(x);", "foo", INLINE_BLOCK); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
static final CanInlineResult NEW_VARS_IN_GLOBAL_SCOPE = |
| 189 |
CanInlineResult.YES; |
| 190 |
|
| 191 |
public void testCanInlineReferenceToFunction16() { |
| 192 |
|
| 193 |
|
| 194 |
helperCanInlineReferenceToFunction(NEW_VARS_IN_GLOBAL_SCOPE, |
| 195 |
"function foo(a){var b;return a;}; foo(goo());", "foo", INLINE_BLOCK); |
| 196 |
} |
| 197 |
|
| 198 |
public void testCanInlineReferenceToFunction17() { |
| 199 |
|
| 200 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 201 |
"function foo(a){return a;}; " + |
| 202 |
"function x() { foo(goo()); }", |
| 203 |
"foo", INLINE_BLOCK); |
| 204 |
} |
| 205 |
|
| 206 |
public void testCanInlineReferenceToFunction18() { |
| 207 |
|
| 208 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 209 |
"function foo(a){return a;} foo(x++);", "foo", INLINE_DIRECT); |
| 210 |
} |
| 211 |
|
| 212 |
public void testCanInlineReferenceToFunction19() { |
| 213 |
|
| 214 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 215 |
"function foo(a){return a+a} foo([]);", "foo", INLINE_DIRECT); |
| 216 |
} |
| 217 |
|
| 218 |
public void testCanInlineReferenceToFunction20() { |
| 219 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 220 |
"function foo(a){return a+a} foo({});", "foo", INLINE_DIRECT); |
| 221 |
} |
| 222 |
|
| 223 |
public void testCanInlineReferenceToFunction21() { |
| 224 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 225 |
"function foo(a){return a+a} foo(new Date);", "foo", INLINE_DIRECT); |
| 226 |
} |
| 227 |
|
| 228 |
public void testCanInlineReferenceToFunction22() { |
| 229 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 230 |
"function foo(a){return a+a} foo(true && new Date);", "foo", |
| 231 |
INLINE_DIRECT); |
| 232 |
} |
| 233 |
|
| 234 |
public void testCanInlineReferenceToFunction23() { |
| 235 |
|
| 236 |
helperCanInlineReferenceToFunction(NEW_VARS_IN_GLOBAL_SCOPE, |
| 237 |
"function foo(a){return a;}; foo(x++);", "foo", INLINE_BLOCK); |
| 238 |
} |
| 239 |
|
| 240 |
public void testCanInlineReferenceToFunction24() { |
| 241 |
|
| 242 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 243 |
"function foo(a){return a;}; " + |
| 244 |
"function x() { foo(x++); }", |
| 245 |
"foo", INLINE_BLOCK); |
| 246 |
} |
| 247 |
|
| 248 |
public void testCanInlineReferenceToFunction25() { |
| 249 |
|
| 250 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 251 |
"function foo(a){return a+a;}; foo(x++);", "foo", INLINE_DIRECT); |
| 252 |
} |
| 253 |
|
| 254 |
public void testCanInlineReferenceToFunction26() { |
| 255 |
helperCanInlineReferenceToFunction(NEW_VARS_IN_GLOBAL_SCOPE, |
| 256 |
"function foo(a){return a+a;}; foo(x++);", "foo", INLINE_BLOCK); |
| 257 |
} |
| 258 |
|
| 259 |
public void testCanInlineReferenceToFunction27() { |
| 260 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 261 |
"function foo(a){return a+a;}; " + |
| 262 |
"function x() { foo(x++); }", |
| 263 |
"foo", INLINE_BLOCK); |
| 264 |
} |
| 265 |
|
| 266 |
public void testCanInlineReferenceToFunction28() { |
| 267 |
|
| 268 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 269 |
"function foo(a){return true;}; foo(goo());", "foo", INLINE_DIRECT); |
| 270 |
} |
| 271 |
|
| 272 |
public void testCanInlineReferenceToFunction29() { |
| 273 |
helperCanInlineReferenceToFunction(NEW_VARS_IN_GLOBAL_SCOPE, |
| 274 |
"function foo(a){return true;}; foo(goo());", "foo", INLINE_BLOCK); |
| 275 |
} |
| 276 |
|
| 277 |
public void testCanInlineReferenceToFunction30() { |
| 278 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 279 |
"function foo(a){return true;}; " + |
| 280 |
"function x() { foo(goo()); }", |
| 281 |
"foo", INLINE_BLOCK); |
| 282 |
} |
| 283 |
|
| 284 |
public void testCanInlineReferenceToFunction31() { |
| 285 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 286 |
"function foo(a) {return true;}; " + |
| 287 |
"function x() {foo.call(this, 1);}", |
| 288 |
"foo", INLINE_DIRECT); |
| 289 |
} |
| 290 |
|
| 291 |
public void testCanInlineReferenceToFunction32() { |
| 292 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 293 |
"function foo(a){return true;}; " + |
| 294 |
"function x() { foo.apply(this, [1]); }", |
| 295 |
"foo", INLINE_DIRECT); |
| 296 |
} |
| 297 |
|
| 298 |
public void testCanInlineReferenceToFunction33() { |
| 299 |
|
| 300 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 301 |
"function foo(a){return true;}; " + |
| 302 |
"function x() { foo.bar(this, 1); }", |
| 303 |
"foo", INLINE_DIRECT); |
| 304 |
} |
| 305 |
|
| 306 |
public void testCanInlineReferenceToFunction34() { |
| 307 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 308 |
"function foo(a){return true;}; " + |
| 309 |
"function x() { foo.call(this, goo()); }", |
| 310 |
"foo", INLINE_BLOCK); |
| 311 |
} |
| 312 |
|
| 313 |
public void testCanInlineReferenceToFunction35() { |
| 314 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 315 |
"function foo(a){return true;}; " + |
| 316 |
"function x() { foo.apply(this, goo()); }", |
| 317 |
"foo", INLINE_BLOCK); |
| 318 |
} |
| 319 |
|
| 320 |
public void testCanInlineReferenceToFunction36() { |
| 321 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 322 |
"function foo(a){return true;}; " + |
| 323 |
"function x() { foo.bar(this, goo()); }", |
| 324 |
"foo", INLINE_BLOCK); |
| 325 |
} |
| 326 |
|
| 327 |
public void testCanInlineReferenceToFunction37() { |
| 328 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 329 |
"function foo(a){return true;}; " + |
| 330 |
"function x() { foo.call(null, 1); }", |
| 331 |
"foo", INLINE_DIRECT); |
| 332 |
} |
| 333 |
|
| 334 |
public void testCanInlineReferenceToFunction38() { |
| 335 |
assumeStrictThis = false; |
| 336 |
|
| 337 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 338 |
"function foo(a){return true;}; " + |
| 339 |
"function x() { foo.call(null, goo()); }", |
| 340 |
"foo", INLINE_BLOCK); |
| 341 |
|
| 342 |
assumeStrictThis = true; |
| 343 |
|
| 344 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 345 |
"function foo(a){return true;}; " + |
| 346 |
"function x() { foo.call(null, goo()); }", |
| 347 |
"foo", INLINE_BLOCK); |
| 348 |
} |
| 349 |
|
| 350 |
public void testCanInlineReferenceToFunction39() { |
| 351 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 352 |
"function foo(a){return true;}; " + |
| 353 |
"function x() { foo.call(bar, 1); }", |
| 354 |
"foo", INLINE_DIRECT); |
| 355 |
} |
| 356 |
|
| 357 |
public void testCanInlineReferenceToFunction40() { |
| 358 |
assumeStrictThis = false; |
| 359 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 360 |
"function foo(a){return true;}; " + |
| 361 |
"function x() { foo.call(bar, goo()); }", |
| 362 |
"foo", INLINE_BLOCK); |
| 363 |
|
| 364 |
assumeStrictThis = true; |
| 365 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 366 |
"function foo(a){return true;}; " + |
| 367 |
"function x() { foo.call(bar, goo()); }", |
| 368 |
"foo", INLINE_BLOCK); |
| 369 |
} |
| 370 |
|
| 371 |
public void testCanInlineReferenceToFunction41() { |
| 372 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 373 |
"function foo(a){return true;}; " + |
| 374 |
"function x() { foo.call(new bar(), 1); }", |
| 375 |
"foo", INLINE_DIRECT); |
| 376 |
} |
| 377 |
|
| 378 |
public void testCanInlineReferenceToFunction42() { |
| 379 |
assumeStrictThis = false; |
| 380 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 381 |
"function foo(a){return true;}; " + |
| 382 |
"function x() { foo.call(new bar(), goo()); }", |
| 383 |
"foo", INLINE_BLOCK); |
| 384 |
|
| 385 |
assumeStrictThis = true; |
| 386 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 387 |
"function foo(a){return true;}; " + |
| 388 |
"function x() { foo.call(new bar(), goo()); }", |
| 389 |
"foo", INLINE_BLOCK); |
| 390 |
} |
| 391 |
|
| 392 |
public void testCanInlineReferenceToFunction43() { |
| 393 |
|
| 394 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 395 |
"function foo(){return true;}; " + |
| 396 |
"function x() { foo.call(); }", |
| 397 |
"foo", INLINE_DIRECT); |
| 398 |
} |
| 399 |
|
| 400 |
public void testCanInlineReferenceToFunction44() { |
| 401 |
assumeStrictThis = false; |
| 402 |
|
| 403 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 404 |
"function foo(){return true;}; " + |
| 405 |
"function x() { foo.call(); }", |
| 406 |
"foo", INLINE_BLOCK); |
| 407 |
|
| 408 |
assumeStrictThis = true; |
| 409 |
|
| 410 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 411 |
"function foo(){return true;}; " + |
| 412 |
"function x() { foo.call(); }", |
| 413 |
"foo", INLINE_BLOCK); |
| 414 |
} |
| 415 |
|
| 416 |
public void testCanInlineReferenceToFunction45() { |
| 417 |
|
| 418 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 419 |
"function foo(){return function() {return true;}}; foo();", |
| 420 |
"foo", INLINE_DIRECT); |
| 421 |
} |
| 422 |
|
| 423 |
public void testCanInlineReferenceToFunction46() { |
| 424 |
|
| 425 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 426 |
"function foo(){return function() {return true;}}; foo();", |
| 427 |
"foo", INLINE_BLOCK); |
| 428 |
} |
| 429 |
|
| 430 |
public void testCanInlineReferenceToFunction47() { |
| 431 |
|
| 432 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 433 |
"function foo(){var a; return function() {return true;}}; foo();", |
| 434 |
"foo", INLINE_DIRECT); |
| 435 |
} |
| 436 |
|
| 437 |
public void testCanInlineReferenceToFunction48() { |
| 438 |
|
| 439 |
|
| 440 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 441 |
"function foo(){var a; return function() {return true;}}; foo();", |
| 442 |
"foo", INLINE_BLOCK); |
| 443 |
} |
| 444 |
|
| 445 |
public void testCanInlineReferenceToFunction49() { |
| 446 |
|
| 447 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 448 |
"function foo(){return function() {var a; return true;}}; foo();", |
| 449 |
"foo", INLINE_DIRECT); |
| 450 |
} |
| 451 |
|
| 452 |
public void testCanInlineReferenceToFunction50() { |
| 453 |
|
| 454 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 455 |
"function foo(){return function() {var a; return true;}}; foo();", |
| 456 |
"foo", INLINE_BLOCK); |
| 457 |
} |
| 458 |
|
| 459 |
public void testCanInlineReferenceToFunction51() { |
| 460 |
|
| 461 |
helperCanInlineReferenceToFunction(CanInlineResult.YES, |
| 462 |
"function foo(){function x() {var a; return true;} return x}; foo();", |
| 463 |
"foo", INLINE_BLOCK); |
| 464 |
} |
| 465 |
|
| 466 |
public void testCanInlineReferenceToFunctionInExpression1() { |
| 467 |
|
| 468 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 469 |
"function foo(a){return true;}; " + |
| 470 |
"function x() { if (foo(1)) throw 'test'; }", |
| 471 |
"foo", INLINE_BLOCK, true); |
| 472 |
} |
| 473 |
|
| 474 |
public void testCanInlineReferenceToFunctionInExpression2() { |
| 475 |
|
| 476 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 477 |
"function foo(a){return true;}; " + |
| 478 |
"function x() { return foo(1); }", |
| 479 |
"foo", INLINE_BLOCK, true); |
| 480 |
} |
| 481 |
|
| 482 |
public void testCanInlineReferenceToFunctionInExpression3() { |
| 483 |
|
| 484 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 485 |
"function foo(a){return true;}; " + |
| 486 |
"function x() { switch(foo(1)) { default:break; } }", |
| 487 |
"foo", INLINE_BLOCK, true); |
| 488 |
} |
| 489 |
|
| 490 |
public void testCanInlineReferenceToFunctionInExpression4() { |
| 491 |
|
| 492 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 493 |
"function foo(a){return true;}; " + |
| 494 |
"function x() {foo(1)?0:1 }", |
| 495 |
"foo", INLINE_BLOCK, true); |
| 496 |
} |
| 497 |
|
| 498 |
public void testCanInlineReferenceToFunctionInExpression5() { |
| 499 |
|
| 500 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 501 |
"function foo(a){return true;}; " + |
| 502 |
"function x() {true?foo(1):1 }", |
| 503 |
"foo", INLINE_BLOCK); |
| 504 |
} |
| 505 |
|
| 506 |
public void testCanInlineReferenceToFunctionInExpression5a() { |
| 507 |
|
| 508 |
helperCanInlineReferenceToFunction( |
| 509 |
CanInlineResult.AFTER_PREPARATION, |
| 510 |
"function foo(a){return true;}; " + |
| 511 |
"function x() {true?foo(1):1 }", |
| 512 |
"foo", INLINE_BLOCK, true); |
| 513 |
} |
| 514 |
|
| 515 |
public void testCanInlineReferenceToFunctionInExpression6() { |
| 516 |
|
| 517 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 518 |
"function foo(a){return true;}; " + |
| 519 |
"function x() {foo(1) && 1 }", |
| 520 |
"foo", INLINE_BLOCK, true); |
| 521 |
} |
| 522 |
|
| 523 |
public void testCanInlineReferenceToFunctionInExpression7() { |
| 524 |
|
| 525 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 526 |
"function foo(a){return true;}; " + |
| 527 |
"function x() {1 && foo(1) }", |
| 528 |
"foo", INLINE_BLOCK); |
| 529 |
} |
| 530 |
|
| 531 |
public void testCanInlineReferenceToFunctionInExpression7a() { |
| 532 |
|
| 533 |
helperCanInlineReferenceToFunction( |
| 534 |
CanInlineResult.AFTER_PREPARATION, |
| 535 |
"function foo(a){return true;}; " + |
| 536 |
"function x() {1 && foo(1) }", |
| 537 |
"foo", INLINE_BLOCK, true); |
| 538 |
} |
| 539 |
|
| 540 |
public void testCanInlineReferenceToFunctionInExpression8() { |
| 541 |
|
| 542 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 543 |
"function foo(a){return true;}; " + |
| 544 |
"function x() {1 + foo(1) }", |
| 545 |
"foo", INLINE_BLOCK, true); |
| 546 |
} |
| 547 |
|
| 548 |
public void testCanInlineReferenceToFunctionInExpression9() { |
| 549 |
|
| 550 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 551 |
"function foo(a){return true;}; " + |
| 552 |
"function x() {var b = 1 + foo(1)}", |
| 553 |
"foo", INLINE_BLOCK, true); |
| 554 |
} |
| 555 |
|
| 556 |
public void testCanInlineReferenceToFunctionInExpression10() { |
| 557 |
|
| 558 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 559 |
"function foo(a){return true;}; " + |
| 560 |
"function x() {var b; b += 1 + foo(1) }", |
| 561 |
"foo", INLINE_BLOCK); |
| 562 |
} |
| 563 |
|
| 564 |
public void testCanInlineReferenceToFunctionInExpression10a() { |
| 565 |
|
| 566 |
helperCanInlineReferenceToFunction( |
| 567 |
CanInlineResult.AFTER_PREPARATION, |
| 568 |
"function foo(a){return true;}; " + |
| 569 |
"function x() {var b; b += 1 + foo(1) }", |
| 570 |
"foo", INLINE_BLOCK, true); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
public void testCanInlineReferenceToFunctionInExpression12() { |
| 582 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 583 |
"function foo(a){return true;}; " + |
| 584 |
"function x() {var a,b,c; a = b = c = foo(1) }", |
| 585 |
"foo", INLINE_BLOCK, true); |
| 586 |
} |
| 587 |
|
| 588 |
public void testCanInlineReferenceToFunctionInExpression13() { |
| 589 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 590 |
"function foo(a){return true;}; " + |
| 591 |
"function x() {var a,b,c; a = b = c = 1 + foo(1) }", |
| 592 |
"foo", INLINE_BLOCK, true); |
| 593 |
} |
| 594 |
|
| 595 |
public void testCanInlineReferenceToFunctionInExpression14() { |
| 596 |
|
| 597 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 598 |
"var a = {}, b = {}, c;" + |
| 599 |
"a.test = 'a';" + |
| 600 |
"b.test = 'b';" + |
| 601 |
"c = a;" + |
| 602 |
"function foo(){c = b; return 'foo'};" + |
| 603 |
"c.test=foo();", |
| 604 |
"foo", INLINE_BLOCK); |
| 605 |
} |
| 606 |
|
| 607 |
public void testCanInlineReferenceToFunctionInExpression14a() { |
| 608 |
|
| 609 |
helperCanInlineReferenceToFunction( |
| 610 |
CanInlineResult.AFTER_PREPARATION, |
| 611 |
"var a = {}, b = {}, c;" + |
| 612 |
"a.test = 'a';" + |
| 613 |
"b.test = 'b';" + |
| 614 |
"c = a;" + |
| 615 |
"function foo(){c = b; return 'foo'};" + |
| 616 |
"c.test=foo();", |
| 617 |
"foo", INLINE_BLOCK, true); |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public void testCanInlineReferenceToFunctionInExpression18() { |
| 660 |
|
| 661 |
helperCanInlineReferenceToFunction(CanInlineResult.AFTER_PREPARATION, |
| 662 |
"function foo(){return _g();}; " + |
| 663 |
"function x() {1 + foo()() }", |
| 664 |
"foo", INLINE_BLOCK, true); |
| 665 |
} |
| 666 |
|
| 667 |
public void testCanInlineReferenceToFunctionInExpression19() { |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 672 |
"function foo(){return a;}; " + |
| 673 |
"function x() {1 + _g(foo()) }", |
| 674 |
"foo", INLINE_BLOCK); |
| 675 |
} |
| 676 |
|
| 677 |
public void testCanInlineReferenceToFunctionInExpression19a() { |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
helperCanInlineReferenceToFunction( |
| 682 |
CanInlineResult.AFTER_PREPARATION, |
| 683 |
"function foo(){return a;}; " + |
| 684 |
"function x() {1 + _g(foo()) }", |
| 685 |
"foo", INLINE_BLOCK, true); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
public void testCanInlineReferenceToFunctionInExpression21() { |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 702 |
"var z = {};" + |
| 703 |
"function foo(a){z = {};return true;}; " + |
| 704 |
"function x() { z.gack = foo(1) }", |
| 705 |
"foo", INLINE_BLOCK); |
| 706 |
} |
| 707 |
|
| 708 |
public void testCanInlineReferenceToFunctionInExpression21a() { |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
helperCanInlineReferenceToFunction( |
| 714 |
CanInlineResult.AFTER_PREPARATION, |
| 715 |
"var z = {};" + |
| 716 |
"function foo(a){z = {};return true;}; " + |
| 717 |
"function x() { z.gack = foo(1) }", |
| 718 |
"foo", INLINE_BLOCK, true); |
| 719 |
} |
| 720 |
|
| 721 |
public void testCanInlineReferenceToFunctionInExpression22() { |
| 722 |
|
| 723 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 724 |
"function foo(){return a;}; " + |
| 725 |
"function x() {1 + _g(_a(), foo()) }", |
| 726 |
"foo", INLINE_BLOCK); |
| 727 |
} |
| 728 |
|
| 729 |
public void testCanInlineReferenceToFunctionInExpression22a() { |
| 730 |
|
| 731 |
helperCanInlineReferenceToFunction( |
| 732 |
CanInlineResult.AFTER_PREPARATION, |
| 733 |
"function foo(){return a;}; " + |
| 734 |
"function x() {1 + _g(_a(), foo()) }", |
| 735 |
"foo", INLINE_BLOCK, true); |
| 736 |
} |
| 737 |
|
| 738 |
public void testCanInlineReferenceToFunctionInExpression23() { |
| 739 |
|
| 740 |
helperCanInlineReferenceToFunction(CanInlineResult.NO, |
| 741 |
"function foo(){return a;}; " + |
| 742 |
"function x() {1 + _g(_a(), foo.call(this)) }", |
| 743 |
"foo", INLINE_BLOCK); |
| 744 |
} |
| 745 |
|
| 746 |
public void testCanInlineReferenceToFunctionInExpression23a() { |
| 747 |
|
| 748 |
helperCanInlineReferenceToFunction( |
| 749 |
CanInlineResult.AFTER_PREPARATION, |
| 750 |
"function foo(){return a;}; " + |
| 751 |
"function x() {1 + _g(_a(), foo.call(this)) }", |
| 752 |
"foo", INLINE_BLOCK, true); |
| 753 |
} |
| 754 |
|
| 755 |
public void testCanInlineReferenceToFunctionInLoop1() { |
| 756 |
helperCanInlineReferenceToFunction( |
| 757 |
CanInlineResult.YES, |
| 758 |
"function foo(){return a;}; " + |
| 759 |
"while(1) { foo(); }", |
| 760 |
"foo", INLINE_BLOCK, true); |
| 761 |
} |
| 762 |
|
| 763 |
public void testCanInlineReferenceToFunctionInLoop2() { |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
helperCanInlineReferenceToFunction( |
| 769 |
CanInlineResult.NO, |
| 770 |
"function foo(){return function() {};}; " + |
| 771 |
"while(1) { foo(); }", |
| 772 |
"foo", INLINE_BLOCK, true); |
| 773 |
} |
| 774 |
|
| 775 |
public void testInline1() { |
| 776 |
helperInlineReferenceToFunction( |
| 777 |
"function foo(){}; foo();", |
| 778 |
"function foo(){}; void 0", |
| 779 |
"foo", INLINE_DIRECT); |
| 780 |
} |
| 781 |
|
| 782 |
public void testInline2() { |
| 783 |
helperInlineReferenceToFunction( |
| 784 |
"function foo(){}; foo();", |
| 785 |
"function foo(){}; {}", |
| 786 |
"foo", INLINE_BLOCK); |
| 787 |
} |
| 788 |
|
| 789 |
public void testInline3() { |
| 790 |
helperInlineReferenceToFunction( |
| 791 |
"function foo(){return;}; foo();", |
| 792 |
"function foo(){return;}; {}", |
| 793 |
"foo", INLINE_BLOCK); |
| 794 |
} |
| 795 |
|
| 796 |
public void testInline4() { |
| 797 |
helperInlineReferenceToFunction( |
| 798 |
"function foo(){return true;}; foo();", |
| 799 |
"function foo(){return true;}; true;", |
| 800 |
"foo", INLINE_DIRECT); |
| 801 |
} |
| 802 |
|
| 803 |
public void testInline5() { |
| 804 |
helperInlineReferenceToFunction( |
| 805 |
"function foo(){return true;}; foo();", |
| 806 |
"function foo(){return true;}; {true;}", |
| 807 |
"foo", INLINE_BLOCK); |
| 808 |
} |
| 809 |
|
| 810 |
public void testInline6() { |
| 811 |
|
| 812 |
helperInlineReferenceToFunction( |
| 813 |
"function foo(){return true;}; var x=foo();", |
| 814 |
"function foo(){return true;}; var x=true;", |
| 815 |
"foo", INLINE_DIRECT); |
| 816 |
} |
| 817 |
|
| 818 |
public void testInline7() { |
| 819 |
helperInlineReferenceToFunction( |
| 820 |
"function foo(){return true;}; var x=foo();", |
| 821 |
"function foo(){return true;}; var x;" + |
| 822 |
"{x=true}", |
| 823 |
"foo", INLINE_BLOCK); |
| 824 |
} |
| 825 |
|
| 826 |
public void testInline8() { |
| 827 |
|
| 828 |
helperInlineReferenceToFunction( |
| 829 |
"function foo(){return true;}; var x; x=foo();", |
| 830 |
"function foo(){return true;}; var x; x=true;", |
| 831 |
"foo", INLINE_DIRECT); |
| 832 |
} |
| 833 |
|
| 834 |
public void testInline9() { |
| 835 |
helperInlineReferenceToFunction( |
| 836 |
"function foo(){return true;}; var x; x=foo();", |
| 837 |
"function foo(){return true;}; var x;{x=true}", |
| 838 |
"foo", INLINE_BLOCK); |
| 839 |
} |
| 840 |
|
| 841 |
public void testInline10() { |
| 842 |
|
| 843 |
helperInlineReferenceToFunction( |
| 844 |
"function foo(){return true;}; var x; x=x+foo();", |
| 845 |
"function foo(){return true;}; var x; x=x+true;", |
| 846 |
"foo", INLINE_DIRECT); |
| 847 |
} |
| 848 |
|
| 849 |
public void testInline11() { |
| 850 |
|
| 851 |
helperInlineReferenceToFunction( |
| 852 |
"function foo(a){return true;}; foo(x);", |
| 853 |
"function foo(a){return true;}; true;", |
| 854 |
"foo", INLINE_DIRECT); |
| 855 |
} |
| 856 |
|
| 857 |
public void testInline12() { |
| 858 |
helperInlineReferenceToFunction( |
| 859 |
"function foo(a){return true;}; foo(x);", |
| 860 |
"function foo(a){return true;}; {true}", |
| 861 |
"foo", INLINE_BLOCK); |
| 862 |
} |
| 863 |
|
| 864 |
public void testInline13() { |
| 865 |
|
| 866 |
helperInlineReferenceToFunction( |
| 867 |
"function foo(a){return a;}; " + |
| 868 |
"function x() { foo(x++); }", |
| 869 |
"function foo(a){return a;}; " + |
| 870 |
"function x() {{var a$$inline_0=x++;" + |
| 871 |
"a$$inline_0}}", |
| 872 |
"foo", INLINE_BLOCK); |
| 873 |
} |
| 874 |
|
| 875 |
public void testInline14() { |
| 876 |
|
| 877 |
helperInlineReferenceToFunction( |
| 878 |
"function foo(a){return a+a;}; foo(x++);", |
| 879 |
"function foo(a){return a+a;}; " + |
| 880 |
"{var a$$inline_0=x++;" + |
| 881 |
" a$$inline_0+" + |
| 882 |
"a$$inline_0;}", |
| 883 |
"foo", INLINE_BLOCK); |
| 884 |
} |
| 885 |
|
| 886 |
public void testInline15() { |
| 887 |
|
| 888 |
helperInlineReferenceToFunction( |
| 889 |
"function foo(a){return a+a;}; foo(new Date());", |
| 890 |
"function foo(a){return a+a;}; " + |
| 891 |
"{var a$$inline_0=new Date();" + |
| 892 |
" a$$inline_0+" + |
| 893 |
"a$$inline_0;}", |
| 894 |
"foo", INLINE_BLOCK); |
| 895 |
} |
| 896 |
|
| 897 |
public void testInline16() { |
| 898 |
|
| 899 |
helperInlineReferenceToFunction( |
| 900 |
"function foo(a){return a+a;}; foo(function(){});", |
| 901 |
"function foo(a){return a+a;}; " + |
| 902 |
"{var a$$inline_0=function(){};" + |
| 903 |
" a$$inline_0+" + |
| 904 |
"a$$inline_0;}", |
| 905 |
"foo", INLINE_BLOCK); |
| 906 |
} |
| 907 |
|
| 908 |
public void testInline17() { |
| 909 |
|
| 910 |
helperInlineReferenceToFunction( |
| 911 |
"function foo(a){return true;}; foo(goo());", |
| 912 |
"function foo(a){return true;};" + |
| 913 |
"{var a$$inline_0=goo();true}", |
| 914 |
"foo", INLINE_BLOCK); |
| 915 |
} |
| 916 |
|
| 917 |
public void testInline18() { |
| 918 |
|
| 919 |
helperInlineReferenceToFunction( |
| 920 |
"function foo(a){var b;return a;}; " + |
| 921 |
"function x() { foo(goo()); }", |
| 922 |
"function foo(a){var b;return a;}; " + |
| 923 |
"function x() {{var a$$inline_0=goo();" + |
| 924 |
"var b$$inline_1;a$$inline_0}}", |
| 925 |
"foo", INLINE_BLOCK); |
| 926 |
} |
| 927 |
|
| 928 |
public void testInline19() { |
| 929 |
|
| 930 |
helperInlineReferenceToFunction( |
| 931 |
"var x = 1; var y = 2;" + |
| 932 |
"function foo(a,b){x = b; y = a;}; " + |
| 933 |
"function bar() { foo(x,y); }", |
| 934 |
"var x = 1; var y = 2;" + |
| 935 |
"function foo(a,b){x = b; y = a;}; " + |
| 936 |
"function bar() {" + |
| 937 |
"{var a$$inline_0=x;" + |
| 938 |
"x = y;" + |
| 939 |
"y = a$$inline_0;}" + |
| 940 |
"}", |
| 941 |
"foo", INLINE_BLOCK); |
| 942 |
} |
| 943 |
|
| 944 |
public void testInline19b() { |
| 945 |
helperInlineReferenceToFunction( |
| 946 |
"var x = 1; var y = 2;" + |
| 947 |
"function foo(a,b){y = a; x = b;}; " + |
| 948 |
"function bar() { foo(x,y); }", |
| 949 |
"var x = 1; var y = 2;" + |
| 950 |
"function foo(a,b){y = a; x = b;}; " + |
| 951 |
"function bar() {" + |
| 952 |
"{var b$$inline_1=y;" + |
| 953 |
"y = x;" + |
| 954 |
"x = b$$inline_1;}" + |
| 955 |
"}", |
| 956 |
"foo", INLINE_BLOCK); |
| 957 |
} |
| 958 |
|
| 959 |
public void testInlineIntoLoop() { |
| 960 |
helperInlineReferenceToFunction( |
| 961 |
"function foo(a){var b;return a;}; " + |
| 962 |
"for(;1;){ foo(1); }", |
| 963 |
"function foo(a){var b;return a;}; " + |
| 964 |
"for(;1;){ {" + |
| 965 |
"var b$$inline_1=void 0;1}}", |
| 966 |
"foo", INLINE_BLOCK); |
| 967 |
|
| 968 |
helperInlineReferenceToFunction( |
| 969 |
"function foo(a){var b;return a;}; " + |
| 970 |
"do{ foo(1); } while(1)", |
| 971 |
"function foo(a){var b;return a;}; " + |
| 972 |
"do{ {" + |
| 973 |
"var b$$inline_1=void 0;1}}while(1)", |
| 974 |
"foo", INLINE_BLOCK); |
| 975 |
|
| 976 |
helperInlineReferenceToFunction( |
| 977 |
"function foo(a){for(var b in c)return a;}; " + |
| 978 |
"for(;1;){ foo(1); }", |
| 979 |
"function foo(a){var b;for(b in c)return a;}; " + |
| 980 |
"for(;1;){ {JSCompiler_inline_label_foo_2:{" + |
| 981 |
"var b$$inline_1=void 0;for(b$$inline_1 in c){" + |
| 982 |
"1;break JSCompiler_inline_label_foo_2" + |
| 983 |
"}}}}", |
| 984 |
"foo", INLINE_BLOCK); |
| 985 |
} |
| 986 |
|
| 987 |
public void testInlineFunctionWithInnerFunction1() { |
| 988 |
|
| 989 |
helperInlineReferenceToFunction( |
| 990 |
"function foo(){return function() {return true;}}; foo();", |
| 991 |
"function foo(){return function() {return true;}};" + |
| 992 |
"(function() {return true;})", |
| 993 |
"foo", INLINE_DIRECT); |
| 994 |
} |
| 995 |
|
| 996 |
public void testInlineFunctionWithInnerFunction2() { |
| 997 |
|
| 998 |
helperInlineReferenceToFunction( |
| 999 |
"function foo(){return function() {return true;}}; foo();", |
| 1000 |
"function foo(){return function() {return true;}};" + |
| 1001 |
"{(function() {return true;})}", |
| 1002 |
"foo", INLINE_BLOCK); |
| 1003 |
} |
| 1004 |
|
| 1005 |
public void testInlineFunctionWithInnerFunction3() { |
| 1006 |
|
| 1007 |
helperInlineReferenceToFunction( |
| 1008 |
"function foo(){return function() {var a; return true;}}; foo();", |
| 1009 |
"function foo(){return function() {var a; return true;}};" + |
| 1010 |
"(function() {var a; return true;});", |
| 1011 |
"foo", INLINE_DIRECT); |
| 1012 |
} |
| 1013 |
|
| 1014 |
public void testInlineFunctionWithInnerFunction4() { |
| 1015 |
|
| 1016 |
helperInlineReferenceToFunction( |
| 1017 |
"function foo(){return function() {var a; return true;}}; foo();", |
| 1018 |
"function foo(){return function() {var a; return true;}};" + |
| 1019 |
"{(function() {var a$$inline_0; return true;});}", |
| 1020 |
"foo", INLINE_BLOCK); |
| 1021 |
} |
| 1022 |
|
| 1023 |
public void testInlineFunctionWithInnerFunction5() { |
| 1024 |
|
| 1025 |
helperInlineReferenceToFunction( |
| 1026 |
"function foo(){function x() {var a; return true;} return x}; foo();", |
| 1027 |
"function foo(){function x(){var a;return true}return x};" + |
| 1028 |
"{var x$$inline_0 = function(){" + |
| 1029 |
"var a$$inline_1;return true};x$$inline_0}", |
| 1030 |
"foo", INLINE_BLOCK); |
| 1031 |
} |
| 1032 |
|
| 1033 |
public void testInlineReferenceInExpression1() { |
| 1034 |
|
| 1035 |
helperInlineReferenceToFunction( |
| 1036 |
"function foo(a){return true;}; " + |
| 1037 |
"function x() { if (foo(1)) throw 'test'; }", |
| 1038 |
"function foo(a){return true;}; " + |
| 1039 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1040 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1041 |
"if (JSCompiler_inline_result$$0) throw 'test'; }", |
| 1042 |
"foo", INLINE_BLOCK, true); |
| 1043 |
} |
| 1044 |
|
| 1045 |
public void testInlineReferenceInExpression2() { |
| 1046 |
|
| 1047 |
helperInlineReferenceToFunction( |
| 1048 |
"function foo(a){return true;}; " + |
| 1049 |
"function x() { return foo(1); }", |
| 1050 |
"function foo(a){return true;}; " + |
| 1051 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1052 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1053 |
"return JSCompiler_inline_result$$0; }", |
| 1054 |
"foo", INLINE_BLOCK, true); |
| 1055 |
} |
| 1056 |
|
| 1057 |
public void testInlineReferenceInExpression3() { |
| 1058 |
|
| 1059 |
helperInlineReferenceToFunction( |
| 1060 |
"function foo(a){return true;}; " + |
| 1061 |
"function x() { switch(foo(1)) { default:break; } }", |
| 1062 |
"function foo(a){return true;}; " + |
| 1063 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1064 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1065 |
"switch(JSCompiler_inline_result$$0) { default:break; } }", |
| 1066 |
"foo", INLINE_BLOCK, true); |
| 1067 |
} |
| 1068 |
|
| 1069 |
public void testInlineReferenceInExpression4() { |
| 1070 |
|
| 1071 |
helperInlineReferenceToFunction( |
| 1072 |
"function foo(a){return true;}; " + |
| 1073 |
"function x() {foo(1)?0:1 }", |
| 1074 |
"function foo(a){return true;}; " + |
| 1075 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1076 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1077 |
"JSCompiler_inline_result$$0?0:1 }", |
| 1078 |
"foo", INLINE_BLOCK, true); |
| 1079 |
} |
| 1080 |
|
| 1081 |
public void testInlineReferenceInExpression5() { |
| 1082 |
|
| 1083 |
helperInlineReferenceToFunction( |
| 1084 |
"function foo(a){return true;}; " + |
| 1085 |
"function x() {foo(1)&&1 }", |
| 1086 |
"function foo(a){return true;}; " + |
| 1087 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1088 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1089 |
"JSCompiler_inline_result$$0&&1 }", |
| 1090 |
"foo", INLINE_BLOCK, true); |
| 1091 |
} |
| 1092 |
|
| 1093 |
public void testInlineReferenceInExpression6() { |
| 1094 |
|
| 1095 |
helperInlineReferenceToFunction( |
| 1096 |
"function foo(a){return true;}; " + |
| 1097 |
"function x() {1 + foo(1) }", |
| 1098 |
"function foo(a){return true;}; " + |
| 1099 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1100 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1101 |
"1 + JSCompiler_inline_result$$0 }", |
| 1102 |
"foo", INLINE_BLOCK, true); |
| 1103 |
} |
| 1104 |
|
| 1105 |
public void testInlineReferenceInExpression7() { |
| 1106 |
|
| 1107 |
helperInlineReferenceToFunction( |
| 1108 |
"function foo(a){return true;}; " + |
| 1109 |
"function x() {foo(1) && 1 }", |
| 1110 |
"function foo(a){return true;}; " + |
| 1111 |
"function x() { var JSCompiler_inline_result$$0; " + |
| 1112 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1113 |
"JSCompiler_inline_result$$0&&1 }", |
| 1114 |
"foo", INLINE_BLOCK, true); |
| 1115 |
} |
| 1116 |
|
| 1117 |
public void testInlineReferenceInExpression8() { |
| 1118 |
|
| 1119 |
helperInlineReferenceToFunction( |
| 1120 |
"function foo(a){return true;}; " + |
| 1121 |
"function x() {1 + foo(1) }", |
| 1122 |
"function foo(a){return true;}; " + |
| 1123 |
"function x() { var JSCompiler_inline_result$$0;" + |
| 1124 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1125 |
"1 + JSCompiler_inline_result$$0 }", |
| 1126 |
"foo", INLINE_BLOCK, true); |
| 1127 |
} |
| 1128 |
|
| 1129 |
public void testInlineReferenceInExpression9() { |
| 1130 |
|
| 1131 |
helperInlineReferenceToFunction( |
| 1132 |
"function foo(a){return true;}; " + |
| 1133 |
"function x() {var b = 1 + foo(1)}", |
| 1134 |
"function foo(a){return true;}; " + |
| 1135 |
"function x() { " + |
| 1136 |
"var JSCompiler_inline_result$$0;" + |
| 1137 |
"{JSCompiler_inline_result$$0=true;}" + |
| 1138 |
"var b = 1 + JSCompiler_inline_result$$0 " + |
| 1139 |
"}", |
| 1140 |
"foo", INLINE_BLOCK, true); |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
public void testInlineReferenceInExpression11() { |
| 1158 |
|
| 1159 |
helperInlineReferenceToFunction( |
| 1160 |
"function foo(a){return true;}; " + |
| 1161 |
"function x() {a:foo(1)?0:1 }", |
| 1162 |
"function foo(a){return true;}; " + |
| 1163 |
"function x() {" + |
| 1164 |
" a:{" + |
| 1165 |
" var JSCompiler_inline_result$$0; " + |
| 1166 |
" {JSCompiler_inline_result$$0=true;}" + |
| 1167 |
" JSCompiler_inline_result$$0?0:1 " + |
| 1168 |
" }" + |
| 1169 |
"}", |
| 1170 |
"foo", INLINE_BLOCK, true); |
| 1171 |
} |
| 1172 |
|
| 1173 |
public void testInlineReferenceInExpression12() { |
| 1174 |
helperInlineReferenceToFunction( |
| 1175 |
"function foo(a){return true;}" + |
| 1176 |
"function x() { 1?foo(1):1; }", |
| 1177 |
"function foo(a){return true}" + |
| 1178 |
"function x() {" + |
| 1179 |
" if(1) {" + |
| 1180 |
" {true;}" + |
| 1181 |
" } else {" + |
| 1182 |
" 1;" + |
| 1183 |
" }" + |
| 1184 |
"}", |
| 1185 |
"foo", INLINE_BLOCK, true); |
| 1186 |
} |
| 1187 |
|
| 1188 |
public void testInlineReferenceInExpression13() { |
| 1189 |
helperInlineReferenceToFunction( |
| 1190 |
"function foo(a){return true;}; " + |
| 1191 |
"function x() { goo() + (1?foo(1):1) }", |
| 1192 |
"function foo(a){return true;}; " + |
| 1193 |
"function x() { var JSCompiler_temp_const$$0=goo();" + |
| 1194 |
"var JSCompiler_temp$$1;" + |
| 1195 |
"if(1) {" + |
| 1196 |
" {JSCompiler_temp$$1=true;} " + |
| 1197 |
"} else {" + |
| 1198 |
" JSCompiler_temp$$1=1;" + |
| 1199 |
"}" + |
| 1200 |
"JSCompiler_temp_const$$0 + JSCompiler_temp$$1" + |
| 1201 |
"}", |
| 1202 |
"foo", INLINE_BLOCK, true); |
| 1203 |
} |
| 1204 |
|
| 1205 |
public void testInlineReferenceInExpression14() { |
| 1206 |
helperInlineReferenceToFunction( |
| 1207 |
"var z = {};" + |
| 1208 |
"function foo(a){z = {};return true;}; " + |
| 1209 |
"function x() { z.gack = foo(1) }", |
| 1210 |
|
| 1211 |
"var z = {};" + |
| 1212 |
"function foo(a){z = {};return true;}; " + |
| 1213 |
"function x() {" + |
| 1214 |
"var JSCompiler_temp_const$$0=z;" + |
| 1215 |
"var JSCompiler_inline_result$$1;" + |
| 1216 |
"{" + |
| 1217 |
"z= {};" + |
| 1218 |
"JSCompiler_inline_result$$1 = true;" + |
| 1219 |
"}" + |
| 1220 |
"JSCompiler_temp_const$$0.gack = JSCompiler_inline_result$$1;" + |
| 1221 |
"}", |
| 1222 |
"foo", INLINE_BLOCK, true); |
| 1223 |
} |
| 1224 |
|
| 1225 |
public void testInlineReferenceInExpression15() { |
| 1226 |
helperInlineReferenceToFunction( |
| 1227 |
"var z = {};" + |
| 1228 |
"function foo(a){z = {};return true;}; " + |
| 1229 |
"function x() { z.gack = foo.call(this,1) }", |
| 1230 |
|
| 1231 |
"var z = {};" + |
| 1232 |
"function foo(a){z = {};return true;}; " + |
| 1233 |
"function x() {" + |
| 1234 |
"var JSCompiler_temp_const$$0=z;" + |
| 1235 |
"var JSCompiler_inline_result$$1;" + |
| 1236 |
"{" + |
| 1237 |
"z= {};" + |
| 1238 |
"JSCompiler_inline_result$$1 = true;" + |
| 1239 |
"}" + |
| 1240 |
"JSCompiler_temp_const$$0.gack = JSCompiler_inline_result$$1;" + |
| 1241 |
"}", |
| 1242 |
"foo", INLINE_BLOCK, true); |
| 1243 |
} |
| 1244 |
|
| 1245 |
public void testInlineReferenceInExpression16() { |
| 1246 |
helperInlineReferenceToFunction( |
| 1247 |
"var z = {};" + |
| 1248 |
"function foo(a){z = {};return true;}; " + |
| 1249 |
"function x() { z[bar()] = foo(1) }", |
| 1250 |
|
| 1251 |
"var z = {};" + |
| 1252 |
"function foo(a){z = {};return true;}; " + |
| 1253 |
"function x() {" + |
| 1254 |
"var JSCompiler_temp_const$$1=z;" + |
| 1255 |
"var JSCompiler_temp_const$$0=bar();" + |
| 1256 |
"var JSCompiler_inline_result$$2;" + |
| 1257 |
"{" + |
| 1258 |
"z= {};" + |
| 1259 |
"JSCompiler_inline_result$$2 = true;" + |
| 1260 |
"}" + |
| 1261 |
"JSCompiler_temp_const$$1[JSCompiler_temp_const$$0] = " + |
| 1262 |
"JSCompiler_inline_result$$2;" + |
| 1263 |
"}", |
| 1264 |
"foo", INLINE_BLOCK, true); |
| 1265 |
} |
| 1266 |
|
| 1267 |
public void testInlineReferenceInExpression17() { |
| 1268 |
helperInlineReferenceToFunction( |
| 1269 |
"var z = {};" + |
| 1270 |
"function foo(a){z = {};return true;}; " + |
| 1271 |
"function x() { z.y.x.gack = foo(1) }", |
| 1272 |
|
| 1273 |
"var z = {};" + |
| 1274 |
"function foo(a){z = {};return true;}; " + |
| 1275 |
"function x() {" + |
| 1276 |
"var JSCompiler_temp_const$$0=z.y.x;" + |
| 1277 |
"var JSCompiler_inline_result$$1;" + |
| 1278 |
"{" + |
| 1279 |
"z= {};" + |
| 1280 |
"JSCompiler_inline_result$$1 = true;" + |
| 1281 |
"}" + |
| 1282 |
"JSCompiler_temp_const$$0.gack = JSCompiler_inline_result$$1;" + |
| 1283 |
"}", |
| 1284 |
"foo", INLINE_BLOCK, true); |
| 1285 |
} |
| 1286 |
|
| 1287 |
|
| 1288 |
public void testInlineWithinCalls1() { |
| 1289 |
|
| 1290 |
helperInlineReferenceToFunction( |
| 1291 |
"function foo(){return _g;}; " + |
| 1292 |
"function x() {1 + foo()() }", |
| 1293 |
"function foo(){return _g;}; " + |
| 1294 |
"function x() { var JSCompiler_inline_result$$0;" + |
| 1295 |
"{JSCompiler_inline_result$$0=_g;}" + |
| 1296 |
"1 + JSCompiler_inline_result$$0() }", |
| 1297 |
"foo", INLINE_BLOCK, true); |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
public void testInlineAssignmentToConstant() { |
| 1313 |
|
| 1314 |
helperInlineReferenceToFunction( |
| 1315 |
"function foo(){return _g;}; " + |
| 1316 |
"function x(){var CONSTANT_RESULT = foo(); }", |
| 1317 |
|
| 1318 |
"function foo(){return _g;}; " + |
| 1319 |
"function x() {" + |
| 1320 |
" var JSCompiler_inline_result$$0;" + |
| 1321 |
" {JSCompiler_inline_result$$0=_g;}" + |
| 1322 |
" var CONSTANT_RESULT = JSCompiler_inline_result$$0;" + |
| 1323 |
"}", |
| 1324 |
"foo", INLINE_BLOCK, true); |
| 1325 |
} |
| 1326 |
|
| 1327 |
public void testBug1897706() { |
| 1328 |
helperInlineReferenceToFunction( |
| 1329 |
"function foo(a){}; foo(x())", |
| 1330 |
"function foo(a){}; {var a$$inline_0=x()}", |
| 1331 |
"foo", INLINE_BLOCK); |
| 1332 |
|
| 1333 |
helperInlineReferenceToFunction( |
| 1334 |
"function foo(a){bar()}; foo(x())", |
| 1335 |
"function foo(a){bar()}; {var a$$inline_0=x();bar()}", |
| 1336 |
"foo", INLINE_BLOCK); |
| 1337 |
|
| 1338 |
helperInlineReferenceToFunction( |
| 1339 |
"function foo(a,b){bar()}; foo(x(),y())", |
| 1340 |
"function foo(a,b){bar()};" + |
| 1341 |
"{var a$$inline_0=x();var b$$inline_1=y();bar()}", |
| 1342 |
"foo", INLINE_BLOCK); |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
public void helperCanInlineReferenceToFunction( |
| 1357 |
final CanInlineResult expectedResult, |
| 1358 |
final String code, |
| 1359 |
final String fnName, |
| 1360 |
final InliningMode mode) { |
| 1361 |
helperCanInlineReferenceToFunction( |
| 1362 |
expectedResult, code, fnName, mode, false); |
| 1363 |
} |
| 1364 |
|
| 1365 |
public void helperCanInlineReferenceToFunction( |
| 1366 |
final CanInlineResult expectedResult, |
| 1367 |
final String code, |
| 1368 |
final String fnName, |
| 1369 |
final InliningMode mode, |
| 1370 |
boolean allowDecomposition) { |
| 1371 |
final Compiler compiler = new Compiler(); |
| 1372 |
final FunctionInjector injector = new FunctionInjector( |
| 1373 |
compiler, compiler.getUniqueNameIdSupplier(), allowDecomposition, |
| 1374 |
assumeStrictThis, |
| 1375 |
assumeMinimumCapture); |
| 1376 |
final Node tree = parse(compiler, code); |
| 1377 |
|
| 1378 |
final Node fnNode = findFunction(tree, fnName); |
| 1379 |
final Set<String> unsafe = |
| 1380 |
FunctionArgumentInjector.findModifiedParameters(fnNode); |
| 1381 |
|
| 1382 |
|
| 1383 |
Method tester = new Method() { |
| 1384 |
@Override |
| 1385 |
public boolean call(NodeTraversal t, Node n, Node parent) { |
| 1386 |
CanInlineResult result = injector.canInlineReferenceToFunction( |
| 1387 |
t, n, fnNode, unsafe, mode, |
| 1388 |
NodeUtil.referencesThis(fnNode), |
| 1389 |
NodeUtil.containsFunction(NodeUtil.getFunctionBody(fnNode))); |
| 1390 |
assertEquals(expectedResult, result); |
| 1391 |
return true; |
| 1392 |
} |
| 1393 |
}; |
| 1394 |
|
| 1395 |
compiler.resetUniqueNameId(); |
| 1396 |
TestCallback test = new TestCallback(fnName, tester); |
| 1397 |
NodeTraversal.traverse(compiler, tree, test); |
| 1398 |
} |
| 1399 |
|
| 1400 |
public void helperInlineReferenceToFunction( |
| 1401 |
String code, final String expectedResult, |
| 1402 |
final String fnName, final InliningMode mode) { |
| 1403 |
helperInlineReferenceToFunction( |
| 1404 |
code, expectedResult, fnName, mode, false); |
| 1405 |
} |
| 1406 |
|
| 1407 |
private void validateSourceInfo(Compiler compiler, Node subtree) { |
| 1408 |
(new LineNumberCheck(compiler)).setCheckSubTree(subtree); |
| 1409 |
|
| 1410 |
if (compiler.getErrorCount() != 0) { |
| 1411 |
String msg = "Error encountered: "; |
| 1412 |
for (JSError err : compiler.getErrors()) { |
| 1413 |
msg += err.toString() + "\n"; |
| 1414 |
} |
| 1415 |
assertTrue(msg, compiler.getErrorCount() == 0); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
|
| 1419 |
public void helperInlineReferenceToFunction( |
| 1420 |
String code, final String expectedResult, |
| 1421 |
final String fnName, final InliningMode mode, |
| 1422 |
final boolean decompose) { |
| 1423 |
final Compiler compiler = new Compiler(); |
| 1424 |
final FunctionInjector injector = new FunctionInjector( |
| 1425 |
compiler, compiler.getUniqueNameIdSupplier(), decompose, |
| 1426 |
assumeStrictThis, |
| 1427 |
assumeMinimumCapture); |
| 1428 |
|
| 1429 |
List<SourceFile> externsInputs = Lists.newArrayList( |
| 1430 |
SourceFile.fromCode("externs", "")); |
| 1431 |
|
| 1432 |
CompilerOptions options = new CompilerOptions(); |
| 1433 |
options.setCodingConvention(new GoogleCodingConvention()); |
| 1434 |
compiler.init(externsInputs, Lists.newArrayList( |
| 1435 |
SourceFile.fromCode("code", code)), options); |
| 1436 |
Node parseRoot = compiler.parseInputs(); |
| 1437 |
Node externsRoot = parseRoot.getFirstChild(); |
| 1438 |
final Node tree = parseRoot.getLastChild(); |
| 1439 |
assertNotNull(tree); |
| 1440 |
assertTrue(tree != externsRoot); |
| 1441 |
|
| 1442 |
final Node expectedRoot = parseExpected(new Compiler(), expectedResult); |
| 1443 |
|
| 1444 |
Node mainRoot = tree; |
| 1445 |
MarkNoSideEffectCalls mark = new MarkNoSideEffectCalls(compiler); |
| 1446 |
mark.process(externsRoot, mainRoot); |
| 1447 |
|
| 1448 |
Normalize normalize = new Normalize(compiler, false); |
| 1449 |
normalize.process(externsRoot, mainRoot); |
| 1450 |
compiler.setLifeCycleStage(LifeCycleStage.NORMALIZED); |
| 1451 |
|
| 1452 |
final Node fnNode = findFunction(tree, fnName); |
| 1453 |
assertNotNull(fnNode); |
| 1454 |
final Set<String> unsafe = |
| 1455 |
FunctionArgumentInjector.findModifiedParameters(fnNode); |
| 1456 |
assertNotNull(fnNode); |
| 1457 |
|
| 1458 |
|
| 1459 |
Method tester = new Method() { |
| 1460 |
@Override |
| 1461 |
public boolean call(NodeTraversal t, Node n, Node parent) { |
| 1462 |
|
| 1463 |
CanInlineResult canInline = injector.canInlineReferenceToFunction( |
| 1464 |
t, n, fnNode, unsafe, mode, |
| 1465 |
NodeUtil.referencesThis(fnNode), |
| 1466 |
NodeUtil.containsFunction(NodeUtil.getFunctionBody(fnNode))); |
| 1467 |
assertTrue("canInlineReferenceToFunction should not be CAN_NOT_INLINE", |
| 1468 |
CanInlineResult.NO != canInline); |
| 1469 |
if (decompose) { |
| 1470 |
assertTrue("canInlineReferenceToFunction " + |
| 1471 |
"should be CAN_INLINE_AFTER_DECOMPOSITION", |
| 1472 |
CanInlineResult.AFTER_PREPARATION == canInline); |
| 1473 |
|
| 1474 |
Set<String> knownConstants = Sets.newHashSet(); |
| 1475 |
injector.setKnownConstants(knownConstants); |
| 1476 |
injector.maybePrepareCall(n); |
| 1477 |
|
| 1478 |
assertTrue("canInlineReferenceToFunction " + |
| 1479 |
"should be CAN_INLINE", |
| 1480 |
CanInlineResult.YES != canInline); |
| 1481 |
} |
| 1482 |
|
| 1483 |
Node result = injector.inline(n, fnName, fnNode, mode); |
| 1484 |
validateSourceInfo(compiler, result); |
| 1485 |
String explanation = expectedRoot.checkTreeEquals(tree.getFirstChild()); |
| 1486 |
assertNull("\nExpected: " + toSource(expectedRoot) + |
| 1487 |
"\nResult: " + toSource(tree.getFirstChild()) + |
| 1488 |
"\n" + explanation, explanation); |
| 1489 |
return true; |
| 1490 |
} |
| 1491 |
}; |
| 1492 |
|
| 1493 |
compiler.resetUniqueNameId(); |
| 1494 |
TestCallback test = new TestCallback(fnName, tester); |
| 1495 |
NodeTraversal.traverse(compiler, tree, test); |
| 1496 |
} |
| 1497 |
|
| 1498 |
interface Method { |
| 1499 |
boolean call(NodeTraversal t, Node n, Node parent); |
| 1500 |
} |
| 1501 |
|
| 1502 |
class TestCallback implements Callback { |
| 1503 |
|
| 1504 |
private final String callname; |
| 1505 |
private final Method method; |
| 1506 |
private boolean complete = false; |
| 1507 |
|
| 1508 |
TestCallback(String callname, Method method) { |
| 1509 |
this.callname = callname; |
| 1510 |
this.method = method; |
| 1511 |
} |
| 1512 |
|
| 1513 |
@Override |
| 1514 |
public boolean shouldTraverse( |
| 1515 |
NodeTraversal nodeTraversal, Node n, Node parent) { |
| 1516 |
return !complete; |
| 1517 |
} |
| 1518 |
|
| 1519 |
@Override |
| 1520 |
public void visit(NodeTraversal t, Node n, Node parent) { |
| 1521 |
if (n.isCall()) { |
| 1522 |
Node callee; |
| 1523 |
if (NodeUtil.isGet(n.getFirstChild())) { |
| 1524 |
callee = n.getFirstChild().getFirstChild(); |
| 1525 |
} else { |
| 1526 |
callee = n.getFirstChild(); |
| 1527 |
} |
| 1528 |
|
| 1529 |
if (callee.isName() && |
| 1530 |
callee.getString().equals(callname)) { |
| 1531 |
complete = method.call(t, n, parent); |
| 1532 |
} |
| 1533 |
} |
| 1534 |
|
| 1535 |
if (parent == null) { |
| 1536 |
assertTrue(complete); |
| 1537 |
} |
| 1538 |
} |
| 1539 |
} |
| 1540 |
|
| 1541 |
private static Node findFunction(Node n, String name) { |
| 1542 |
if (n.isFunction()) { |
| 1543 |
if (n.getFirstChild().getString().equals(name)) { |
| 1544 |
return n; |
| 1545 |
} |
| 1546 |
} |
| 1547 |
|
| 1548 |
for (Node c : n.children()) { |
| 1549 |
Node result = findFunction(c, name); |
| 1550 |
if (result != null) { |
| 1551 |
return result; |
| 1552 |
} |
| 1553 |
} |
| 1554 |
|
| 1555 |
return null; |
| 1556 |
} |
| 1557 |
|
| 1558 |
private static Node prep(String js) { |
| 1559 |
Compiler compiler = new Compiler(); |
| 1560 |
Node n = compiler.parseTestCode(js); |
| 1561 |
assertEquals(0, compiler.getErrorCount()); |
| 1562 |
return n.getFirstChild(); |
| 1563 |
} |
| 1564 |
|
| 1565 |
private static Node parse(Compiler compiler, String js) { |
| 1566 |
Node n = compiler.parseTestCode(js); |
| 1567 |
assertEquals(0, compiler.getErrorCount()); |
| 1568 |
return n; |
| 1569 |
} |
| 1570 |
|
| 1571 |
private static Node parseExpected(Compiler compiler, String js) { |
| 1572 |
Node n = compiler.parseTestCode(js); |
| 1573 |
String message = "Unexpected errors: "; |
| 1574 |
JSError[] errs = compiler.getErrors(); |
| 1575 |
for (int i = 0; i < errs.length; i++){ |
| 1576 |
message += "\n" + errs[i].toString(); |
| 1577 |
} |
| 1578 |
assertEquals(message, 0, compiler.getErrorCount()); |
| 1579 |
return n; |
| 1580 |
} |
| 1581 |
|
| 1582 |
private static String toSource(Node n) { |
| 1583 |
return new CodePrinter.Builder(n) |
| 1584 |
.setPrettyPrint(false) |
| 1585 |
.setLineBreak(false) |
| 1586 |
.setSourceMap(null) |
| 1587 |
.build(); |
| 1588 |
} |
| 1589 |
|
| 1590 |
} |