Repository navigation
Commit da779b5
authored
Avoid emitting extra blank lines for JS library items in
This change is mostly about cleaning up the code in `addFromLibrary`.
Previously, `depsText` in `src/jsifier.mjs` had two issues that caused
extra blank lines in unoptimized JS output:
1. When `addFromLibrary` was called on an already-emitted dependency, it
returned `undefined`. Using `.filter((x) => x != '')` did not filter
out `undefined`, causing `.join('\n')` to emit an empty line for each
already-emitted dependency.
2. Because `deps` is always an array (`??= []`), the `deps ? ... : ''`
ternary always took the truthy branch and appended `'\n'`, even when
no dependencies were emitted. This gave every `addFromLibrary` return
value a leading `'\n'`.
Use a `joinChunks` helper (`chunks.filter(Boolean).join('\n')`) to join
non-empty dependency, doc comment, and content strings without extra
newlines.
Also update `indentify` in `src/parseTools.mjs` to indent the first line
of non-empty strings, which previously only happened because of the
accidental leading `'\n'` on each item.jsifier.mjs (emscripten-core#28044)1 parent 45a6cff commit da779b5
4 files changed
Lines changed: 18 additions & 33 deletions
File tree
- src
- test/codesize
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
| 871 | + | |
875 | 872 | | |
876 | 873 | | |
877 | 874 | | |
| |||
880 | 877 | | |
881 | 878 | | |
882 | 879 | | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
889 | 884 | | |
890 | 885 | | |
891 | 886 | | |
892 | 887 | | |
893 | 888 | | |
894 | 889 | | |
895 | | - | |
896 | | - | |
| 890 | + | |
| 891 | + | |
897 | 892 | | |
898 | | - | |
| 893 | + | |
899 | 894 | | |
900 | 895 | | |
901 | 896 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
355 | | - | |
| 355 | + | |
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
715 | | - | |
716 | 715 | | |
717 | 716 | | |
718 | 717 | | |
719 | 718 | | |
720 | 719 | | |
721 | 720 | | |
722 | 721 | | |
723 | | - | |
724 | 722 | | |
725 | 723 | | |
726 | | - | |
727 | 724 | | |
728 | 725 | | |
729 | | - | |
730 | 726 | | |
731 | 727 | | |
732 | | - | |
733 | 728 | | |
734 | 729 | | |
735 | 730 | | |
736 | 731 | | |
737 | 732 | | |
738 | 733 | | |
739 | | - | |
740 | 734 | | |
741 | 735 | | |
742 | 736 | | |
743 | 737 | | |
744 | 738 | | |
745 | 739 | | |
746 | | - | |
747 | 740 | | |
748 | | - | |
749 | 741 | | |
750 | | - | |
751 | 742 | | |
752 | 743 | | |
753 | 744 | | |
| |||
757 | 748 | | |
758 | 749 | | |
759 | 750 | | |
760 | | - | |
761 | 751 | | |
762 | 752 | | |
763 | 753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
0 commit comments