@alloy-js/core 0.20.0-dev.7 → 0.20.0-dev.9
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/dist/src/components/Output.d.ts.map +1 -1
- package/dist/src/components/Output.js +16 -12
- package/dist/src/components/Output.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +5 -3
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/context/format-options.d.ts +10 -0
- package/dist/src/context/format-options.d.ts.map +1 -0
- package/dist/src/context/format-options.js +32 -0
- package/dist/src/context/format-options.js.map +1 -0
- package/dist/src/context/index.d.ts +1 -0
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +1 -0
- package/dist/src/context/index.js.map +1 -1
- package/dist/src/render.d.ts +5 -0
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/render.js +6 -7
- package/dist/src/render.js.map +1 -1
- package/dist/test/components/source-file.test.d.ts.map +1 -1
- package/dist/test/components/source-file.test.js +123 -9
- package/dist/test/components/source-file.test.js.map +1 -1
- package/dist/test/rendering/formatting.test.js +2 -0
- package/dist/test/rendering/formatting.test.js.map +1 -1
- package/dist/testing/extend-expect.js +12 -7
- package/dist/testing/extend-expect.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/Output.tsx +14 -14
- package/src/components/SourceFile.tsx +4 -2
- package/src/context/format-options.ts +31 -0
- package/src/context/index.ts +1 -0
- package/src/render.ts +21 -20
- package/temp/api.json +269 -0
- package/test/components/source-file.test.tsx +110 -12
- package/test/rendering/formatting.test.tsx +2 -0
- package/testing/extend-expect.ts +17 -19
package/testing/extend-expect.ts
CHANGED
|
@@ -40,6 +40,12 @@ expect.extend({
|
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
function isAsymmetricMatcher(value: any): value is {
|
|
44
|
+
asymmetricMatch: (other: any) => boolean;
|
|
45
|
+
} {
|
|
46
|
+
return value.$$typeof === Symbol.for("jest.asymmetricMatcher");
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
function validateRender(
|
|
44
50
|
actual: string | Record<string, string>,
|
|
45
51
|
expectedRaw: string | Record<string, string>,
|
|
@@ -73,12 +79,18 @@ function validateRender(
|
|
|
73
79
|
const expected = expectedRaw;
|
|
74
80
|
const dedentExpected: Record<string, string> = {};
|
|
75
81
|
for (const [key, value] of Object.entries(expected)) {
|
|
76
|
-
|
|
82
|
+
if (isAsymmetricMatcher(value)) {
|
|
83
|
+
dedentExpected[key] = value;
|
|
84
|
+
} else {
|
|
85
|
+
dedentExpected[key] = dedent(value);
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
const pass =
|
|
79
89
|
Object.keys(actual).length === Object.keys(expected).length &&
|
|
80
90
|
Object.entries(actual).every(([key, value]) => {
|
|
81
|
-
return dedentExpected[key]
|
|
91
|
+
return isAsymmetricMatcher(dedentExpected[key]) ?
|
|
92
|
+
dedentExpected[key].asymmetricMatch(value)
|
|
93
|
+
: dedentExpected[key] === value;
|
|
82
94
|
});
|
|
83
95
|
return {
|
|
84
96
|
pass,
|
|
@@ -98,12 +110,6 @@ function validateRender(
|
|
|
98
110
|
|
|
99
111
|
function getFilesFromTree(tree: RenderedTextTree, options?: ToRenderToOptions) {
|
|
100
112
|
const files: Record<string, string> = {};
|
|
101
|
-
// when passing Output, the first render tree child is the Output component.
|
|
102
|
-
const rootRenderOptions =
|
|
103
|
-
Array.isArray(tree) ?
|
|
104
|
-
(getContextForRenderNode(tree[0] as RenderedTextTree)?.meta
|
|
105
|
-
?.printOptions ?? {})
|
|
106
|
-
: {};
|
|
107
113
|
|
|
108
114
|
collectSourceFiles(tree);
|
|
109
115
|
// If we found no source files, we return the tree as a string.
|
|
@@ -121,17 +127,9 @@ function getFilesFromTree(tree: RenderedTextTree, options?: ToRenderToOptions) {
|
|
|
121
127
|
if (context?.meta?.sourceFile) {
|
|
122
128
|
files[context.meta.sourceFile.path] = printTree(root, {
|
|
123
129
|
printWidth:
|
|
124
|
-
options?.printWidth ??
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
tabWidth:
|
|
128
|
-
options?.tabWidth ??
|
|
129
|
-
context.meta?.printOptions?.tabWidth ??
|
|
130
|
-
rootRenderOptions.tabWidth,
|
|
131
|
-
useTabs:
|
|
132
|
-
options?.useTabs ??
|
|
133
|
-
context.meta?.printOptions?.useTabs ??
|
|
134
|
-
rootRenderOptions.useTabs,
|
|
130
|
+
options?.printWidth ?? context.meta?.printOptions?.printWidth,
|
|
131
|
+
tabWidth: options?.tabWidth ?? context.meta?.printOptions?.tabWidth,
|
|
132
|
+
useTabs: options?.useTabs ?? context.meta?.printOptions?.useTabs,
|
|
135
133
|
});
|
|
136
134
|
} else {
|
|
137
135
|
visitChildren();
|