Commit 0afd9c5
refactor(core): swap dev/prod error handling order in injector for tree-shaking (#63354)
In production builds, `ngDevMode` is replaced with `false`, so the guard compiles to `return;`. However, bundlers like ESBuild still keep the remaining statements after the return as unreachable code instead of removing them. This leaves behind unnecessary dead code in the output.
Technically, the body is unreachable. But to prove that, the bundler must be 100% certain that:
- `return` cannot be removed by some transform
- there's no later transformation that changes control flow
As thus, it's always conservative.
This also allows dropping `assertDefined`, which was previously
referenced only inside `prependTokenToDependencyPath`. With the
function now fully inlined and dev-only, `assertDefined` is also
eliminated from production builds, further reducing bundle size.
PR Close #633541 parent 444fd01 commit 0afd9c5
File tree
8 files changed
+15
-46
lines changed- packages/core
- src/di
- test/bundling
- animations-standalone
- defer
- forms_reactive
- forms_template_driven
- hydration
- router
- standalone_bootstrap
8 files changed
+15
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
| |||
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
400 | 401 | | |
401 | | - | |
402 | | - | |
403 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
404 | 409 | | |
405 | | - | |
406 | | - | |
| 410 | + | |
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
419 | 418 | | |
420 | 419 | | |
421 | | - | |
422 | 420 | | |
423 | 421 | | |
424 | 422 | | |
| |||
551 | 549 | | |
552 | 550 | | |
553 | 551 | | |
554 | | - | |
555 | 552 | | |
556 | 553 | | |
557 | 554 | | |
| |||
808 | 805 | | |
809 | 806 | | |
810 | 807 | | |
811 | | - | |
812 | 808 | | |
813 | 809 | | |
814 | 810 | | |
| |||
909 | 905 | | |
910 | 906 | | |
911 | 907 | | |
912 | | - | |
913 | 908 | | |
914 | 909 | | |
915 | 910 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | 361 | | |
363 | 362 | | |
364 | | - | |
365 | 363 | | |
366 | 364 | | |
367 | 365 | | |
| |||
469 | 467 | | |
470 | 468 | | |
471 | 469 | | |
472 | | - | |
473 | 470 | | |
474 | 471 | | |
475 | 472 | | |
| |||
683 | 680 | | |
684 | 681 | | |
685 | 682 | | |
686 | | - | |
687 | 683 | | |
688 | 684 | | |
689 | 685 | | |
| |||
776 | 772 | | |
777 | 773 | | |
778 | 774 | | |
779 | | - | |
780 | 775 | | |
781 | 776 | | |
782 | 777 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
455 | 454 | | |
456 | 455 | | |
457 | 456 | | |
458 | | - | |
459 | 457 | | |
460 | 458 | | |
461 | 459 | | |
| |||
611 | 609 | | |
612 | 610 | | |
613 | 611 | | |
614 | | - | |
615 | 612 | | |
616 | 613 | | |
617 | 614 | | |
| |||
930 | 927 | | |
931 | 928 | | |
932 | 929 | | |
933 | | - | |
934 | 930 | | |
935 | 931 | | |
936 | 932 | | |
| |||
1073 | 1069 | | |
1074 | 1070 | | |
1075 | 1071 | | |
1076 | | - | |
1077 | 1072 | | |
1078 | 1073 | | |
1079 | 1074 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
457 | 456 | | |
458 | 457 | | |
459 | 458 | | |
460 | | - | |
461 | 459 | | |
462 | 460 | | |
463 | 461 | | |
| |||
610 | 608 | | |
611 | 609 | | |
612 | 610 | | |
613 | | - | |
614 | 611 | | |
615 | 612 | | |
616 | 613 | | |
| |||
926 | 923 | | |
927 | 924 | | |
928 | 925 | | |
929 | | - | |
930 | 926 | | |
931 | 927 | | |
932 | 928 | | |
| |||
1070 | 1066 | | |
1071 | 1067 | | |
1072 | 1068 | | |
1073 | | - | |
1074 | 1069 | | |
1075 | 1070 | | |
1076 | 1071 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
360 | 359 | | |
361 | 360 | | |
362 | | - | |
363 | 361 | | |
364 | 362 | | |
365 | 363 | | |
| |||
488 | 486 | | |
489 | 487 | | |
490 | 488 | | |
491 | | - | |
492 | 489 | | |
493 | 490 | | |
494 | 491 | | |
| |||
723 | 720 | | |
724 | 721 | | |
725 | 722 | | |
726 | | - | |
727 | 723 | | |
728 | 724 | | |
729 | 725 | | |
| |||
828 | 824 | | |
829 | 825 | | |
830 | 826 | | |
831 | | - | |
832 | 827 | | |
833 | 828 | | |
834 | 829 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
530 | 529 | | |
531 | 530 | | |
532 | | - | |
533 | 531 | | |
534 | 532 | | |
535 | 533 | | |
| |||
725 | 723 | | |
726 | 724 | | |
727 | 725 | | |
728 | | - | |
729 | 726 | | |
730 | 727 | | |
731 | 728 | | |
| |||
1061 | 1058 | | |
1062 | 1059 | | |
1063 | 1060 | | |
1064 | | - | |
1065 | 1061 | | |
1066 | 1062 | | |
1067 | 1063 | | |
| |||
1226 | 1222 | | |
1227 | 1223 | | |
1228 | 1224 | | |
1229 | | - | |
1230 | 1225 | | |
1231 | 1226 | | |
1232 | 1227 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
298 | 297 | | |
299 | 298 | | |
300 | | - | |
301 | 299 | | |
302 | 300 | | |
303 | 301 | | |
| |||
397 | 395 | | |
398 | 396 | | |
399 | 397 | | |
400 | | - | |
401 | 398 | | |
402 | 399 | | |
403 | 400 | | |
| |||
579 | 576 | | |
580 | 577 | | |
581 | 578 | | |
582 | | - | |
583 | 579 | | |
584 | 580 | | |
585 | 581 | | |
| |||
663 | 659 | | |
664 | 660 | | |
665 | 661 | | |
666 | | - | |
667 | 662 | | |
668 | 663 | | |
669 | 664 | | |
| |||
0 commit comments