@alloy-js/typescript 0.23.0-dev.9 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/dev/src/components/ImportStatement.js +42 -10
  3. package/dist/dev/src/components/ImportStatement.js.map +1 -1
  4. package/dist/dev/src/name-conflict-resolver.js +8 -2
  5. package/dist/dev/src/name-conflict-resolver.js.map +1 -1
  6. package/dist/dev/src/symbols/index.js +9 -3
  7. package/dist/dev/src/symbols/index.js.map +1 -1
  8. package/dist/dev/src/symbols/reference.js +19 -9
  9. package/dist/dev/src/symbols/reference.js.map +1 -1
  10. package/dist/dev/src/symbols/ts-module-scope.js +66 -2
  11. package/dist/dev/src/symbols/ts-module-scope.js.map +1 -1
  12. package/dist/dev/test/externals.test.js +17 -13
  13. package/dist/dev/test/externals.test.js.map +1 -1
  14. package/dist/dev/test/imports-reactive.test.js +223 -0
  15. package/dist/dev/test/imports-reactive.test.js.map +1 -0
  16. package/dist/dev/test/imports.test.js +262 -80
  17. package/dist/dev/test/imports.test.js.map +1 -1
  18. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  19. package/dist/src/components/ImportStatement.js +16 -8
  20. package/dist/src/components/ImportStatement.js.map +1 -1
  21. package/dist/src/name-conflict-resolver.d.ts.map +1 -1
  22. package/dist/src/name-conflict-resolver.js +8 -2
  23. package/dist/src/name-conflict-resolver.js.map +1 -1
  24. package/dist/src/symbols/index.d.ts.map +1 -1
  25. package/dist/src/symbols/index.js +9 -3
  26. package/dist/src/symbols/index.js.map +1 -1
  27. package/dist/src/symbols/reference.d.ts.map +1 -1
  28. package/dist/src/symbols/reference.js +13 -3
  29. package/dist/src/symbols/reference.js.map +1 -1
  30. package/dist/src/symbols/ts-module-scope.d.ts +7 -0
  31. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  32. package/dist/src/symbols/ts-module-scope.js +66 -2
  33. package/dist/src/symbols/ts-module-scope.js.map +1 -1
  34. package/dist/test/externals.test.js +5 -1
  35. package/dist/test/externals.test.js.map +1 -1
  36. package/dist/test/imports-reactive.test.d.ts +2 -0
  37. package/dist/test/imports-reactive.test.d.ts.map +1 -0
  38. package/dist/test/imports-reactive.test.js +167 -0
  39. package/dist/test/imports-reactive.test.js.map +1 -0
  40. package/dist/test/imports.test.js +121 -3
  41. package/dist/test/imports.test.js.map +1 -1
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/docs/api/types/TSModuleScope.md +9 -8
  44. package/package.json +6 -6
  45. package/src/components/ImportStatement.tsx +26 -12
  46. package/src/name-conflict-resolver.ts +8 -2
  47. package/src/symbols/index.ts +18 -3
  48. package/src/symbols/reference.tsx +17 -6
  49. package/src/symbols/ts-module-scope.ts +79 -2
  50. package/temp/api.json +66 -0
  51. package/test/externals.test.tsx +5 -1
  52. package/test/imports-reactive.test.tsx +128 -0
  53. package/test/imports.test.tsx +136 -2
