@alloy-js/core 0.7.0 → 0.9.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 (131) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/babel.config.cjs +1 -4
  3. package/dist/src/binder.d.ts +14 -12
  4. package/dist/src/binder.d.ts.map +1 -1
  5. package/dist/src/binder.js +26 -23
  6. package/dist/src/binder.js.map +1 -1
  7. package/dist/src/code.d.ts +11 -2
  8. package/dist/src/code.d.ts.map +1 -1
  9. package/dist/src/code.js +27 -2
  10. package/dist/src/code.js.map +1 -1
  11. package/dist/src/components/Block.d.ts +2 -2
  12. package/dist/src/components/Block.d.ts.map +1 -1
  13. package/dist/src/components/Block.js +6 -5
  14. package/dist/src/components/Block.js.map +1 -1
  15. package/dist/src/components/Declaration.d.ts +31 -7
  16. package/dist/src/components/Declaration.d.ts.map +1 -1
  17. package/dist/src/components/Declaration.js +15 -7
  18. package/dist/src/components/Declaration.js.map +1 -1
  19. package/dist/src/components/For.d.ts +8 -2
  20. package/dist/src/components/For.d.ts.map +1 -1
  21. package/dist/src/components/For.js +2 -3
  22. package/dist/src/components/For.js.map +1 -1
  23. package/dist/src/components/Indent.d.ts +29 -1
  24. package/dist/src/components/Indent.d.ts.map +1 -1
  25. package/dist/src/components/Indent.js +7 -2
  26. package/dist/src/components/Indent.js.map +1 -1
  27. package/dist/src/components/List.d.ts +7 -3
  28. package/dist/src/components/List.d.ts.map +1 -1
  29. package/dist/src/components/List.js +1 -16
  30. package/dist/src/components/List.js.map +1 -1
  31. package/dist/src/components/MemberDeclaration.d.ts +35 -5
  32. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  33. package/dist/src/components/MemberDeclaration.js +18 -7
  34. package/dist/src/components/MemberDeclaration.js.map +1 -1
  35. package/dist/src/components/MemberScope.d.ts +2 -0
  36. package/dist/src/components/MemberScope.d.ts.map +1 -1
  37. package/dist/src/components/MemberScope.js +2 -0
  38. package/dist/src/components/MemberScope.js.map +1 -1
  39. package/dist/src/components/Prose.d.ts +10 -0
  40. package/dist/src/components/Prose.d.ts.map +1 -0
  41. package/dist/src/components/Prose.js +23 -0
  42. package/dist/src/components/Prose.js.map +1 -0
  43. package/dist/src/components/Scope.d.ts +33 -2
  44. package/dist/src/components/Scope.d.ts.map +1 -1
  45. package/dist/src/components/Scope.js +20 -4
  46. package/dist/src/components/Scope.js.map +1 -1
  47. package/dist/src/components/SourceFile.d.ts +5 -0
  48. package/dist/src/components/SourceFile.d.ts.map +1 -1
  49. package/dist/src/components/SourceFile.js +10 -1
  50. package/dist/src/components/SourceFile.js.map +1 -1
  51. package/dist/src/components/index.d.ts +1 -0
  52. package/dist/src/components/index.d.ts.map +1 -1
  53. package/dist/src/components/index.js +1 -0
  54. package/dist/src/components/index.js.map +1 -1
  55. package/dist/src/components/stc/index.d.ts +19 -95
  56. package/dist/src/components/stc/index.d.ts.map +1 -1
  57. package/dist/src/components/stc/index.js +3 -6
  58. package/dist/src/components/stc/index.js.map +1 -1
  59. package/dist/src/components/stc/sti.d.ts +9 -0
  60. package/dist/src/components/stc/sti.d.ts.map +1 -0
  61. package/dist/src/components/stc/sti.js +10 -0
  62. package/dist/src/components/stc/sti.js.map +1 -0
  63. package/dist/src/context/assignment.d.ts +6 -0
  64. package/dist/src/context/assignment.d.ts.map +1 -1
  65. package/dist/src/context/assignment.js +7 -0
  66. package/dist/src/context/assignment.js.map +1 -1
  67. package/dist/src/context.d.ts +2 -0
  68. package/dist/src/context.d.ts.map +1 -1
  69. package/dist/src/context.js +12 -9
  70. package/dist/src/context.js.map +1 -1
  71. package/dist/src/index.d.ts +2 -1
  72. package/dist/src/index.d.ts.map +1 -1
  73. package/dist/src/index.js +2 -1
  74. package/dist/src/index.js.map +1 -1
  75. package/dist/src/jsx-runtime.d.ts +93 -2
  76. package/dist/src/jsx-runtime.d.ts.map +1 -1
  77. package/dist/src/jsx-runtime.js +51 -3
  78. package/dist/src/jsx-runtime.js.map +1 -1
  79. package/dist/src/stc.d.ts +5 -7
  80. package/dist/src/stc.d.ts.map +1 -1
  81. package/dist/src/stc.js +11 -23
  82. package/dist/src/stc.js.map +1 -1
  83. package/dist/src/sti.d.ts +11 -0
  84. package/dist/src/sti.d.ts.map +1 -0
  85. package/dist/src/sti.js +31 -0
  86. package/dist/src/sti.js.map +1 -0
  87. package/dist/src/tap.d.ts +69 -6
  88. package/dist/src/tap.d.ts.map +1 -1
  89. package/dist/src/tap.js +70 -0
  90. package/dist/src/tap.js.map +1 -1
  91. package/dist/src/utils.d.ts +5 -0
  92. package/dist/src/utils.d.ts.map +1 -1
  93. package/dist/src/utils.js +20 -0
  94. package/dist/src/utils.js.map +1 -1
  95. package/dist/test/components/prose.test.d.ts +2 -0
  96. package/dist/test/components/prose.test.d.ts.map +1 -0
  97. package/dist/test/props-with-defaults.test.d.ts +2 -0
  98. package/dist/test/props-with-defaults.test.d.ts.map +1 -0
  99. package/dist/tsconfig.tsbuildinfo +1 -1
  100. package/package.json +3 -3
  101. package/src/binder.ts +44 -29
  102. package/src/code.ts +37 -3
  103. package/src/components/Block.tsx +3 -6
  104. package/src/components/Declaration.tsx +43 -11
  105. package/src/components/For.tsx +16 -4
  106. package/src/components/Indent.tsx +38 -5
  107. package/src/components/List.tsx +14 -40
  108. package/src/components/MemberDeclaration.tsx +51 -12
  109. package/src/components/MemberScope.tsx +2 -0
  110. package/src/components/Prose.tsx +35 -0
  111. package/src/components/Scope.tsx +45 -5
  112. package/src/components/SourceFile.tsx +10 -0
  113. package/src/components/index.tsx +1 -0
  114. package/src/components/stc/index.ts +3 -6
  115. package/src/components/stc/sti.ts +10 -0
  116. package/src/context/assignment.ts +7 -1
  117. package/src/context.ts +15 -11
  118. package/src/index.ts +3 -0
  119. package/src/jsx-runtime.ts +168 -3
  120. package/src/stc.ts +38 -59
  121. package/src/sti.ts +63 -0
  122. package/src/tap.ts +69 -6
  123. package/src/{utils.ts → utils.tsx} +45 -0
  124. package/temp/api.json +1657 -440
  125. package/test/components/declaration.test.tsx +1 -1
  126. package/test/components/prose.test.tsx +36 -0
  127. package/test/components/source-file.test.tsx +17 -0
  128. package/test/control-flow/for.test.tsx +17 -0
  129. package/test/props-with-defaults.test.ts +97 -0
  130. package/test/symbols.test.ts +0 -25
  131. package/vitest.config.ts +2 -10
