@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6
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 +1 -1
- package/api/discover/_adapter.d.mts +7 -5
- package/api/discover/_adapter.mjs +12 -11
- package/api/doctor/_adapter.d.mts +11 -62
- package/api/doctor/_adapter.mjs +242 -472
- package/api/doctor/doctor.d.mts +1 -1
- package/api/doctor/doctor.mjs +1 -1
- package/api/doctor/theme-checks.mjs +37 -45
- package/api/error.d.mts +21 -0
- package/api/error.mjs +89 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/icon.doc.mjs +1 -1
- package/api/icon/icon.type.mjs +1 -1
- package/api/icon/search/search.d.mts +4 -1
- package/api/icon/search/search.mjs +41 -4
- package/api/render/_adapter.mjs +233 -40
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +2 -2
- package/api/search/_candidate-score.mjs +32 -8
- package/api/search/_cards.json +1 -1
- package/api/search/_compound.d.mts +0 -1
- package/api/search/_compound.mjs +93 -2
- package/api/search/_lexical.mjs +177 -17
- package/api/search/_order.d.mts +3 -1
- package/api/search/_order.mjs +16 -5
- package/api/search/_result.d.mts +9 -0
- package/api/search/_result.mjs +10 -0
- package/api/search/_score.mjs +21 -3
- package/api/swizzle/_moduleGraph.d.mts +8 -0
- package/api/swizzle/_moduleGraph.mjs +61 -3
- package/api/template/copy/copy.mjs +5 -3
- package/api/theme/_adapter.mjs +48 -12
- package/api/theme/build/build.d.mts +4 -0
- package/api/theme/build/build.mjs +69 -18
- package/api/theme/build/style-keys.mjs +4 -5
- package/api/theme/build/theme-object.mjs +5 -0
- package/api/theme/palette/generate/color.d.mts +47 -0
- package/api/theme/palette/generate/color.mjs +58 -1
- package/api/theme/palette/generate/derive-look.d.mts +293 -0
- package/api/theme/palette/generate/derive-look.mjs +1362 -0
- package/api/theme/palette/generate/editor-look.d.mts +62 -0
- package/api/theme/palette/generate/editor-look.mjs +550 -0
- package/api/theme/palette/generate/mapping.d.mts +94 -9
- package/api/theme/palette/generate/mapping.mjs +94 -22
- package/api/theme-edit/_adapter.mjs +10 -1
- package/api/theme-edit/_catalog.d.mts +13 -13
- package/api/theme-edit/_catalog.mjs +38 -16
- package/api/theme-edit/_check.d.mts +82 -6
- package/api/theme-edit/_check.mjs +1230 -223
- package/api/theme-edit/_color.d.mts +74 -0
- package/api/theme-edit/_color.mjs +168 -3
- package/api/theme-edit/_compiler.d.mts +3 -5
- package/api/theme-edit/_compiler.mjs +122 -23
- package/api/theme-edit/_context.d.mts +46 -5
- package/api/theme-edit/_context.mjs +97 -49
- package/api/theme-edit/_css.d.mts +11 -0
- package/api/theme-edit/_css.mjs +40 -0
- package/api/theme-edit/_edit.d.mts +13 -0
- package/api/theme-edit/_edit.mjs +1450 -128
- package/api/theme-edit/_how-commands.d.mts +12 -0
- package/api/theme-edit/_how-commands.mjs +96 -14
- package/api/theme-edit/_how-question.d.mts +73 -29
- package/api/theme-edit/_how-question.mjs +8131 -1209
- package/api/theme-edit/_how-sides.d.mts +22 -0
- package/api/theme-edit/_how-sides.mjs +173 -0
- package/api/theme-edit/_how-steps.d.mts +42 -0
- package/api/theme-edit/_how-steps.mjs +208 -0
- package/api/theme-edit/_how-values.d.mts +29 -0
- package/api/theme-edit/_how-values.mjs +111 -0
- package/api/theme-edit/_how-words.d.mts +15 -0
- package/api/theme-edit/_how-words.mjs +239 -0
- package/api/theme-edit/_how.d.mts +1 -1
- package/api/theme-edit/_how.mjs +412 -37
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +125 -13
- package/api/theme-edit/_normal.d.mts +5 -3
- package/api/theme-edit/_normal.mjs +54 -14
- package/api/theme-edit/_palette.d.mts +204 -4
- package/api/theme-edit/_palette.mjs +901 -25
- package/api/theme-edit/_part-pieces.d.mts +54 -0
- package/api/theme-edit/_part-pieces.mjs +179 -0
- package/api/theme-edit/_part-words.mjs +33 -5
- package/api/theme-edit/_parts.d.mts +133 -0
- package/api/theme-edit/_parts.mjs +599 -10
- package/api/theme-edit/_picture-traits.d.mts +259 -0
- package/api/theme-edit/_picture-traits.mjs +1030 -0
- package/api/theme-edit/_preview.d.mts +84 -4
- package/api/theme-edit/_preview.mjs +260 -24
- package/api/theme-edit/_project.d.mts +14 -4
- package/api/theme-edit/_project.mjs +95 -26
- package/api/theme-edit/_set-line.d.mts +29 -0
- package/api/theme-edit/_set-line.mjs +100 -0
- package/api/theme-edit/_settings.d.mts +625 -28
- package/api/theme-edit/_settings.mjs +4587 -880
- package/api/theme-edit/_tables.d.mts +25 -1
- package/api/theme-edit/_tables.mjs +115 -11
- package/api/theme-edit/_text-looks.d.mts +78 -0
- package/api/theme-edit/_text-looks.mjs +376 -0
- package/api/theme-edit/_vet.d.mts +3 -26
- package/api/theme-edit/_vet.mjs +5 -89
- package/api/theme-edit/how/how.d.mts +1 -1
- package/api/theme-edit/how/how.mjs +1 -1
- package/api/theme-edit/theme-edit.type.d.mts +54 -1
- package/api/theme-edit/theme-edit.type.mjs +17 -2
- package/api/theme-edit/themeEditHow.doc.mjs +3 -3
- package/api/theme-edit/themeEditNew.doc.mjs +4 -0
- package/api/theme-edit/themeEditSet.doc.mjs +6 -2
- package/api/theme-edit/themeEditShow.doc.mjs +4 -0
- package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/tree/export-pages.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +89 -17
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/article.doc.mjs +9 -0
- package/assets/icons/template-icons.json +5 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ide/page.tsx +5 -10
- package/assets/templates/pages/payment-form/page.tsx +16 -60
- package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/doctypes/_schema.d.mts +13 -13
- package/authoring/gap-report/parse.d.mts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/ensure-core-built.mjs +17 -10
- package/clients/cli/commands/experimental/theme.mjs +46 -6
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/hook.mjs +7 -0
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/index.mjs +6 -2
- package/clients/cli/lib/hook-format.mjs +41 -1
- package/clients/cli/lib/json-shim.mjs +34 -14
- package/clients/cli/lib/other-cli-words.mjs +7 -0
- package/clients/cli/lib/unknown-command.mjs +345 -46
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +11 -2
- package/foundation/agent-docs/agent-docs.mjs +51 -8
- package/foundation/config/project.d.mts +11 -1
- package/foundation/config/project.mjs +11 -2
- package/foundation/discovery/component-replacement.d.mts +5 -8
- package/foundation/discovery/component-replacement.mjs +12 -14
- package/foundation/discovery/core-augmentation-points.d.mts +35 -0
- package/foundation/discovery/core-augmentation-points.mjs +410 -9
- package/foundation/discovery/core-elements.d.mts +6 -0
- package/foundation/discovery/core-elements.mjs +10 -2
- package/foundation/discovery/core-prop-types.d.mts +5 -0
- package/foundation/discovery/core-prop-types.mjs +10 -3
- package/foundation/discovery/core-props.d.mts +8 -0
- package/foundation/discovery/core-props.mjs +29 -13
- package/foundation/discovery/official-list.d.mts +17 -0
- package/foundation/discovery/official-list.mjs +77 -0
- package/foundation/discovery/unknown-core-props.d.mts +130 -0
- package/foundation/discovery/unknown-core-props.mjs +601 -0
- package/foundation/discovery/written-prop-values.d.mts +35 -0
- package/foundation/discovery/written-prop-values.mjs +258 -0
- package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
- package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
- package/foundation/fs/package-name.d.mts +10 -0
- package/foundation/fs/package-name.mjs +37 -0
- package/foundation/fs/project-source-files.d.mts +27 -0
- package/foundation/fs/project-source-files.mjs +115 -0
- package/foundation/fs/project-sources.d.mts +25 -0
- package/foundation/fs/project-sources.mjs +83 -0
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +36 -2
- package/foundation/integrations/integration-warnings.d.mts +39 -7
- package/foundation/integrations/integration-warnings.mjs +141 -19
- package/foundation/integrations/missing-dependency.d.mts +11 -0
- package/foundation/integrations/missing-dependency.mjs +20 -5
- package/foundation/release/folder-lock.d.mts +5 -2
- package/foundation/release/folder-lock.mjs +9 -3
- package/foundation/release/notices.mjs +2 -8
- package/foundation/render/cut-short.d.mts +8 -2
- package/foundation/render/cut-short.mjs +50 -5
- package/foundation/render/drawn-contrast.d.mts +38 -0
- package/foundation/render/drawn-contrast.mjs +237 -0
- package/foundation/render/file-header.mjs +4 -0
- package/foundation/render/layers.d.mts +2 -1
- package/foundation/render/layers.mjs +22 -1
- package/foundation/render/page-worker.mjs +83 -18
- package/foundation/render/part-boxes.d.mts +27 -0
- package/foundation/render/part-boxes.mjs +45 -0
- package/foundation/render/picture-chrome.mjs +36 -4
- package/foundation/render/picture-playwright.mjs +26 -2
- package/foundation/render/picture-window.d.mts +29 -2
- package/foundation/render/picture-window.mjs +99 -1
- package/foundation/render/render-page.d.mts +39 -6
- package/foundation/render/render-page.mjs +26 -10
- package/foundation/render/ts-paths.mjs +2 -1
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/written-string.d.mts +4 -1
- package/foundation/text/written-string.mjs +4 -1
- package/package.json +8 -7
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The props pages give Core components that the component does not
|
|
5
|
+
* take.
|
|
6
|
+
* @input The props pages give Core components (core-props.mjs), a reader of
|
|
7
|
+
* each component's documented props, and the project's TypeScript.
|
|
8
|
+
* @output Each prop the component does not take, with a documented prop that
|
|
9
|
+
* has the same words; or why the props were not checked.
|
|
10
|
+
* @position Shared by `astryx doctor` (api/doctor/_adapter.mjs), which reads
|
|
11
|
+
* every page of the project, and `astryx experimental export`
|
|
12
|
+
* (api/render/_adapter.mjs), which reads the page it exports.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
export {OTHER_JSX_RUNTIME} from './core-elements.mjs';
|
|
18
|
+
import {projectAugmentations} from './core-augmentation-points.mjs';
|
|
19
|
+
import {
|
|
20
|
+
findInstalledPackage,
|
|
21
|
+
findPackageRoot,
|
|
22
|
+
findWorkspaceRoot,
|
|
23
|
+
} from '../fs/paths.mjs';
|
|
24
|
+
import {
|
|
25
|
+
listProjectSourceFiles,
|
|
26
|
+
SOURCE_FILE_LIMIT,
|
|
27
|
+
} from '../fs/project-source-files.mjs';
|
|
28
|
+
import {compilerOptionsFor, projectMapsImport} from '../render/ts-paths.mjs';
|
|
29
|
+
import {nameWords, orderByAffinity} from '../text/suggest-order.mjs';
|
|
30
|
+
import {compareText} from '../text/compare-text.mjs';
|
|
31
|
+
import {
|
|
32
|
+
resolveProjectTypeScript,
|
|
33
|
+
TYPESCRIPT_FIX,
|
|
34
|
+
unusableTypeScriptReason,
|
|
35
|
+
} from './project-typescript.mjs';
|
|
36
|
+
|
|
37
|
+
/** What to do when Core's types cannot be read without Core installed. */
|
|
38
|
+
const CORE_FIX =
|
|
39
|
+
'Install `@astryxdesign/core` in the project that holds the pages.';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The project's own TypeScript, found from the first of `dirs` that has one,
|
|
43
|
+
* or why the props cannot be checked without it and what to install. Doctor
|
|
44
|
+
* and the export say the same thing.
|
|
45
|
+
* @param {string[]} dirs
|
|
46
|
+
* @returns {{ts: any} | {skipped: string, reason: string}} `reason` is the
|
|
47
|
+
* same reason worded for a folder outside a project, with no install step
|
|
48
|
+
*/
|
|
49
|
+
export function projectTypeScript(dirs) {
|
|
50
|
+
const compiler = resolveProjectTypeScript(dirs);
|
|
51
|
+
if (compiler === null) {
|
|
52
|
+
return {
|
|
53
|
+
skipped: `TypeScript is not installed in this project, so the props were not checked. ${TYPESCRIPT_FIX}`,
|
|
54
|
+
reason:
|
|
55
|
+
'TypeScript is not installed here, so the props were not checked.',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (compiler.ts === null)
|
|
59
|
+
return {
|
|
60
|
+
skipped: unusableTypeScriptReason(
|
|
61
|
+
compiler.version,
|
|
62
|
+
'the props were not checked',
|
|
63
|
+
),
|
|
64
|
+
reason: unusableTypeScriptReason(
|
|
65
|
+
compiler.version,
|
|
66
|
+
'the props were not checked',
|
|
67
|
+
{here: true},
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
return {ts: compiler.ts};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A TypeScript module that may widen what JSX gives every component: one
|
|
75
|
+
* that augments React or the global scope (where `JSX` lives), or that loads
|
|
76
|
+
* a library's `css` prop types.
|
|
77
|
+
*/
|
|
78
|
+
const JSX_DECLARATION =
|
|
79
|
+
/\bdeclare\s+(?:module\s+['"]react(?:\/jsx-runtime)?['"]|global\b)|\bnamespace\s+JSX\b|styled-components\/cssprop|@emotion\/react\/types\/css-prop/;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The JSX runtime other than React's that compiler options name: a
|
|
83
|
+
* `jsxImportSource` other than `react`, or a `jsxFactory` other than
|
|
84
|
+
* `React.createElement`. Null for React's.
|
|
85
|
+
* @param {Record<string, unknown>} options
|
|
86
|
+
* @returns {string | null}
|
|
87
|
+
*/
|
|
88
|
+
function otherJsxRuntime(options) {
|
|
89
|
+
const {jsxImportSource: source, jsxFactory: factory} = options;
|
|
90
|
+
if (typeof source === 'string' && source !== 'react') return source;
|
|
91
|
+
if (typeof factory === 'string' && factory !== 'React.createElement')
|
|
92
|
+
return factory;
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A build config, by file name, that can set how JSX compiles: Babel, SWC,
|
|
98
|
+
* Vite, Vitest, esbuild, webpack, Rspack, Rsbuild, Next.js or tsup.
|
|
99
|
+
*/
|
|
100
|
+
const BUILD_CONFIG =
|
|
101
|
+
/^(?:\.babelrc(?:\.[cm]?js|\.json)?|babel\.config\.(?:[cm]?[jt]s|json)|\.swcrc|(?:vite|vitest|webpack|rspack|rsbuild|next|esbuild|tsup)\.config\.[cm]?[jt]s)$/;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A build setting that compiles JSX other than as React does: a runtime
|
|
105
|
+
* (`jsxImportSource`, `importSource`) other than `react`; a classic factory
|
|
106
|
+
* (`jsxFactory`, `pragma`, a name such as `jsx` or `h`) other than
|
|
107
|
+
* `React.createElement`; or Next.js's `styledComponents` compiler option,
|
|
108
|
+
* which compiles a `css` prop, when it is not `false`.
|
|
109
|
+
*/
|
|
110
|
+
const BUILD_JSX_RUNTIME =
|
|
111
|
+
/\b(?:jsxImportSource|importSource)['"]?\s*[:=]\s*['"](?!react['"])[^'"\s]+['"]|\b(?:jsxFactory|pragma)['"]?\s*[:=]\s*['"](?!React\.createElement['"])[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*['"]|\bstyledComponents['"]?\s*:(?!\s*false\b)/;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The packages that compile a `css` prop at build time, whatever name the
|
|
115
|
+
* build config gives them (Babel reads `styled-components` as
|
|
116
|
+
* `babel-plugin-styled-components`): a config can use one only when the
|
|
117
|
+
* project depends on it, or when it is installed through another package
|
|
118
|
+
* (`gatsby-plugin-emotion` brings emotion's preset).
|
|
119
|
+
*/
|
|
120
|
+
const CSS_PROP_TRANSFORMS = new Set([
|
|
121
|
+
'@emotion/babel-preset-css-prop',
|
|
122
|
+
'gatsby-plugin-emotion',
|
|
123
|
+
'babel-plugin-styled-components',
|
|
124
|
+
'@swc/plugin-styled-components',
|
|
125
|
+
'@compiled/babel-plugin',
|
|
126
|
+
'@compiled/webpack-loader',
|
|
127
|
+
'@compiled/vite-plugin',
|
|
128
|
+
'@compiled/parcel-config',
|
|
129
|
+
'@compiled/parcel-transformer',
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* What compiles the JSX of a page other than as React does, in the folder of
|
|
134
|
+
* the page or a folder above it, up to the project's workspace root (as
|
|
135
|
+
* `findWorkspaceRoot` reads it): a build config
|
|
136
|
+
* that sets another runtime or factory (a config file, or the `babel` key of
|
|
137
|
+
* a `package.json`), a `package.json` that depends on a transform that
|
|
138
|
+
* compiles a `css` prop, or such a transform installed where the project
|
|
139
|
+
* finds packages. Null when nothing does.
|
|
140
|
+
* @param {string[]} pages
|
|
141
|
+
* @param {string} projectDir
|
|
142
|
+
* @returns {{file: string, transform: string | null, installed?: boolean} | null}
|
|
143
|
+
* the config, and the transform it depends on or has installed
|
|
144
|
+
*/
|
|
145
|
+
function buildJsxRuntime(pages, projectDir) {
|
|
146
|
+
const top = findWorkspaceRoot(projectDir);
|
|
147
|
+
/** @type {Map<string, {file: string, transform: string | null, installed?: boolean} | null>} */
|
|
148
|
+
const configIn = new Map();
|
|
149
|
+
const read = (/** @type {string} */ dir) => {
|
|
150
|
+
/** @type {string[]} */
|
|
151
|
+
let names;
|
|
152
|
+
try {
|
|
153
|
+
names = fs.readdirSync(dir).sort();
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
for (const name of names) {
|
|
158
|
+
const file = path.join(dir, name);
|
|
159
|
+
/** @type {string | null} */
|
|
160
|
+
let text = null;
|
|
161
|
+
try {
|
|
162
|
+
if (BUILD_CONFIG.test(name)) text = fs.readFileSync(file, 'utf-8');
|
|
163
|
+
else if (name === 'package.json') {
|
|
164
|
+
const manifest = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
165
|
+
for (const field of [
|
|
166
|
+
'dependencies',
|
|
167
|
+
'devDependencies',
|
|
168
|
+
'peerDependencies',
|
|
169
|
+
'optionalDependencies',
|
|
170
|
+
]) {
|
|
171
|
+
const transform = Object.keys(manifest?.[field] ?? {}).find(
|
|
172
|
+
dependency => CSS_PROP_TRANSFORMS.has(dependency),
|
|
173
|
+
);
|
|
174
|
+
if (transform) return {file, transform};
|
|
175
|
+
}
|
|
176
|
+
text =
|
|
177
|
+
manifest?.babel == null ? null : JSON.stringify(manifest.babel);
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (text != null && BUILD_JSX_RUNTIME.test(text))
|
|
183
|
+
return {file, transform: null};
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
};
|
|
187
|
+
for (const page of pages) {
|
|
188
|
+
for (let dir = path.dirname(page); ; dir = path.dirname(dir)) {
|
|
189
|
+
if (!configIn.has(dir)) configIn.set(dir, read(dir));
|
|
190
|
+
const found = configIn.get(dir);
|
|
191
|
+
if (found) return found;
|
|
192
|
+
if (
|
|
193
|
+
dir === top ||
|
|
194
|
+
path.relative(top, dir).startsWith('..') ||
|
|
195
|
+
dir === path.dirname(dir)
|
|
196
|
+
)
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// A transform installed where a page finds packages: the project's own
|
|
201
|
+
// folders, or a workspace member's.
|
|
202
|
+
const pageDirs = [
|
|
203
|
+
...new Set([projectDir, ...pages.map(page => path.dirname(page))]),
|
|
204
|
+
];
|
|
205
|
+
for (const transform of [...CSS_PROP_TRANSFORMS].sort()) {
|
|
206
|
+
for (const dir of pageDirs) {
|
|
207
|
+
const installed = findInstalledPackage(dir, transform, Infinity);
|
|
208
|
+
if (installed) return {file: installed, transform, installed: true};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The configs TypeScript reads for the pages; pages that share a config
|
|
216
|
+
* share one read.
|
|
217
|
+
* @param {string[]} pages
|
|
218
|
+
*/
|
|
219
|
+
function readConfigs(pages) {
|
|
220
|
+
/** @type {Map<string, {file: string, options: Record<string, unknown>}>} */
|
|
221
|
+
const configs = new Map();
|
|
222
|
+
/** @type {Map<string, string>} */
|
|
223
|
+
const configOf = new Map();
|
|
224
|
+
for (const file of pages) {
|
|
225
|
+
const config = compilerOptionsFor(file) ?? {file: '', options: {}};
|
|
226
|
+
configs.set(config.file, config);
|
|
227
|
+
configOf.set(file, config.file);
|
|
228
|
+
}
|
|
229
|
+
return {configs, configOf};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The configs TypeScript reads for the pages, or why their props are not
|
|
234
|
+
* judged: a config or build that compiles JSX with another runtime, or a
|
|
235
|
+
* `css` prop, can give every component props of its own.
|
|
236
|
+
* @param {string[]} pages every page that imports Core
|
|
237
|
+
* @param {string} projectDir
|
|
238
|
+
* @returns {ReturnType<typeof readConfigs> | {skipped: string}}
|
|
239
|
+
*/
|
|
240
|
+
function jsxRuntimeCheck(pages, projectDir) {
|
|
241
|
+
const read = readConfigs(pages);
|
|
242
|
+
for (const {options} of read.configs.values()) {
|
|
243
|
+
const runtime = otherJsxRuntime(options);
|
|
244
|
+
if (runtime)
|
|
245
|
+
return {
|
|
246
|
+
skipped: `the project compiles JSX with \`${runtime}\`, which can give every component props of its own`,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const build = buildJsxRuntime(pages, projectDir);
|
|
250
|
+
if (build?.transform) {
|
|
251
|
+
return {
|
|
252
|
+
skipped: `${build.installed ? `\`${build.transform}\` is installed` : `the project depends on \`${build.transform}\``}, which compiles a \`css\` prop that every component can take`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (build) {
|
|
256
|
+
const shown = path
|
|
257
|
+
.relative(projectDir, build.file)
|
|
258
|
+
.split(path.sep)
|
|
259
|
+
.join('/');
|
|
260
|
+
return {
|
|
261
|
+
skipped: `the build config \`${shown}\` sets another JSX runtime or compiles a \`css\` prop, which can give every component props of its own`,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return read;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* For each component that Core's docs describe, its documented props as
|
|
269
|
+
* `astryx component <Name> --props` prints them, read in batches from the
|
|
270
|
+
* Core of the folder `cwd`. Doctor and the export read the docs through this
|
|
271
|
+
* one reader.
|
|
272
|
+
* @param {(names: string[], options: {cwd: string, package: string, props: boolean}) => Promise<unknown>} answer
|
|
273
|
+
* the component read (`component` of api/component), which this layer
|
|
274
|
+
* cannot import
|
|
275
|
+
* @param {string[]} names
|
|
276
|
+
* @param {string} cwd
|
|
277
|
+
* @param {number} batchLimit the most components one read takes
|
|
278
|
+
* @returns {Promise<Map<string, any[]>>}
|
|
279
|
+
*/
|
|
280
|
+
export async function readCoreDocs(answer, names, cwd, batchLimit) {
|
|
281
|
+
/** @type {Map<string, any[]>} */
|
|
282
|
+
const documented = new Map();
|
|
283
|
+
for (let start = 0; start < names.length; start += batchLimit) {
|
|
284
|
+
const batch = names.slice(start, start + batchLimit);
|
|
285
|
+
const read = /** @type {any} */ (
|
|
286
|
+
await answer(batch, {cwd, package: '@astryxdesign/core', props: true})
|
|
287
|
+
);
|
|
288
|
+
for (const each of read?.data?.results ?? []) {
|
|
289
|
+
const props = each?.status === 'found' ? each.result?.data : null;
|
|
290
|
+
if (Array.isArray(props)) documented.set(each.selector, props);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return documented;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The names of a component's documented props, as `readCoreDocs` gives them.
|
|
298
|
+
* @param {any[]} props
|
|
299
|
+
* @returns {string[]}
|
|
300
|
+
*/
|
|
301
|
+
export function propNamesOf(props) {
|
|
302
|
+
return props.map(prop => prop?.name).filter(Boolean);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @typedef {import('./core-props.mjs').CorePropUse & {file: string, path: string}} PageCorePropUse
|
|
307
|
+
* a prop a page gives a Core component, with the page as the caller shows
|
|
308
|
+
* it (`file`) and its absolute path
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @typedef {object} UnknownCoreProp
|
|
313
|
+
* @property {string} file as the caller shows it
|
|
314
|
+
* @property {number} line
|
|
315
|
+
* @property {number} column
|
|
316
|
+
* @property {string} component
|
|
317
|
+
* @property {string} prop
|
|
318
|
+
* @property {string | null} suggestion a documented prop with the same
|
|
319
|
+
* words, when there is one
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The files of a project that may widen what JSX gives every component (see
|
|
324
|
+
* `JSX_DECLARATION`); null when the project has more source files than the
|
|
325
|
+
* walk reads, since a declaration beyond them could add a prop to every
|
|
326
|
+
* component.
|
|
327
|
+
* @param {string} projectDir
|
|
328
|
+
* @returns {string[] | null}
|
|
329
|
+
*/
|
|
330
|
+
function jsxDeclarationFiles(projectDir) {
|
|
331
|
+
const files = listProjectSourceFiles(projectDir, '');
|
|
332
|
+
if (files.length >= SOURCE_FILE_LIMIT) return null;
|
|
333
|
+
return files.filter(file => {
|
|
334
|
+
try {
|
|
335
|
+
return widensJsx(file, fs.readFileSync(file, 'utf-8'));
|
|
336
|
+
} catch {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Whether a TypeScript module may widen what JSX gives every component (see
|
|
344
|
+
* `JSX_DECLARATION`). Doctor, which reads each file once, asks it of every
|
|
345
|
+
* file it reads.
|
|
346
|
+
* @param {string} file
|
|
347
|
+
* @param {string} text
|
|
348
|
+
*/
|
|
349
|
+
export function widensJsx(file, text) {
|
|
350
|
+
return /\.[cm]?tsx?$/.test(file) && JSX_DECLARATION.test(text);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* The props pages give Core components that the component does not take. A
|
|
355
|
+
* prop is a candidate when Core's docs for the component (the props
|
|
356
|
+
* `astryx component <Name> --package @astryxdesign/core` lists) leave it out,
|
|
357
|
+
* and it is reported only when TypeScript, reading Core's own published types
|
|
358
|
+
* as the pages see them, says the component's props do not take it either;
|
|
359
|
+
* the project's own modules that widen React's JSX are read with Core's
|
|
360
|
+
* types. A prop name React's types give an HTML or SVG element is never
|
|
361
|
+
* reported, since a component may pass it on to the element it renders, and
|
|
362
|
+
* neither is a prop JSX gives every component. A component with no docs, one
|
|
363
|
+
* TypeScript cannot read, a generic one, and a page whose config or build
|
|
364
|
+
* compiles JSX with another runtime or a `css` prop are not judged. Each page
|
|
365
|
+
* is judged with the config TypeScript reads for it. Only the docs are read
|
|
366
|
+
* while every prop is documented: TypeScript, configs and the project's
|
|
367
|
+
* files are read for candidates alone. `skipped` says why the candidates
|
|
368
|
+
* were not judged.
|
|
369
|
+
* @param {object} input
|
|
370
|
+
* @param {string} input.projectDir the folder of the pages' project
|
|
371
|
+
* @param {PageCorePropUse[]} input.uses
|
|
372
|
+
* @param {string[]} input.pages every page that imports Core, the pages of
|
|
373
|
+
* `uses` among them
|
|
374
|
+
* @param {(names: string[], cwd: string) => Promise<Map<string, any[]>>} input.readDocs
|
|
375
|
+
* for each component the docs describe, its documented props (`readCoreDocs`),
|
|
376
|
+
* read from the Core of the folder `cwd`
|
|
377
|
+
* @param {() => {ts: any} | {skipped: string, reason?: string}} input.typescript
|
|
378
|
+
* the compiler to read Core's types with, or why there is none (`reason`
|
|
379
|
+
* worded for a folder outside a project)
|
|
380
|
+
* @param {() => string[] | null} [input.jsxDeclarations] the files that may
|
|
381
|
+
* widen what JSX gives every component (`jsxDeclarationFiles` by default)
|
|
382
|
+
* @param {boolean} [input.runtimeFirst] doctor's order: report pages that
|
|
383
|
+
* find no installed Core, and a project on another JSX runtime
|
|
384
|
+
* (`jsxRuntimeCheck`), before the docs, whatever the props are. By default
|
|
385
|
+
* both are reported for candidates alone, and a page that finds no
|
|
386
|
+
* installed Core still reads the docs of the Core it renders with
|
|
387
|
+
* @returns {Promise<{found: UnknownCoreProp[], skipped: string | null, reason?: string}>}
|
|
388
|
+
* `skipped` ends with what to install when an install fixes it; `reason`,
|
|
389
|
+
* when given, is the same reason without that step, for a folder outside
|
|
390
|
+
* a project, where a project install step does not apply
|
|
391
|
+
*/
|
|
392
|
+
export async function judgeCoreProps({
|
|
393
|
+
projectDir,
|
|
394
|
+
uses,
|
|
395
|
+
pages,
|
|
396
|
+
readDocs,
|
|
397
|
+
typescript,
|
|
398
|
+
jsxDeclarations,
|
|
399
|
+
runtimeFirst = false,
|
|
400
|
+
}) {
|
|
401
|
+
const notChecked = (/** @type {string} */ reason, fix = '') => ({
|
|
402
|
+
found: [],
|
|
403
|
+
skipped: `${reason}, so the props were not checked.${fix ? ` ${fix}` : ''}`,
|
|
404
|
+
reason: `${reason}, so the props were not checked.`,
|
|
405
|
+
});
|
|
406
|
+
// Each page is read as TypeScript reads it, with Core and React found from
|
|
407
|
+
// the page's own folder.
|
|
408
|
+
/** @type {Map<string, string | null>} */
|
|
409
|
+
const coreFrom = new Map();
|
|
410
|
+
const coreDirFrom = (/** @type {string} */ dir) => {
|
|
411
|
+
if (!coreFrom.has(dir)) {
|
|
412
|
+
const found = findInstalledPackage(dir, '@astryxdesign/core', Infinity);
|
|
413
|
+
let real = found;
|
|
414
|
+
try {
|
|
415
|
+
real = found ? fs.realpathSync(found) : null;
|
|
416
|
+
} catch {
|
|
417
|
+
// A Core folder that does not resolve is read where it is found.
|
|
418
|
+
}
|
|
419
|
+
coreFrom.set(dir, real);
|
|
420
|
+
}
|
|
421
|
+
return coreFrom.get(dir) ?? null;
|
|
422
|
+
};
|
|
423
|
+
// Pages that import Core and find no installed Core have no types to
|
|
424
|
+
// read. Doctor says so whatever the pages hold; the export says so only
|
|
425
|
+
// for props the docs leave out.
|
|
426
|
+
const noCore = () =>
|
|
427
|
+
notChecked(
|
|
428
|
+
'Core is not installed where the pages that import it can find it',
|
|
429
|
+
CORE_FIX,
|
|
430
|
+
);
|
|
431
|
+
if (
|
|
432
|
+
runtimeFirst &&
|
|
433
|
+
pages.length > 0 &&
|
|
434
|
+
pages.every(page => !coreDirFrom(path.dirname(page)))
|
|
435
|
+
) {
|
|
436
|
+
return noCore();
|
|
437
|
+
}
|
|
438
|
+
const early = runtimeFirst ? jsxRuntimeCheck(pages, projectDir) : null;
|
|
439
|
+
if (early && 'skipped' in early) return notChecked(early.skipped);
|
|
440
|
+
// Batched reads of the props the docs of each Core list, as
|
|
441
|
+
// `astryx component <Name> --props` prints them; a component they do not
|
|
442
|
+
// describe is not judged.
|
|
443
|
+
/** @type {Map<string, {from: string, uses: PageCorePropUse[]}>} */
|
|
444
|
+
const byCore = new Map();
|
|
445
|
+
for (const use of uses) {
|
|
446
|
+
const from = path.dirname(use.path);
|
|
447
|
+
const coreDir = coreDirFrom(from);
|
|
448
|
+
if (!coreDir && runtimeFirst) continue;
|
|
449
|
+
// A page without installed Core reads the docs of the Core it renders
|
|
450
|
+
// with, found from its folder.
|
|
451
|
+
const key = coreDir ?? '';
|
|
452
|
+
const group =
|
|
453
|
+
byCore.get(key) ??
|
|
454
|
+
/** @type {any} */ (byCore.set(key, {from, uses: []}).get(key));
|
|
455
|
+
group.uses.push(use);
|
|
456
|
+
}
|
|
457
|
+
/** @type {Map<string, Map<string, string[]>>} */
|
|
458
|
+
const documentedBy = new Map();
|
|
459
|
+
/** @type {PageCorePropUse[]} */
|
|
460
|
+
const candidates = [];
|
|
461
|
+
for (const [coreDir, group] of byCore) {
|
|
462
|
+
const documented = await readDocs(
|
|
463
|
+
[...new Set(group.uses.map(use => use.component))],
|
|
464
|
+
group.from,
|
|
465
|
+
);
|
|
466
|
+
documentedBy.set(
|
|
467
|
+
coreDir,
|
|
468
|
+
new Map(
|
|
469
|
+
[...documented].map(([name, props]) => [name, propNamesOf(props)]),
|
|
470
|
+
),
|
|
471
|
+
);
|
|
472
|
+
for (const use of group.uses) {
|
|
473
|
+
const props = documentedBy.get(coreDir)?.get(use.component);
|
|
474
|
+
if (props != null && !props.includes(use.prop)) candidates.push(use);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// A page whose config maps a Core module path elsewhere (`paths`) reads
|
|
478
|
+
// another module, so it is not judged.
|
|
479
|
+
let judged = candidates.filter(
|
|
480
|
+
use => !projectMapsImport(use.source, use.path),
|
|
481
|
+
);
|
|
482
|
+
if (judged.length === 0) return {found: [], skipped: null};
|
|
483
|
+
// A candidate in a file that finds no installed Core is not judged; the
|
|
484
|
+
// line says Core is missing only when no page finds it, as doctor says.
|
|
485
|
+
judged = judged.filter(use => coreDirFrom(path.dirname(use.path)));
|
|
486
|
+
if (judged.length === 0) {
|
|
487
|
+
return pages.some(page => coreDirFrom(path.dirname(page)))
|
|
488
|
+
? {found: [], skipped: null}
|
|
489
|
+
: noCore();
|
|
490
|
+
}
|
|
491
|
+
const config = early ?? jsxRuntimeCheck(pages, projectDir);
|
|
492
|
+
if ('skipped' in config) return notChecked(config.skipped);
|
|
493
|
+
const {configs, configOf} = config;
|
|
494
|
+
const compiler = typescript();
|
|
495
|
+
if (!('ts' in compiler))
|
|
496
|
+
return {found: [], skipped: compiler.skipped, reason: compiler.reason};
|
|
497
|
+
const declarations = (
|
|
498
|
+
jsxDeclarations ?? (() => jsxDeclarationFiles(projectDir))
|
|
499
|
+
)();
|
|
500
|
+
if (declarations === null)
|
|
501
|
+
return notChecked('the project has more source files than are read');
|
|
502
|
+
/** @type {Map<string, {configFile: string, coreDir: string, from: string, uses: PageCorePropUse[]}>} */
|
|
503
|
+
const groups = new Map();
|
|
504
|
+
for (const use of judged) {
|
|
505
|
+
const from = path.dirname(use.path);
|
|
506
|
+
const coreDir = /** @type {string} */ (coreDirFrom(from));
|
|
507
|
+
const configFile = configOf.get(use.path) ?? '';
|
|
508
|
+
const key = `${configFile}\0${coreDir}`;
|
|
509
|
+
const group =
|
|
510
|
+
groups.get(key) ??
|
|
511
|
+
/** @type {any} */ (
|
|
512
|
+
groups.set(key, {configFile, coreDir, from, uses: []}).get(key)
|
|
513
|
+
);
|
|
514
|
+
group.uses.push(use);
|
|
515
|
+
}
|
|
516
|
+
// Core's types are read for candidates alone.
|
|
517
|
+
const {readCorePropTypes} = await import('./core-prop-types.mjs');
|
|
518
|
+
/** @type {UnknownCoreProp[]} */
|
|
519
|
+
const found = [];
|
|
520
|
+
for (const group of groups.values()) {
|
|
521
|
+
const documented = documentedBy.get(group.coreDir) ?? new Map();
|
|
522
|
+
// What augments Core for a page: the project's files and installed
|
|
523
|
+
// packages, and those of the page's own package, as a workspace member
|
|
524
|
+
// installs its own.
|
|
525
|
+
const memberDir = findPackageRoot(group.from) ?? projectDir;
|
|
526
|
+
const reads = [projectAugmentations(projectDir, group.uses[0].path)];
|
|
527
|
+
if (memberDir !== projectDir)
|
|
528
|
+
reads.push(projectAugmentations(memberDir, group.uses[0].path));
|
|
529
|
+
if (reads.some(read => !read.complete))
|
|
530
|
+
return notChecked(
|
|
531
|
+
"the files that may add to Core's types could not all be read",
|
|
532
|
+
);
|
|
533
|
+
const augmentations = [...new Set(reads.flatMap(read => read.files))];
|
|
534
|
+
/** @type {Map<string, Set<string>>} */
|
|
535
|
+
const asked = new Map();
|
|
536
|
+
/** @type {Map<string, string>} */
|
|
537
|
+
const sources = new Map();
|
|
538
|
+
for (const use of group.uses) {
|
|
539
|
+
(
|
|
540
|
+
asked.get(use.component) ??
|
|
541
|
+
asked.set(use.component, new Set()).get(use.component)
|
|
542
|
+
)?.add(use.prop);
|
|
543
|
+
if (!sources.has(use.component)) sources.set(use.component, use.source);
|
|
544
|
+
}
|
|
545
|
+
const types = readCorePropTypes({
|
|
546
|
+
ts: compiler.ts,
|
|
547
|
+
projectDir: group.from,
|
|
548
|
+
configDir: group.configFile ? path.dirname(group.configFile) : group.from,
|
|
549
|
+
options: configs.get(group.configFile)?.options ?? {},
|
|
550
|
+
augmentations: [...augmentations, ...declarations],
|
|
551
|
+
props: asked,
|
|
552
|
+
sources,
|
|
553
|
+
configFile: group.configFile || undefined,
|
|
554
|
+
});
|
|
555
|
+
if (types.unread) return notChecked(types.unread, types.unreadFix);
|
|
556
|
+
for (const use of group.uses) {
|
|
557
|
+
if (
|
|
558
|
+
types.attributes.has(use.prop) ||
|
|
559
|
+
types.takes.get(use.component)?.get(use.prop) !== false
|
|
560
|
+
)
|
|
561
|
+
continue;
|
|
562
|
+
const {path: _file, source: _source, ...report} = use;
|
|
563
|
+
found.push({
|
|
564
|
+
...report,
|
|
565
|
+
suggestion: closestProp(use.prop, documented.get(use.component) ?? []),
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
found.sort(
|
|
570
|
+
(a, b) =>
|
|
571
|
+
compareText(a.file, b.file) || a.line - b.line || a.column - b.column,
|
|
572
|
+
);
|
|
573
|
+
return {found, skipped: null};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* The documented prop a name means, when one has the same words: in another
|
|
578
|
+
* order or case, with a plural `s`, or with the `is` or `has` that Core puts
|
|
579
|
+
* in front of a yes-or-no prop (`isLabelHidden` for `labelHidden`,
|
|
580
|
+
* `startIcon` for `iconStart`). Words are read as a failed lookup reads them.
|
|
581
|
+
* A name with another word, or a near spelling, can mean something else
|
|
582
|
+
* (`padding` for `paddingX`, `maxWidth` for `minWidth`), so it is not
|
|
583
|
+
* offered. Null when no prop has the same words.
|
|
584
|
+
* @param {string} name
|
|
585
|
+
* @param {string[]} props
|
|
586
|
+
* @returns {string | null}
|
|
587
|
+
*/
|
|
588
|
+
function closestProp(name, props) {
|
|
589
|
+
const key = (/** @type {string} */ text) =>
|
|
590
|
+
nameWords(text)
|
|
591
|
+
.filter(word => word !== 'is' && word !== 'has')
|
|
592
|
+
.map(word => (word.length > 3 ? word.replace(/s$/, '') : word))
|
|
593
|
+
.sort()
|
|
594
|
+
.join(' ');
|
|
595
|
+
const wanted = key(name);
|
|
596
|
+
return (
|
|
597
|
+
orderByAffinity(name, props, prop => [prop]).find(
|
|
598
|
+
prop => prop !== name && key(prop) === wanted,
|
|
599
|
+
) ?? null
|
|
600
|
+
);
|
|
601
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./core-augmentation-points.mjs').ValueKind} ValueKind
|
|
6
|
+
* @typedef {{kinds: ValueKind[], strings: string[] | null}} WrittenValue
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* What a JSX attribute certainly gives its prop. Every branch of the value
|
|
10
|
+
* must be certain: a literal (a string, a template, a number, a boolean, an
|
|
11
|
+
* object or array literal, `new Date(…)`, a function), a conditional or
|
|
12
|
+
* logical expression of certain branches, a `const` bound to one, or the
|
|
13
|
+
* first value of `useState(<certain value>)`, which is what the first paint
|
|
14
|
+
* gets. A bare attribute (`<Button isDisabled>`) is `true`. A branch that is
|
|
15
|
+
* `null` or `undefined` gives no value. `strings` lists the string values
|
|
16
|
+
* when every string branch is a literal, else null. Null when any branch is
|
|
17
|
+
* not certain: such a prop is not checked.
|
|
18
|
+
* @param {any} attr a JSXAttribute node
|
|
19
|
+
* @param {any} scope the element's Babel scope
|
|
20
|
+
* @returns {WrittenValue | null}
|
|
21
|
+
*/
|
|
22
|
+
export function writtenValue(attr: any, scope: any): WrittenValue | null;
|
|
23
|
+
export type ValueKind = import("./core-augmentation-points.mjs").ValueKind;
|
|
24
|
+
export type WrittenValue = {
|
|
25
|
+
kinds: ValueKind[];
|
|
26
|
+
strings: string[] | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* One value a branch can give. `nullish` is `null` or `undefined`, which
|
|
30
|
+
* gives the prop no value.
|
|
31
|
+
*/
|
|
32
|
+
export type Leaf = {
|
|
33
|
+
kind: ValueKind | "nullish";
|
|
34
|
+
text?: string;
|
|
35
|
+
};
|