@@ -276,8 +276,14 @@ it("works with importing the same name many times from different files with the
276
276
  ).toRenderTo({
277
277
  "test-import.ts": `
278
278
  import { conflict, type MyInterface } from "./test1.js";
279
- import { conflict as conflict_2, type MyInterface as MyInterface_2 } from "./test2.js";
280
- import { conflict as conflict_3, type MyInterface as MyInterface_3 } from "./test3.js";
279
+ import {
280
+ conflict as conflict_2,
281
+ type MyInterface as MyInterface_2,
282
+ } from "./test2.js";
283
+ import {
284
+ conflict as conflict_3,
285
+ type MyInterface as MyInterface_3,
286
+ } from "./test3.js";
281
287
 
282
288
  const one: MyInterface = conflict;
283
289
  const two: MyInterface_2 = conflict_2;
@@ -634,3 +640,131 @@ describe("type imports", () => {
634
640
  });
635
641
  });
636
642
  });
643
+
644
+ describe("import formatting", () => {
645
+ it("breaks long imports across lines", () => {
646
+ const lib = createPackage({
647
+ name: "testLib",
648
+ version: "1.0.0",
649
+ descriptor: {
650
+ ".": {
651
+ named: [
652
+ "alphaItem",
653
+ "bravoItem",
654
+ "charlieItem",
655
+ "deltaItem",
656
+ "echoItem",
657
+ "foxtrotItem",
658
+ ],
659
+ },
660
+ },
661
+ });
662
+
663
+ expect(
664
+ <Output externals={[lib]} printWidth={40}>
665
+ <ts.SourceFile path="test.ts">
666
+ {lib.alphaItem};
667
+ <hbr />
668
+ {lib.bravoItem};
669
+ <hbr />
670
+ {lib.charlieItem};
671
+ <hbr />
672
+ {lib.deltaItem};
673
+ <hbr />
674
+ {lib.echoItem};
675
+ <hbr />
676
+ {lib.foxtrotItem};
677
+ </ts.SourceFile>
678
+ </Output>,
679
+ ).toRenderTo({
680
+ "test.ts": `
681
+ import {
682
+ alphaItem,
683
+ bravoItem,
684
+ charlieItem,
685
+ deltaItem,
686
+ echoItem,
687
+ foxtrotItem,
688
+ } from "testLib";
689
+
690
+ alphaItem;
691
+ bravoItem;
692
+ charlieItem;
693
+ deltaItem;
694
+ echoItem;
695
+ foxtrotItem;
696
+ `,
697
+ });
698
+ });
699
+
700
+ it("keeps short imports on one line", () => {
701
+ const lib = createPackage({
702
+ name: "testLib",
703
+ version: "1.0.0",
704
+ descriptor: {
705
+ ".": { named: ["a", "b"] },
706
+ },
707
+ });
708
+
709
+ expect(
710
+ <Output externals={[lib]} printWidth={40}>
711
+ <ts.SourceFile path="test.ts">
712
+ {lib.a};
713
+ <hbr />
714
+ {lib.b};
715
+ </ts.SourceFile>
716
+ </Output>,
717
+ ).toRenderTo({
718
+ "test.ts": `
719
+ import { a, b } from "testLib";
720
+
721
+ a;
722
+ b;
723
+ `,
724
+ });
725
+ });
726
+
727
+ it("breaks long default + named imports", () => {
728
+ const lib = createPackage({
729
+ name: "testLib",
730
+ version: "1.0.0",
731
+ descriptor: {
732
+ ".": {
733
+ default: "Big",
734
+ named: ["alphaItem", "bravoItem", "charlieItem", "deltaItem"],
735
+ },
736
+ },
737
+ });
738
+
739
+ expect(
740
+ <Output externals={[lib]} printWidth={40}>
741
+ <ts.SourceFile path="test.ts">
742
+ {lib.default};
743
+ <hbr />
744
+ {lib.alphaItem};
745
+ <hbr />
746
+ {lib.bravoItem};
747
+ <hbr />
748
+ {lib.charlieItem};
749
+ <hbr />
750
+ {lib.deltaItem};
751
+ </ts.SourceFile>
752
+ </Output>,
753
+ ).toRenderTo({
754
+ "test.ts": `
755
+ import Big, {
756
+ alphaItem,
757
+ bravoItem,
758
+ charlieItem,
759
+ deltaItem,
760
+ } from "testLib";
761
+
762
+ Big;
763
+ alphaItem;
764
+ bravoItem;
765
+ charlieItem;
766
+ deltaItem;
767
+ `,
768
+ });
769
+ });
770
+ });