@@ -19,7 +19,7 @@ it("creates and cleans up a symbol", () => {
19
19
  const template = (
20
20
  <Output>
21
21
  <GetBinder />
22
- <Scope>
22
+ <Scope name="foo">
23
23
  {doDecl.value ?
24
24
  <Declaration name="foo"></Declaration>
25
25
  : ""}
@@ -0,0 +1,36 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { Prose } from "../../src/components/Prose.jsx";
3
+ import "../../testing/extend-expect.js";
4
+ import { d } from "../../testing/render.js";
5
+
6
+ describe("Prose", () => {
7
+ it("formats properly", () => {
8
+ const template = (
9
+ <>
10
+ <Prose>
11
+ This is a long paragraph that should end up being broken into multiple
12
+ lines.
13
+ </Prose>
14
+ <hbr />
15
+ <hbr />
16
+ <Prose>
17
+ This is another paragraph. There should be a couple breaks in front of
18
+ it.
19
+ </Prose>
20
+ </>
21
+ );
22
+
23
+ expect(template).toRenderTo(
24
+ d`
25
+ This is a long paragraph that
26
+ should end up being broken
27
+ into multiple lines.
28
+
29
+ This is another paragraph.
30
+ There should be a couple
31
+ breaks in front of it.
32
+ `,
33
+ { printWidth: 30 },
34
+ );
35
+ });
36
+ });
@@ -9,6 +9,7 @@ import {
9
9
  import { expect, it } from "vitest";
10
10
  import { SourceDirectoryContext } from "../../src/context/source-directory.js";
11
11
  import "../../testing/extend-expect.js";
12
+ import { d } from "../../testing/render.js";
12
13
 
13
14
  it("tracks its content", () => {
14
15
  let context;
@@ -51,3 +52,19 @@ it("has reactive context", () => {
51
52
 
52
53
  expect(tree.contents[1].contents).toEqual("hi.txt contents.txt");
53
54
  });
55
+
56
+ it("Includes header", () => {
57
+ const header = <># This is a header</>;
58
+ const tree = render(
59
+ <Output>
60
+ <SourceFile path="hi.txt" filetype="text" header={header}>
61
+ hello!
62
+ </SourceFile>
63
+ </Output>,
64
+ );
65
+
66
+ expect(tree.contents[0].contents).toEqual(d`
67
+ # This is a header
68
+ hello!
69
+ `);
70
+ });
@@ -34,6 +34,23 @@ it("handles map entries", () => {
34
34
  `);
35
35
  });
36
36
 
37
+ it("handles iterators", () => {
38
+ const iterator = new Map([["a", { name: "foo" }]]).entries();
39
+ const template = (
40
+ <For each={iterator}>
41
+ {([key, value]) => (
42
+ <>
43
+ {key}: {value.name}
44
+ </>
45
+ )}
46
+ </For>
47
+ );
48
+
49
+ expect(template).toRenderTo(`
50
+ a: foo
51
+ `);
52
+ });
53
+
37
54
  it("handles maps", () => {
38
55
  const map = new Map([["a", { name: "foo" }]]);
39
56
  const template = (
@@ -0,0 +1,97 @@
1
+ import { effect, reactive } from "@vue/reactivity";
2
+ import { expect, it, vi } from "vitest";
3
+ import { defaultProps } from "../src/jsx-runtime.js";
4
+
5
+ it("applies defaults to regular object props", () => {
6
+ const props = {
7
+ a: 1,
8
+ b: 2,
9
+ c: undefined as number | undefined,
10
+ };
11
+
12
+ const dProps = defaultProps(props, { a: 10, c: 20 });
13
+
14
+ expect(dProps).toEqual({ a: 1, b: 2, c: 20 });
15
+ });
16
+
17
+ it("applies defaults with getters without invoking them", () => {
18
+ const getterA = vi.fn(() => 1);
19
+ const getterB = vi.fn(() => undefined as number | undefined);
20
+ const props = {
21
+ get a() {
22
+ return getterA();
23
+ },
24
+ get b() {
25
+ return getterB();
26
+ },
27
+ c: 3,
28
+ };
29
+
30
+ const dProps = defaultProps(props, { b: 20, c: 30 });
31
+
32
+ expect(getterA).not.toHaveBeenCalled();
33
+ expect(getterB).not.toHaveBeenCalled();
34
+
35
+ const value = dProps.b;
36
+ expect(getterB).toHaveBeenCalledTimes(1);
37
+ expect(value).toEqual(20);
38
+ });
39
+
40
+ it("applies defaults to reactives without observing them initially", () => {
41
+ const props = reactive({
42
+ a: 1,
43
+ b: 2,
44
+ c: undefined as number | undefined,
45
+ });
46
+
47
+ const defaults = defaultProps(props, { c: 10 });
48
+
49
+ expect(defaults.a).toBe(1);
50
+ expect(defaults.b).toBe(2);
51
+ expect(defaults.c).toBe(10);
52
+ });
53
+
54
+ it("ensures effect is not triggered by defaults but by accessing reactive props", () => {
55
+ const props = reactive({
56
+ a: 1,
57
+ b: 2,
58
+ c: undefined as number | undefined,
59
+ });
60
+
61
+ let withDefaults: any;
62
+ const splitEffect = vi.fn(() => {
63
+ withDefaults = defaultProps(props, { c: 10 });
64
+ });
65
+
66
+ effect(splitEffect);
67
+ expect(splitEffect).toHaveBeenCalledTimes(1);
68
+
69
+ const observeEffect = vi.fn(() => {
70
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
71
+ withDefaults.a;
72
+ });
73
+ effect(observeEffect);
74
+ expect(observeEffect).toHaveBeenCalledTimes(1);
75
+
76
+ props.a = 2;
77
+ expect(splitEffect).toHaveBeenCalledTimes(1);
78
+ expect(observeEffect).toHaveBeenCalledTimes(2);
79
+ });
80
+
81
+ it("applies defaults to reactives", () => {
82
+ const props = reactive({
83
+ a: 1,
84
+ b: 2,
85
+ c: undefined as number | undefined,
86
+ });
87
+
88
+ const withDefaults = defaultProps(props, { c: 10 });
89
+
90
+ expect(withDefaults.c).toBe(10);
91
+ props.c = 20;
92
+
93
+ expect(withDefaults.c).toBe(20);
94
+ props.c = undefined;
95
+
96
+ expect(withDefaults.c).toBe(10);
97
+ });
@@ -296,31 +296,6 @@ describe("instance members", () => {
296
296
  expect(pathUp).toEqual([]);
297
297
  expect(memberPath).toEqual([instance]);
298
298
  });
299
-
300
- it("doesn't resolve from outside the member scope", () => {
301
- const binder = createOutputBinder();
302
- const {
303
- scopes: { root },
304
- symbols: { instance },
305
- } = createScopeTree(binder, {
306
- root: {
307
- symbols: {
308
- root: {
309
- flags: OutputSymbolFlags.InstanceMemberContainer,
310
- instanceMembers: {
311
- instance: {
312
- flags: OutputSymbolFlags.InstanceMember,
313
- },
314
- },
315
- },
316
- },
317
- },
318
- });
319
-
320
- expect(() =>
321
- binder.resolveDeclarationByKey(root, undefined, instance.refkeys[0]),
322
- ).toThrow(/Cannot resolve member symbols/);
323
- });
324
299
  });
325
300
 
326
301
  describe("instantiating members", () => {
package/vitest.config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { babel } from "@rollup/plugin-babel";
1
+ import alloyPlugin from "@alloy-js/rollup-plugin";
2
2
  import { defineConfig } from "vitest/config";
3
3
 
4
4
  export default defineConfig({
@@ -6,13 +6,5 @@ export default defineConfig({
6
6
  jsx: "preserve",
7
7
  sourcemap: "both",
8
8
  },
9
- plugins: [
10
- babel({
11
- inputSourceMap: true as any,
12
- sourceMaps: "both",
13
- babelHelpers: "bundled",
14
- extensions: [".ts", ".tsx"],
15
- presets: ["@babel/preset-typescript", ["@alloy-js/babel-preset"]],
16
- }),
17
- ],
9
+ plugins: [alloyPlugin()],
18
10
  });