@suss/contract-storybook 0.39.0 → 0.40.1
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/README.md +3 -3
- package/dist/index.cjs +50 -126
- package/dist/index.js +53 -136
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ One `component`-kind summary per named story export:
|
|
|
21
21
|
- `identity.name` is `Component.Story`, with `exportPath` set to the story's export name, and a function-call boundary binding with `transport: "in-process"`, `recognition: "react"`, and the component identifier as the export name.
|
|
22
22
|
- One input per arg. The input's `role` is the arg name, and its shape is a `ref` whose name is the arg's source text, so a reader can see the value that was written.
|
|
23
23
|
- One default transition whose output is a render of the component. The reader does not evaluate the render, so the rendered tree is left unset.
|
|
24
|
-
- `metadata.component.storybook` with the story name, the component name, the component's module (`componentModule`, with `workspace`, `file` and `name`) and the specifier it is imported from (`componentImport`), the args map, `argReaders` when the story or its meta has `decorators` or a `render` function, `renderProps` with the props a render function passes the component as its own attributes or children, and `provenance: "independent"`. `renderProps` is left out when the render function renders the component through another element or spreads anything besides its args into it. A decorator or a render function receives the args before the component does, and the reader does not follow either, so the checker does not judge those args against the component. The provenance is what lets a story act as a check on an inferred component summary, since it was written separately from the component.
|
|
24
|
+
- `metadata.component.storybook` with the story name, the component name, the component's module (`componentModule`, with `workspace`, `file` and `name`) and the specifier it is imported from (`componentImport`), the args map, `argReaders` when the story or its meta has `decorators` or a `render` function, `renderProps` with the props a render function passes the component as its own attributes or children, and `provenance: "independent"`. `renderProps` is left out when the render function renders the component through another element or spreads anything besides its args into it. A spread counts as the args only when its name refers to the render function's first parameter, or to the rest of that parameter's destructure, so spreading a callback's own `args` inside the render function does not. A comment alone between the component's tags passes no `children`. A decorator or a render function receives the args before the component does, and the reader does not follow either, so the checker does not judge those args against the component. The provenance is what lets a story act as a check on an inferred component summary, since it was written separately from the component.
|
|
25
25
|
- Confidence is `derived` at `medium`. People write stories, and a story is authoritative about what it covers, but stories do not list everything a component does.
|
|
26
26
|
|
|
27
27
|
## What it does not read
|
|
@@ -30,7 +30,7 @@ One `component`-kind summary per named story export:
|
|
|
30
30
|
- **`argTypes`.** Control types and option lists per arg could support stricter type checking, but they are not read today.
|
|
31
31
|
- **What `decorators`, `render` and `parameters` do.** Their presence is recorded, as above. A render function is read only for the attributes and children it gives the component's element, and the other bodies are not read. Decorators set in `.storybook/preview` apply to every story and are not seen at all.
|
|
32
32
|
- **CSF1 and MDX stories.** CSF3 is the supported format.
|
|
33
|
-
- **A `component` that is
|
|
33
|
+
- **A `component` that is a member of an object the run cannot see written out**, such as an object a function builds or one a library's declaration file types. No module is recorded for it. A member of an object a module writes out, `Card.Root` with `export const Card = { Root: CardRoot }`, is followed to where `CardRoot` is declared, through type arguments such as `Slider.Root<number>` too, and a member of a namespace import, `Icons.Chip` with `import * as Icons from "./icons"`, is followed like a plain name.
|
|
34
34
|
- **Arg values as structured shapes.** An arg's value stays as source text inside a `ref` shape, and is not parsed into a `TypeShape`.
|
|
35
35
|
|
|
36
36
|
## Worked example
|
|
@@ -70,7 +70,7 @@ const summaries = generateSummariesFromStories(
|
|
|
70
70
|
|
|
71
71
|
## Where it fits in suss
|
|
72
72
|
|
|
73
|
-
The package depends on `@suss/behavioral-ir` for the IR types it produces, on `@suss/adapter-typescript` for
|
|
73
|
+
The package depends on `@suss/behavioral-ir` for the IR types it produces, on `@suss/adapter-typescript` for a story file's module ops over its facts, and on `@suss/recognize` for `discoverEntryObject`, which reads the meta and the stories through those ops, with `ts-morph` as a peer dependency. A render function's JSX and the component's declaration are read through the value ops too, so the reader builds the program for each tsconfig and reads no syntax itself. It is the only contract reader that parses TypeScript, because CSF is TypeScript. It still reads a declared artifact, and does not infer behavior from a component's implementation.
|
|
74
74
|
|
|
75
75
|
## More
|
|
76
76
|
|
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,13 @@ var import_ts_morph = require("ts-morph");
|
|
|
38
38
|
var import_adapter_typescript = require("@suss/adapter-typescript");
|
|
39
39
|
var import_behavioral_ir = require("@suss/behavioral-ir");
|
|
40
40
|
var import_files = require("@suss/behavioral-ir/files");
|
|
41
|
+
var import_recognize = require("@suss/recognize");
|
|
42
|
+
var STORIES = {
|
|
43
|
+
type: "entryObject",
|
|
44
|
+
entry: "default",
|
|
45
|
+
target: "component",
|
|
46
|
+
inputs: "args"
|
|
47
|
+
};
|
|
41
48
|
function generateSummariesFromStories(filePaths, options = {}) {
|
|
42
49
|
const componentModules = options.componentModules ?? true;
|
|
43
50
|
const byFile = /* @__PURE__ */ new Map();
|
|
@@ -51,15 +58,15 @@ function generateSummariesFromStories(filePaths, options = {}) {
|
|
|
51
58
|
storyFile,
|
|
52
59
|
options.projectRoot ?? (0, import_files.defaultProjectRoot)(storyFile)
|
|
53
60
|
);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (meta === null) {
|
|
61
|
+
const found = (0, import_recognize.discoverEntryObject)(STORIES, (0, import_adapter_typescript.moduleOpsFor)(sf, resolution));
|
|
62
|
+
if (found === null) {
|
|
57
63
|
continue;
|
|
58
64
|
}
|
|
65
|
+
const meta = metaOf(found, componentModules);
|
|
59
66
|
byFile.set(
|
|
60
67
|
sf.getFilePath(),
|
|
61
|
-
|
|
62
|
-
(
|
|
68
|
+
found.members.map(
|
|
69
|
+
(member) => buildSummary(storyOf(member, meta), meta, relPath)
|
|
63
70
|
)
|
|
64
71
|
);
|
|
65
72
|
}
|
|
@@ -113,147 +120,64 @@ function argReadersOf(storyOrMeta) {
|
|
|
113
120
|
return ARG_READERS.filter((name) => keys.has(name));
|
|
114
121
|
}
|
|
115
122
|
function renderPropsOf(storyOrMeta, componentName) {
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
if (render === null) {
|
|
123
|
+
const render = storyOrMeta.property("render")?.function?.() ?? null;
|
|
124
|
+
const elements = render?.elements?.(componentName) ?? [];
|
|
125
|
+
if (render === null || elements.length === 0) {
|
|
119
126
|
return null;
|
|
120
127
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
].filter((element) => element.getTagNameNode().getText() === componentName);
|
|
126
|
-
if (elements.length === 0) {
|
|
128
|
+
const spreadsOther = elements.some(
|
|
129
|
+
(element) => element.spreads().some((spread) => spread.parameterAt?.(render) !== 0)
|
|
130
|
+
);
|
|
131
|
+
if (spreadsOther) {
|
|
127
132
|
return null;
|
|
128
133
|
}
|
|
129
|
-
const passed =
|
|
130
|
-
if (elements.some(
|
|
134
|
+
const passed = new Set(elements.flatMap((element) => element.props()));
|
|
135
|
+
if (elements.some((element) => element.hasChildren())) {
|
|
131
136
|
passed.add("children");
|
|
132
137
|
}
|
|
133
|
-
for (const attribute of elements.flatMap((e) => e.getAttributes())) {
|
|
134
|
-
if (import_ts_morph.Node.isJsxAttribute(attribute)) {
|
|
135
|
-
passed.add(attribute.getNameNode().getText());
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
if (!argNames.has(attribute.getExpression().getText())) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
138
|
return [...passed].sort();
|
|
143
139
|
}
|
|
144
|
-
function
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const names = /* @__PURE__ */ new Set();
|
|
155
|
-
const nameNode = parameter?.getNameNode();
|
|
156
|
-
if (nameNode === void 0) {
|
|
157
|
-
return names;
|
|
158
|
-
}
|
|
159
|
-
if (import_ts_morph.Node.isIdentifier(nameNode)) {
|
|
160
|
-
names.add(nameNode.getText());
|
|
161
|
-
return names;
|
|
162
|
-
}
|
|
163
|
-
const elements = import_ts_morph.Node.isObjectBindingPattern(nameNode) ? nameNode.getDescendantsOfKind(import_ts_morph.SyntaxKind.BindingElement).filter((element) => element.getParent() === nameNode) : [];
|
|
164
|
-
for (const element of elements) {
|
|
165
|
-
if (element.getDotDotDotToken() !== void 0) {
|
|
166
|
-
names.add(element.getName());
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return names;
|
|
170
|
-
}
|
|
171
|
-
function extractMeta(exported, componentModules) {
|
|
172
|
-
for (const { value } of exported.get("default") ?? []) {
|
|
173
|
-
const meta = value.object?.() ?? null;
|
|
174
|
-
const component = meta?.property("component") ?? null;
|
|
175
|
-
if (meta === null || component === null) {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const componentName = textOf(component);
|
|
179
|
-
return {
|
|
180
|
-
componentName,
|
|
181
|
-
componentModule: componentModules ? declaredModuleOf(nodeBehind(component)) : void 0,
|
|
182
|
-
componentImport: component.importedFrom?.() ?? void 0,
|
|
183
|
-
args: argsOf(meta),
|
|
184
|
-
argReaders: argReadersOf(meta),
|
|
185
|
-
renderProps: renderPropsOf(meta, componentName)
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
140
|
+
function metaOf(found, componentModules) {
|
|
141
|
+
const { entry: meta, target: component } = found;
|
|
142
|
+
const componentName = textOf(component);
|
|
143
|
+
return {
|
|
144
|
+
componentName,
|
|
145
|
+
componentModule: componentModules ? declaredModuleOf(component, componentName) : void 0,
|
|
146
|
+
componentImport: component.importedFrom?.() ?? void 0,
|
|
147
|
+
argReaders: argReadersOf(meta),
|
|
148
|
+
renderProps: renderPropsOf(meta, componentName)
|
|
149
|
+
};
|
|
189
150
|
}
|
|
190
|
-
function declaredModuleOf(component) {
|
|
191
|
-
|
|
151
|
+
function declaredModuleOf(component, spelling) {
|
|
152
|
+
const declared = component.declaration?.() ?? null;
|
|
153
|
+
if (declared === null) {
|
|
192
154
|
return void 0;
|
|
193
155
|
}
|
|
194
|
-
const
|
|
195
|
-
if (declaration === void 0) {
|
|
196
|
-
return void 0;
|
|
197
|
-
}
|
|
198
|
-
const place = (0, import_adapter_typescript.projectPlaceOf)(declaration.getSourceFile().getFilePath());
|
|
156
|
+
const place = (0, import_adapter_typescript.projectPlaceOf)(declared.file);
|
|
199
157
|
return {
|
|
200
158
|
...place.workspace === null ? {} : { workspace: place.workspace },
|
|
201
159
|
file: place.file,
|
|
202
|
-
name:
|
|
160
|
+
name: declared.name ?? spelling
|
|
203
161
|
};
|
|
204
162
|
}
|
|
205
|
-
function componentDeclarationOf(component) {
|
|
206
|
-
return (0, import_adapter_typescript.declarationsBehind)((0, import_adapter_typescript.symbolBehind)(component)).find(
|
|
207
|
-
(declaration) => !isImportBinding(declaration)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
function isImportBinding(node) {
|
|
211
|
-
return import_ts_morph.Node.isImportSpecifier(node) || import_ts_morph.Node.isImportClause(node) || import_ts_morph.Node.isNamespaceImport(node) || import_ts_morph.Node.isImportEqualsDeclaration(node);
|
|
212
|
-
}
|
|
213
|
-
function declaredNameOf(declaration) {
|
|
214
|
-
if (import_ts_morph.Node.isVariableDeclaration(declaration) || import_ts_morph.Node.isFunctionDeclaration(declaration) || import_ts_morph.Node.isClassDeclaration(declaration)) {
|
|
215
|
-
return declaration.getName();
|
|
216
|
-
}
|
|
217
|
-
return void 0;
|
|
218
|
-
}
|
|
219
|
-
function nodeBehind(value) {
|
|
220
|
-
return value.ast();
|
|
221
|
-
}
|
|
222
163
|
function textOf(value) {
|
|
223
|
-
return value.source?.() ??
|
|
164
|
+
return value.source?.() ?? "";
|
|
224
165
|
}
|
|
225
|
-
function
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const ownReaders = argReadersOf(story);
|
|
237
|
-
results.push({
|
|
238
|
-
name,
|
|
239
|
-
args: { ...meta.args, ...argsOf(story) },
|
|
240
|
-
argReaders: ARG_READERS.filter(
|
|
241
|
-
(reader) => meta.argReaders.includes(reader) || ownReaders.includes(reader)
|
|
242
|
-
),
|
|
243
|
-
renderProps: ownReaders.includes("render") ? renderPropsOf(story, meta.componentName) : meta.renderProps,
|
|
244
|
-
line
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return results;
|
|
166
|
+
function storyOf(member, meta) {
|
|
167
|
+
const ownReaders = argReadersOf(member.value);
|
|
168
|
+
return {
|
|
169
|
+
name: member.name,
|
|
170
|
+
args: argsOf(member.inputs),
|
|
171
|
+
argReaders: ARG_READERS.filter(
|
|
172
|
+
(reader) => meta.argReaders.includes(reader) || ownReaders.includes(reader)
|
|
173
|
+
),
|
|
174
|
+
renderProps: ownReaders.includes("render") ? renderPropsOf(member.value, meta.componentName) : meta.renderProps,
|
|
175
|
+
line: member.line ?? 0
|
|
176
|
+
};
|
|
249
177
|
}
|
|
250
|
-
function argsOf(
|
|
178
|
+
function argsOf(inputs) {
|
|
251
179
|
const args = {};
|
|
252
|
-
const
|
|
253
|
-
for (const { key, value } of object?.entries("nothing") ?? []) {
|
|
254
|
-
if (key === null) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
180
|
+
for (const { key, value } of inputs) {
|
|
257
181
|
const settled = value.evaluated?.() ?? null;
|
|
258
182
|
args[key] = typeof settled === "string" ? settled : textOf(value);
|
|
259
183
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { Project } from "ts-morph";
|
|
3
4
|
import {
|
|
4
|
-
Node as N,
|
|
5
|
-
Project,
|
|
6
|
-
SyntaxKind
|
|
7
|
-
} from "ts-morph";
|
|
8
|
-
import {
|
|
9
|
-
declarationsBehind,
|
|
10
|
-
exportedValuesOf,
|
|
11
5
|
findNearestTsconfig,
|
|
6
|
+
moduleOpsFor,
|
|
12
7
|
projectPlaceOf,
|
|
13
|
-
ResolutionStore
|
|
14
|
-
symbolBehind,
|
|
15
|
-
toFunctionRoot
|
|
8
|
+
ResolutionStore
|
|
16
9
|
} from "@suss/adapter-typescript";
|
|
17
10
|
import { functionCallBinding } from "@suss/behavioral-ir";
|
|
18
11
|
import { defaultProjectRoot, pathInProject } from "@suss/behavioral-ir/files";
|
|
12
|
+
import { discoverEntryObject } from "@suss/recognize";
|
|
13
|
+
var STORIES = {
|
|
14
|
+
type: "entryObject",
|
|
15
|
+
entry: "default",
|
|
16
|
+
target: "component",
|
|
17
|
+
inputs: "args"
|
|
18
|
+
};
|
|
19
19
|
function generateSummariesFromStories(filePaths, options = {}) {
|
|
20
20
|
const componentModules = options.componentModules ?? true;
|
|
21
21
|
const byFile = /* @__PURE__ */ new Map();
|
|
@@ -29,15 +29,15 @@ function generateSummariesFromStories(filePaths, options = {}) {
|
|
|
29
29
|
storyFile,
|
|
30
30
|
options.projectRoot ?? defaultProjectRoot(storyFile)
|
|
31
31
|
);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (meta === null) {
|
|
32
|
+
const found = discoverEntryObject(STORIES, moduleOpsFor(sf, resolution));
|
|
33
|
+
if (found === null) {
|
|
35
34
|
continue;
|
|
36
35
|
}
|
|
36
|
+
const meta = metaOf(found, componentModules);
|
|
37
37
|
byFile.set(
|
|
38
38
|
sf.getFilePath(),
|
|
39
|
-
|
|
40
|
-
(
|
|
39
|
+
found.members.map(
|
|
40
|
+
(member) => buildSummary(storyOf(member, meta), meta, relPath)
|
|
41
41
|
)
|
|
42
42
|
);
|
|
43
43
|
}
|
|
@@ -91,147 +91,64 @@ function argReadersOf(storyOrMeta) {
|
|
|
91
91
|
return ARG_READERS.filter((name) => keys.has(name));
|
|
92
92
|
}
|
|
93
93
|
function renderPropsOf(storyOrMeta, componentName) {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
if (render === null) {
|
|
94
|
+
const render = storyOrMeta.property("render")?.function?.() ?? null;
|
|
95
|
+
const elements = render?.elements?.(componentName) ?? [];
|
|
96
|
+
if (render === null || elements.length === 0) {
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
].filter((element) => element.getTagNameNode().getText() === componentName);
|
|
104
|
-
if (elements.length === 0) {
|
|
99
|
+
const spreadsOther = elements.some(
|
|
100
|
+
(element) => element.spreads().some((spread) => spread.parameterAt?.(render) !== 0)
|
|
101
|
+
);
|
|
102
|
+
if (spreadsOther) {
|
|
105
103
|
return null;
|
|
106
104
|
}
|
|
107
|
-
const passed =
|
|
108
|
-
if (elements.some(
|
|
105
|
+
const passed = new Set(elements.flatMap((element) => element.props()));
|
|
106
|
+
if (elements.some((element) => element.hasChildren())) {
|
|
109
107
|
passed.add("children");
|
|
110
108
|
}
|
|
111
|
-
for (const attribute of elements.flatMap((e) => e.getAttributes())) {
|
|
112
|
-
if (N.isJsxAttribute(attribute)) {
|
|
113
|
-
passed.add(attribute.getNameNode().getText());
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (!argNames.has(attribute.getExpression().getText())) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
109
|
return [...passed].sort();
|
|
121
110
|
}
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const names = /* @__PURE__ */ new Set();
|
|
133
|
-
const nameNode = parameter?.getNameNode();
|
|
134
|
-
if (nameNode === void 0) {
|
|
135
|
-
return names;
|
|
136
|
-
}
|
|
137
|
-
if (N.isIdentifier(nameNode)) {
|
|
138
|
-
names.add(nameNode.getText());
|
|
139
|
-
return names;
|
|
140
|
-
}
|
|
141
|
-
const elements = N.isObjectBindingPattern(nameNode) ? nameNode.getDescendantsOfKind(SyntaxKind.BindingElement).filter((element) => element.getParent() === nameNode) : [];
|
|
142
|
-
for (const element of elements) {
|
|
143
|
-
if (element.getDotDotDotToken() !== void 0) {
|
|
144
|
-
names.add(element.getName());
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return names;
|
|
148
|
-
}
|
|
149
|
-
function extractMeta(exported, componentModules) {
|
|
150
|
-
for (const { value } of exported.get("default") ?? []) {
|
|
151
|
-
const meta = value.object?.() ?? null;
|
|
152
|
-
const component = meta?.property("component") ?? null;
|
|
153
|
-
if (meta === null || component === null) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
const componentName = textOf(component);
|
|
157
|
-
return {
|
|
158
|
-
componentName,
|
|
159
|
-
componentModule: componentModules ? declaredModuleOf(nodeBehind(component)) : void 0,
|
|
160
|
-
componentImport: component.importedFrom?.() ?? void 0,
|
|
161
|
-
args: argsOf(meta),
|
|
162
|
-
argReaders: argReadersOf(meta),
|
|
163
|
-
renderProps: renderPropsOf(meta, componentName)
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
111
|
+
function metaOf(found, componentModules) {
|
|
112
|
+
const { entry: meta, target: component } = found;
|
|
113
|
+
const componentName = textOf(component);
|
|
114
|
+
return {
|
|
115
|
+
componentName,
|
|
116
|
+
componentModule: componentModules ? declaredModuleOf(component, componentName) : void 0,
|
|
117
|
+
componentImport: component.importedFrom?.() ?? void 0,
|
|
118
|
+
argReaders: argReadersOf(meta),
|
|
119
|
+
renderProps: renderPropsOf(meta, componentName)
|
|
120
|
+
};
|
|
167
121
|
}
|
|
168
|
-
function declaredModuleOf(component) {
|
|
169
|
-
|
|
122
|
+
function declaredModuleOf(component, spelling) {
|
|
123
|
+
const declared = component.declaration?.() ?? null;
|
|
124
|
+
if (declared === null) {
|
|
170
125
|
return void 0;
|
|
171
126
|
}
|
|
172
|
-
const
|
|
173
|
-
if (declaration === void 0) {
|
|
174
|
-
return void 0;
|
|
175
|
-
}
|
|
176
|
-
const place = projectPlaceOf(declaration.getSourceFile().getFilePath());
|
|
127
|
+
const place = projectPlaceOf(declared.file);
|
|
177
128
|
return {
|
|
178
129
|
...place.workspace === null ? {} : { workspace: place.workspace },
|
|
179
130
|
file: place.file,
|
|
180
|
-
name:
|
|
131
|
+
name: declared.name ?? spelling
|
|
181
132
|
};
|
|
182
133
|
}
|
|
183
|
-
function componentDeclarationOf(component) {
|
|
184
|
-
return declarationsBehind(symbolBehind(component)).find(
|
|
185
|
-
(declaration) => !isImportBinding(declaration)
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
function isImportBinding(node) {
|
|
189
|
-
return N.isImportSpecifier(node) || N.isImportClause(node) || N.isNamespaceImport(node) || N.isImportEqualsDeclaration(node);
|
|
190
|
-
}
|
|
191
|
-
function declaredNameOf(declaration) {
|
|
192
|
-
if (N.isVariableDeclaration(declaration) || N.isFunctionDeclaration(declaration) || N.isClassDeclaration(declaration)) {
|
|
193
|
-
return declaration.getName();
|
|
194
|
-
}
|
|
195
|
-
return void 0;
|
|
196
|
-
}
|
|
197
|
-
function nodeBehind(value) {
|
|
198
|
-
return value.ast();
|
|
199
|
-
}
|
|
200
134
|
function textOf(value) {
|
|
201
|
-
return value.source?.() ??
|
|
135
|
+
return value.source?.() ?? "";
|
|
202
136
|
}
|
|
203
|
-
function
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const ownReaders = argReadersOf(story);
|
|
215
|
-
results.push({
|
|
216
|
-
name,
|
|
217
|
-
args: { ...meta.args, ...argsOf(story) },
|
|
218
|
-
argReaders: ARG_READERS.filter(
|
|
219
|
-
(reader) => meta.argReaders.includes(reader) || ownReaders.includes(reader)
|
|
220
|
-
),
|
|
221
|
-
renderProps: ownReaders.includes("render") ? renderPropsOf(story, meta.componentName) : meta.renderProps,
|
|
222
|
-
line
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return results;
|
|
137
|
+
function storyOf(member, meta) {
|
|
138
|
+
const ownReaders = argReadersOf(member.value);
|
|
139
|
+
return {
|
|
140
|
+
name: member.name,
|
|
141
|
+
args: argsOf(member.inputs),
|
|
142
|
+
argReaders: ARG_READERS.filter(
|
|
143
|
+
(reader) => meta.argReaders.includes(reader) || ownReaders.includes(reader)
|
|
144
|
+
),
|
|
145
|
+
renderProps: ownReaders.includes("render") ? renderPropsOf(member.value, meta.componentName) : meta.renderProps,
|
|
146
|
+
line: member.line ?? 0
|
|
147
|
+
};
|
|
227
148
|
}
|
|
228
|
-
function argsOf(
|
|
149
|
+
function argsOf(inputs) {
|
|
229
150
|
const args = {};
|
|
230
|
-
const
|
|
231
|
-
for (const { key, value } of object?.entries("nothing") ?? []) {
|
|
232
|
-
if (key === null) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
151
|
+
for (const { key, value } of inputs) {
|
|
235
152
|
const settled = value.evaluated?.() ?? null;
|
|
236
153
|
args[key] = typeof settled === "string" ? settled : textOf(value);
|
|
237
154
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suss/contract-storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Turn Storybook CSF stories into a suss contract and check the props they pass against the React components that receive them.",
|
|
6
6
|
"keywords": [
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"typecheck": "tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@suss/adapter-typescript": "0.
|
|
51
|
-
"@suss/behavioral-ir": "0.
|
|
52
|
-
"@suss/recognize": "0.
|
|
50
|
+
"@suss/adapter-typescript": "0.40.1",
|
|
51
|
+
"@suss/behavioral-ir": "0.40.1",
|
|
52
|
+
"@suss/recognize": "0.40.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"tsup": "*",
|