Commit b4acc79
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 e43d9b9 commit b4acc79
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 | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
363 | | - | |
364 | 363 | | |
365 | 364 | | |
366 | | - | |
367 | 365 | | |
368 | 366 | | |
369 | 367 | | |
| |||
471 | 469 | | |
472 | 470 | | |
473 | 471 | | |
474 | | - | |
475 | 472 | | |
476 | 473 | | |
477 | 474 | | |
| |||
685 | 682 | | |
686 | 683 | | |
687 | 684 | | |
688 | | - | |
689 | 685 | | |
690 | 686 | | |
691 | 687 | | |
| |||
778 | 774 | | |
779 | 775 | | |
780 | 776 | | |
781 | | - | |
782 | 777 | | |
783 | 778 | | |
784 | 779 | | |
| |||
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 | | |
| |||
613 | 611 | | |
614 | 612 | | |
615 | 613 | | |
616 | | - | |
617 | 614 | | |
618 | 615 | | |
619 | 616 | | |
| |||
932 | 929 | | |
933 | 930 | | |
934 | 931 | | |
935 | | - | |
936 | 932 | | |
937 | 933 | | |
938 | 934 | | |
| |||
1075 | 1071 | | |
1076 | 1072 | | |
1077 | 1073 | | |
1078 | | - | |
1079 | 1074 | | |
1080 | 1075 | | |
1081 | 1076 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
457 | | - | |
458 | 457 | | |
459 | 458 | | |
460 | 459 | | |
461 | | - | |
462 | 460 | | |
463 | 461 | | |
464 | 462 | | |
| |||
611 | 609 | | |
612 | 610 | | |
613 | 611 | | |
614 | | - | |
615 | 612 | | |
616 | 613 | | |
617 | 614 | | |
| |||
927 | 924 | | |
928 | 925 | | |
929 | 926 | | |
930 | | - | |
931 | 927 | | |
932 | 928 | | |
933 | 929 | | |
| |||
1071 | 1067 | | |
1072 | 1068 | | |
1073 | 1069 | | |
1074 | | - | |
1075 | 1070 | | |
1076 | 1071 | | |
1077 | 1072 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
358 | 357 | | |
359 | 358 | | |
360 | | - | |
361 | 359 | | |
362 | 360 | | |
363 | 361 | | |
| |||
486 | 484 | | |
487 | 485 | | |
488 | 486 | | |
489 | | - | |
490 | 487 | | |
491 | 488 | | |
492 | 489 | | |
| |||
721 | 718 | | |
722 | 719 | | |
723 | 720 | | |
724 | | - | |
725 | 721 | | |
726 | 722 | | |
727 | 723 | | |
| |||
826 | 822 | | |
827 | 823 | | |
828 | 824 | | |
829 | | - | |
830 | 825 | | |
831 | 826 | | |
832 | 827 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
532 | 531 | | |
533 | 532 | | |
534 | | - | |
535 | 533 | | |
536 | 534 | | |
537 | 535 | | |
| |||
728 | 726 | | |
729 | 727 | | |
730 | 728 | | |
731 | | - | |
732 | 729 | | |
733 | 730 | | |
734 | 731 | | |
| |||
1062 | 1059 | | |
1063 | 1060 | | |
1064 | 1061 | | |
1065 | | - | |
1066 | 1062 | | |
1067 | 1063 | | |
1068 | 1064 | | |
| |||
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