@alloy-js/core 0.6.0 → 0.8.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.
- package/CHANGELOG.md +37 -0
- package/babel.config.cjs +1 -4
- package/dist/src/binder.d.ts +15 -13
- package/dist/src/binder.d.ts.map +1 -1
- package/dist/src/binder.js +34 -34
- package/dist/src/binder.js.map +1 -1
- package/dist/src/code.d.ts +11 -2
- package/dist/src/code.d.ts.map +1 -1
- package/dist/src/code.js +27 -2
- package/dist/src/code.js.map +1 -1
- package/dist/src/components/Block.d.ts +2 -2
- package/dist/src/components/Block.d.ts.map +1 -1
- package/dist/src/components/Block.js +6 -5
- package/dist/src/components/Block.js.map +1 -1
- package/dist/src/components/Declaration.d.ts +31 -7
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +15 -7
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/For.d.ts +6 -0
- package/dist/src/components/For.d.ts.map +1 -1
- package/dist/src/components/For.js +2 -3
- package/dist/src/components/For.js.map +1 -1
- package/dist/src/components/Indent.d.ts +29 -1
- package/dist/src/components/Indent.d.ts.map +1 -1
- package/dist/src/components/Indent.js +7 -2
- package/dist/src/components/Indent.js.map +1 -1
- package/dist/src/components/List.d.ts +7 -3
- package/dist/src/components/List.d.ts.map +1 -1
- package/dist/src/components/List.js +1 -16
- package/dist/src/components/List.js.map +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +35 -5
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +18 -7
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/MemberScope.d.ts +2 -0
- package/dist/src/components/MemberScope.d.ts.map +1 -1
- package/dist/src/components/MemberScope.js +2 -0
- package/dist/src/components/MemberScope.js.map +1 -1
- package/dist/src/components/Prose.d.ts +10 -0
- package/dist/src/components/Prose.d.ts.map +1 -0
- package/dist/src/components/Prose.js +23 -0
- package/dist/src/components/Prose.js.map +1 -0
- package/dist/src/components/Scope.d.ts +33 -2
- package/dist/src/components/Scope.d.ts.map +1 -1
- package/dist/src/components/Scope.js +20 -4
- package/dist/src/components/Scope.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +5 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +10 -1
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +19 -95
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +3 -6
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/components/stc/sti.d.ts +9 -0
- package/dist/src/components/stc/sti.d.ts.map +1 -0
- package/dist/src/components/stc/sti.js +10 -0
- package/dist/src/components/stc/sti.js.map +1 -0
- package/dist/src/context/assignment.d.ts +6 -0
- package/dist/src/context/assignment.d.ts.map +1 -1
- package/dist/src/context/assignment.js +7 -0
- package/dist/src/context/assignment.js.map +1 -1
- package/dist/src/context.d.ts +2 -0
- package/dist/src/context.d.ts.map +1 -1
- package/dist/src/context.js +12 -9
- package/dist/src/context.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +98 -1
- package/dist/src/jsx-runtime.d.ts.map +1 -1
- package/dist/src/jsx-runtime.js +46 -1
- package/dist/src/jsx-runtime.js.map +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +12 -0
- package/dist/src/render.js.map +1 -1
- package/dist/src/stc.d.ts +5 -7
- package/dist/src/stc.d.ts.map +1 -1
- package/dist/src/stc.js +11 -23
- package/dist/src/stc.js.map +1 -1
- package/dist/src/sti.d.ts +11 -0
- package/dist/src/sti.d.ts.map +1 -0
- package/dist/src/sti.js +31 -0
- package/dist/src/sti.js.map +1 -0
- package/dist/src/tap.d.ts +69 -6
- package/dist/src/tap.d.ts.map +1 -1
- package/dist/src/tap.js +70 -0
- package/dist/src/tap.js.map +1 -1
- package/dist/src/utils.d.ts +5 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +20 -0
- package/dist/src/utils.js.map +1 -1
- package/dist/src/write-output.js +3 -3
- package/dist/src/write-output.js.map +1 -1
- package/dist/test/components/prose.test.d.ts +2 -0
- package/dist/test/components/prose.test.d.ts.map +1 -0
- package/dist/test/props-with-defaults.test.d.ts +2 -0
- package/dist/test/props-with-defaults.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/binder.ts +46 -40
- package/src/code.ts +37 -3
- package/src/components/Block.tsx +3 -6
- package/src/components/Declaration.tsx +43 -11
- package/src/components/For.tsx +10 -3
- package/src/components/Indent.tsx +38 -5
- package/src/components/List.tsx +14 -40
- package/src/components/MemberDeclaration.tsx +51 -12
- package/src/components/MemberScope.tsx +2 -0
- package/src/components/Prose.tsx +35 -0
- package/src/components/Scope.tsx +45 -5
- package/src/components/SourceFile.tsx +10 -0
- package/src/components/index.tsx +1 -0
- package/src/components/stc/index.ts +3 -6
- package/src/components/stc/sti.ts +10 -0
- package/src/context/assignment.ts +7 -1
- package/src/context.ts +15 -11
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +162 -0
- package/src/render.ts +14 -0
- package/src/stc.ts +35 -56
- package/src/sti.ts +63 -0
- package/src/tap.ts +69 -6
- package/src/{utils.ts → utils.tsx} +45 -0
- package/src/write-output.ts +3 -3
- package/temp/api.json +1563 -393
- package/test/components/declaration.test.tsx +1 -1
- package/test/components/prose.test.tsx +36 -0
- package/test/components/source-file.test.tsx +17 -0
- package/test/props-with-defaults.test.ts +97 -0
- package/test/symbols.test.ts +14 -33
- package/vitest.config.ts +2 -10
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
package/test/symbols.test.ts
CHANGED
|
@@ -158,7 +158,7 @@ describe("static members", () => {
|
|
|
158
158
|
const resolution = binder.resolveDeclarationByKey(
|
|
159
159
|
root,
|
|
160
160
|
undefined,
|
|
161
|
-
staticSym.
|
|
161
|
+
staticSym.refkeys[0],
|
|
162
162
|
);
|
|
163
163
|
expect(resolution.value).toBeDefined();
|
|
164
164
|
const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
|
|
@@ -202,7 +202,7 @@ describe("static members", () => {
|
|
|
202
202
|
const resolution = binder.resolveDeclarationByKey(
|
|
203
203
|
root,
|
|
204
204
|
undefined,
|
|
205
|
-
nested_static.
|
|
205
|
+
nested_static.refkeys[0],
|
|
206
206
|
);
|
|
207
207
|
expect(resolution.value).toBeDefined();
|
|
208
208
|
const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
|
|
@@ -284,7 +284,7 @@ describe("instance members", () => {
|
|
|
284
284
|
const resolution = binder.resolveDeclarationByKey(
|
|
285
285
|
undefined,
|
|
286
286
|
rootSym.instanceMemberScope!,
|
|
287
|
-
instance.
|
|
287
|
+
instance.refkeys[0],
|
|
288
288
|
);
|
|
289
289
|
expect(resolution.value).toBeDefined();
|
|
290
290
|
const { commonScope, pathUp, pathDown, targetDeclaration, memberPath } =
|
|
@@ -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.refkey),
|
|
322
|
-
).toThrow(/Cannot resolve member symbols/);
|
|
323
|
-
});
|
|
324
299
|
});
|
|
325
300
|
|
|
326
301
|
describe("instantiating members", () => {
|
|
@@ -349,7 +324,10 @@ describe("instantiating members", () => {
|
|
|
349
324
|
instantiation.flags & OutputSymbolFlags.InstanceMemberContainer,
|
|
350
325
|
).toBeTruthy();
|
|
351
326
|
expect(instantiation.instanceMemberScope).toBeDefined();
|
|
352
|
-
const expectedRefkey = refkey(
|
|
327
|
+
const expectedRefkey = refkey(
|
|
328
|
+
instantiation.refkeys[0],
|
|
329
|
+
instance.refkeys[0],
|
|
330
|
+
);
|
|
353
331
|
expect(
|
|
354
332
|
instantiation.instanceMemberScope!.symbolsByRefkey.get(expectedRefkey),
|
|
355
333
|
).toBeDefined();
|
|
@@ -380,7 +358,10 @@ describe("instantiating members", () => {
|
|
|
380
358
|
instantiation.flags & OutputSymbolFlags.InstanceMemberContainer,
|
|
381
359
|
).toBeTruthy();
|
|
382
360
|
expect(instantiation.instanceMemberScope).toBeDefined();
|
|
383
|
-
const expectedRefkey = refkey(
|
|
361
|
+
const expectedRefkey = refkey(
|
|
362
|
+
instantiation.refkeys[0],
|
|
363
|
+
instance.refkeys[0],
|
|
364
|
+
);
|
|
384
365
|
expect(
|
|
385
366
|
instantiation.instanceMemberScope!.symbolsByRefkey.get(expectedRefkey),
|
|
386
367
|
).toBeDefined();
|
|
@@ -393,7 +374,7 @@ describe("instantiating members", () => {
|
|
|
393
374
|
flags: OutputSymbolFlags.InstanceMember,
|
|
394
375
|
});
|
|
395
376
|
const newExpectedRefkey = refkey(
|
|
396
|
-
instantiation.
|
|
377
|
+
instantiation.refkeys[0],
|
|
397
378
|
newInstanceMemberRefkey,
|
|
398
379
|
);
|
|
399
380
|
expect(
|
|
@@ -558,7 +539,7 @@ describe("refkey resolution", () => {
|
|
|
558
539
|
|
|
559
540
|
expect(resolvedSym.value).toBe(undefined);
|
|
560
541
|
|
|
561
|
-
sym.
|
|
542
|
+
sym.refkeys[0] = key;
|
|
562
543
|
expect(resolvedSym.value?.targetDeclaration).toBe(sym);
|
|
563
544
|
});
|
|
564
545
|
});
|
|
@@ -581,7 +562,7 @@ describe("Deleting symbols", () => {
|
|
|
581
562
|
|
|
582
563
|
expect(resolvedSym.value).toBe(undefined);
|
|
583
564
|
|
|
584
|
-
sym.
|
|
565
|
+
sym.refkeys[0] = key;
|
|
585
566
|
expect(resolvedSym.value?.targetDeclaration).toBe(sym);
|
|
586
567
|
|
|
587
568
|
binder.deleteSymbol(sym);
|
package/vitest.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
});
|