@astryxdesign/cli 0.7.2-canary.f16dc9f → 0.7.2-canary.f2b60a0
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 +15 -14
- package/api/build/help/help.mjs +1 -1
- package/api/component/_adapter.d.mts +41 -1
- package/api/component/_adapter.mjs +93 -7
- package/api/component/component.mjs +22 -5
- package/api/component/component.test.mjs +420 -167
- package/api/component/integration-export-name.test.mjs +644 -0
- package/api/component/list/list.mjs +42 -4
- package/api/docs/_adapter.d.mts +11 -0
- package/api/docs/_adapter.mjs +244 -1
- package/api/docs/integrationDocs.test.mjs +124 -0
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/gap-report/gap-report.mjs +67 -4
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/init/run/run.mjs +2 -2
- package/api/integration/_adapter.d.mts +12 -0
- package/api/integration/_adapter.mjs +54 -0
- package/api/integration/add-contribution.component-names.test.mjs +66 -0
- package/api/integration/add-contribution.mjs +8 -4
- package/api/integration/add-contribution.test.mjs +4 -2
- package/api/integration/authoring-checks.mjs +11 -2
- package/api/integration/authoring-checks.test.mjs +39 -0
- package/api/integration/authoring-checks.type.d.mts +9 -0
- package/api/integration/authoring-checks.type.mjs +14 -1
- package/api/integration/check/check.d.mts +96 -0
- package/api/integration/check/check.mjs +357 -0
- package/api/integration/check/check.test.mjs +489 -0
- package/api/integration/integration-check.type.d.mts +118 -0
- package/api/integration/integration-check.type.mjs +84 -0
- package/api/integration/integrationCheck.doc.d.mts +10 -0
- package/api/integration/integrationCheck.doc.mjs +73 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +36 -5
- package/api/integration/pack-check.mjs +61 -107
- package/api/integration/pack-check.test.mjs +359 -0
- package/api/integration/validate-integration.mjs +8 -0
- package/api/integration/validate-integration.test.mjs +11 -0
- package/api/integration/validate-integration.type.d.mts +8 -0
- package/api/integration/validate-integration.type.mjs +12 -1
- package/api/integration/validateIntegration.doc.mjs +17 -3
- package/api/search/search.d.mts +22 -6
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.integration-check.test.mjs +24 -0
- package/api/search/search.mjs +141 -25
- package/api/search/search.test.mjs +36 -0
- package/api/swizzle/copy/copy.mjs +28 -14
- package/api/template/template.test.mjs +120 -3
- package/api/theme/build/build.family.test.mjs +64 -0
- package/api/theme/build/build.mjs +180 -24
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
- package/assets/docs/README.md +10 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +11 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +8 -20
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +196 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
- package/assets/docs/tree/checks.doc.mjs +24 -16
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +8 -6
- package/assets/docs/tree/component-imports.doc.mjs +10 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +8 -0
- package/assets/docs/tree/links.doc.mjs +6 -5
- package/assets/docs/tree/migration-setup.doc.mjs +1 -0
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +4 -8
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +37 -21
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
- package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +15 -6
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
- package/assets/docs/tree/type-scale.doc.mjs +3 -3
- package/assets/docs/tree/upgrading.doc.mjs +3 -3
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs/working-with-ai.doc.mjs +43 -4
- package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
- package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
- package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
- package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
- package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
- package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
- package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
- package/assets/templates/pages/detail-page/page.tsx +3 -3
- package/assets/templates/pages/table-inbox/page.tsx +10 -8
- package/assets/theme.template.ts +1 -1
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/base/type.ts +6 -0
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +31 -28
- package/authoring/doctypes/component/type.ts +13 -8
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
- package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
- package/authoring/doctypes/template/parse.d.mts +6 -2
- package/authoring/doctypes/template/parse.mjs +3 -1
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/template/type.ts +22 -0
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/index.d.ts +1 -0
- package/authoring/integration/integration.doc.mjs +12 -4
- package/authoring/integration/parse.test.mjs +10 -0
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +4 -0
- package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
- package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +11 -2
- package/clients/cli/commands/doctor-integration.test.mjs +837 -0
- package/clients/cli/commands/doctor.mjs +190 -0
- package/clients/cli/commands/integration-check.doc.mjs +85 -0
- package/clients/cli/commands/integration-check.test.mjs +267 -0
- package/clients/cli/commands/integration.doc.mjs +6 -2
- package/clients/cli/commands/integration.mjs +107 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
- package/clients/cli/commands/text-json-parity.test.mjs +5 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/index.mjs +30 -5
- package/clients/cli/lib/component-format.mjs +5 -1
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/config/project.mjs +82 -0
- package/foundation/discovery/authoring-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.d.mts +190 -10
- package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
- package/foundation/discovery/component-discovery.mjs +864 -56
- package/foundation/discovery/component-discovery.test.mjs +96 -0
- package/foundation/discovery/component-replacement.mjs +18 -0
- package/foundation/discovery/component-replacement.test.mjs +40 -0
- package/foundation/discovery/doc-types.d.mts +157 -0
- package/foundation/discovery/doc-types.mjs +1224 -0
- package/foundation/discovery/doc-types.test.mjs +652 -0
- package/foundation/discovery/docs-discovery.d.mts +81 -0
- package/foundation/discovery/docs-discovery.mjs +57 -0
- package/foundation/discovery/integration-doc-files.d.mts +22 -0
- package/foundation/discovery/integration-doc-files.mjs +231 -0
- package/foundation/discovery/integration-doc-files.test.mjs +246 -0
- package/foundation/discovery/module-exports.d.mts +27 -0
- package/foundation/discovery/module-exports.mjs +356 -31
- package/foundation/discovery/module-exports.test.mjs +172 -0
- package/foundation/discovery/package-tsconfig.d.mts +14 -0
- package/foundation/discovery/package-tsconfig.mjs +228 -0
- package/foundation/discovery/package-tsconfig.test.mjs +210 -0
- package/foundation/discovery/project-typescript.d.mts +23 -0
- package/foundation/discovery/project-typescript.mjs +61 -0
- package/foundation/discovery/prop-drift.d.mts +278 -0
- package/foundation/discovery/prop-drift.mjs +2263 -0
- package/foundation/discovery/prop-drift.test.mjs +2219 -0
- package/foundation/discovery/template-adapter.mjs +74 -5
- package/foundation/discovery/type-match.d.mts +53 -0
- package/foundation/discovery/type-match.mjs +660 -0
- package/foundation/discovery/type-match.test.mjs +169 -0
- package/foundation/discovery/type-text.d.mts +68 -0
- package/foundation/discovery/type-text.mjs +658 -0
- package/foundation/discovery/type-text.test.mjs +196 -0
- package/foundation/discovery/unresolved-references.d.mts +62 -0
- package/foundation/discovery/unresolved-references.mjs +790 -0
- package/foundation/discovery/unresolved-references.test.mjs +567 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +11 -1
- package/foundation/doc-compiler/inputs.mjs +23 -0
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/links.d.mts +9 -5
- package/foundation/doc-compiler/links.mjs +4 -2
- package/foundation/integrations/contribution-inventory.mjs +6 -1
- package/foundation/response/response-types.doc.mjs +7 -2
- package/foundation/xle/registry.mjs +4 -0
- package/foundation/xle/registry.test.mjs +28 -0
- package/package.json +10 -10
- package/scripts/postinstall.mjs +3 -3
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @file The type-text normalization the prop type judgment compares by. */
|
|
4
|
+
|
|
5
|
+
import {createRequire} from 'node:module';
|
|
6
|
+
import {describe, expect, it} from 'vitest';
|
|
7
|
+
import {
|
|
8
|
+
normalizeTypeText as normalize,
|
|
9
|
+
typeTextTooOld,
|
|
10
|
+
UNPARSED,
|
|
11
|
+
} from './type-text.mjs';
|
|
12
|
+
|
|
13
|
+
const ts = createRequire(import.meta.url)('typescript');
|
|
14
|
+
/** @type {(text: string, options?: {optional?: boolean}) => readonly string[]} */
|
|
15
|
+
const normalizeTypeText = (text, options = {}) =>
|
|
16
|
+
normalize(text, {...options, ts});
|
|
17
|
+
|
|
18
|
+
describe('normalizeTypeText', () => {
|
|
19
|
+
it.each([
|
|
20
|
+
["'b' | 'a'", '"a" | "b"'],
|
|
21
|
+
['React.ReactNode', 'ReactNode'],
|
|
22
|
+
['Array<string>', 'string[]'],
|
|
23
|
+
['ReadonlyArray<"a" | "b">', "('a' | 'b')[]"],
|
|
24
|
+
['readonly string[]', 'string[]'],
|
|
25
|
+
['Readonly<Status>', 'Status'],
|
|
26
|
+
['true | false', 'boolean'],
|
|
27
|
+
["'sm' | string", 'string'],
|
|
28
|
+
['(e: MouseEvent) => void', '(event: MouseEvent) => void'],
|
|
29
|
+
['{b: number; a?: string}', '{ a?: string, b: number }'],
|
|
30
|
+
['{ /** doc */ a: string; }', '{a: string}'],
|
|
31
|
+
['{get /*c*/ a(): string}', '{get a(): string}'],
|
|
32
|
+
['{get a(): string; b: number}', '{b: number, get a(): string}'],
|
|
33
|
+
['{set a(v: string), b: number}', '{set a(v: string); b: number}'],
|
|
34
|
+
['{a: string, b: number}', '{a: string; b: number}'],
|
|
35
|
+
['"a"|"b"', "'a' | 'b'"],
|
|
36
|
+
['string | never', 'string'],
|
|
37
|
+
['Array<() => void>', '(() => void)[]'],
|
|
38
|
+
[
|
|
39
|
+
'Array<(value: string) => string | undefined>',
|
|
40
|
+
'((v: string) => string | undefined)[]',
|
|
41
|
+
],
|
|
42
|
+
['readonly ("a" | "b")[]', "ReadonlyArray<'a' | 'b'>"],
|
|
43
|
+
['readonly [string, number]', '[string, number]'],
|
|
44
|
+
['(() => void) | null', 'null | (() => void)'],
|
|
45
|
+
['() => (string | null)', '() => null | string'],
|
|
46
|
+
['(this: Window) => void', '(this: Window) => void'],
|
|
47
|
+
['(a: X, b: X) => a is T', '(c: X, d: X) => c is T'],
|
|
48
|
+
['Readonly<A & B>[]', '(A & B)[]'],
|
|
49
|
+
['Readonly<{a: string; b: number}>', '{b: number; a: string}'],
|
|
50
|
+
['Readonly<Record<string, string>>', 'Record<string, string>'],
|
|
51
|
+
["(v: unknown) => v is 'x'", "(value: unknown) => value is 'x'"],
|
|
52
|
+
['(a: A, b?: B) => void', '(x: A, y?: B) => void'],
|
|
53
|
+
['[a: string, b?: number]', '[string, number?]'],
|
|
54
|
+
["{'a': string}", '{a: string}'],
|
|
55
|
+
['1e3 | 1000', '1000'],
|
|
56
|
+
['T extends string ? (() => B) : C', 'T extends string ? () => B : C'],
|
|
57
|
+
['(A | B) | C', 'C | B | A'],
|
|
58
|
+
])('reads %s as %s', (a, b) => {
|
|
59
|
+
expect(normalizeTypeText(a)).toEqual(normalizeTypeText(b));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('returns a result no caller can change for the next', () => {
|
|
63
|
+
const first = normalizeTypeText("'b' | 'a'");
|
|
64
|
+
expect(() => /** @type {string[]} */ (first).push('c')).toThrow();
|
|
65
|
+
expect(normalizeTypeText("'b' | 'a'")).toEqual(["'a'", "'b'"]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('drops undefined only on an optional prop', () => {
|
|
69
|
+
expect(normalizeTypeText('string | undefined', {optional: true})).toEqual([
|
|
70
|
+
'string',
|
|
71
|
+
]);
|
|
72
|
+
expect(normalizeTypeText('string | undefined')).toEqual([
|
|
73
|
+
'string',
|
|
74
|
+
'undefined',
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it.each([
|
|
79
|
+
["'a' | 'b'", "'a'"],
|
|
80
|
+
['(a: string) => void', '(a: number) => void'],
|
|
81
|
+
// An array of callbacks, and a callback that returns an array.
|
|
82
|
+
['(() => void)[]', '() => void[]'],
|
|
83
|
+
[
|
|
84
|
+
'((value: string) => string | undefined)[]',
|
|
85
|
+
'(value: string) => string | undefined[]',
|
|
86
|
+
],
|
|
87
|
+
['Array<() => void>', '() => void[]'],
|
|
88
|
+
// An array of an intersection, and an intersection with an array.
|
|
89
|
+
['(A & B)[]', 'A & B[]'],
|
|
90
|
+
['Array<A & B>', 'A & B[]'],
|
|
91
|
+
['(keyof T)[]', 'keyof T[]'],
|
|
92
|
+
['keyof (A & B)', 'keyof A & B'],
|
|
93
|
+
// `never` that is a whole type, not a union member.
|
|
94
|
+
['(x: never) => void', '() => void'],
|
|
95
|
+
['[never]', '[]'],
|
|
96
|
+
['Array<never>', '[]'],
|
|
97
|
+
// String literals as written.
|
|
98
|
+
["{a: 'x;y'}", "{a: 'x,y'}"],
|
|
99
|
+
["'readonly x'", "'x'"],
|
|
100
|
+
["'React.Node'", "'Node'"],
|
|
101
|
+
// A union around a function, and one in its return.
|
|
102
|
+
['(() => ReactNode) | null', '() => ReactNode | null'],
|
|
103
|
+
['(() => string) | undefined', '() => string | undefined'],
|
|
104
|
+
['Array<(() => ReactNode) | null>', 'Array<() => ReactNode | null>'],
|
|
105
|
+
['{f: (() => ReactNode) | null}', '{f: () => ReactNode | null}'],
|
|
106
|
+
// `this` is no ordinary parameter.
|
|
107
|
+
['(this: Window, e: Event) => void', '(w: Window, e: Event) => void'],
|
|
108
|
+
// A conditional's false branch takes the rest of a union.
|
|
109
|
+
['T extends string ? A : B | C', '(T extends string ? A : B) | C'],
|
|
110
|
+
// An array of `Readonly<A & B>` is no intersection with an array.
|
|
111
|
+
['Readonly<A & B>[]', 'A & B[]'],
|
|
112
|
+
// `keyof` keeps its operand apart from the name after it.
|
|
113
|
+
['Array<keyof (B)>', 'keyof (Array<B>)'],
|
|
114
|
+
// A type predicate names a parameter by its place.
|
|
115
|
+
['(a: X, b: X) => a is T', '(b: X, a: X) => a is T'],
|
|
116
|
+
[
|
|
117
|
+
"(a: unknown, b: unknown) => a is 'x'",
|
|
118
|
+
"(b: unknown, a: unknown) => a is 'x'",
|
|
119
|
+
],
|
|
120
|
+
// A function in a conditional's true branch returns only its own type.
|
|
121
|
+
[
|
|
122
|
+
'T extends string ? () => B : C | A',
|
|
123
|
+
'T extends string ? () => A | B : C',
|
|
124
|
+
],
|
|
125
|
+
// `Readonly<…>` keeps its argument grouped.
|
|
126
|
+
['Readonly<A | B> & C', 'A | (B & C)'],
|
|
127
|
+
['keyof Readonly<A & B>', '(keyof A) & B'],
|
|
128
|
+
// Overloads keep their order; an intersection's members keep theirs.
|
|
129
|
+
['{(a: string): A; (a: number): B}', '{(a: number): B; (a: string): A}'],
|
|
130
|
+
// Text that does not parse is kept as written.
|
|
131
|
+
['string?', 'string'],
|
|
132
|
+
// Text spelled as the printer prints a type, but that does not parse.
|
|
133
|
+
['((Item[]) => void)[]', '((items: Item[]) => void)[]'],
|
|
134
|
+
// A computed property name, and an index signature.
|
|
135
|
+
['{[K]: number}', '{[k: K]: number}'],
|
|
136
|
+
// A method named `'new'`, and a construct signature.
|
|
137
|
+
["{'new'(): X}", '{new(): X}'],
|
|
138
|
+
// A comment between two words separates them, as a space does.
|
|
139
|
+
['{get/*c*/a(): string}', '{geta(): string}'],
|
|
140
|
+
// Import attributes change which file a module resolves to.
|
|
141
|
+
[
|
|
142
|
+
"import('dual', {with: {'resolution-mode': 'import'}}).T",
|
|
143
|
+
"import('dual', {with: {'resolution-mode': 'require'}}).T",
|
|
144
|
+
],
|
|
145
|
+
])('keeps %s and %s different', (a, b) => {
|
|
146
|
+
expect(normalizeTypeText(a)).not.toEqual(normalizeTypeText(b));
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('marks text that does not parse, and names a TypeScript too old to read types with', () => {
|
|
150
|
+
expect(normalizeTypeText('((Item[]) => void)[]')).toEqual([
|
|
151
|
+
`${UNPARSED}((Item[])=>void)[]`,
|
|
152
|
+
]);
|
|
153
|
+
// Forms only the checker rejects.
|
|
154
|
+
for (const text of [
|
|
155
|
+
'Foo<>',
|
|
156
|
+
'Array.<string>',
|
|
157
|
+
'{a: Map<>}',
|
|
158
|
+
'typeof Foo<>',
|
|
159
|
+
'?string',
|
|
160
|
+
'string?',
|
|
161
|
+
'*',
|
|
162
|
+
'function(string): void',
|
|
163
|
+
'{[K in keyof P]: P[K]; extra: string}',
|
|
164
|
+
'{public a: string}',
|
|
165
|
+
'(public a: string) => void',
|
|
166
|
+
'(a: string = "x") => void',
|
|
167
|
+
'<in T>(x: T) => void',
|
|
168
|
+
'{[k?: string]: number}',
|
|
169
|
+
'{[a: string, b: string]: number}',
|
|
170
|
+
"{a: string = 'x'}",
|
|
171
|
+
'Foo<A,>',
|
|
172
|
+
]) {
|
|
173
|
+
expect(normalizeTypeText(text)[0].startsWith(UNPARSED)).toBe(true);
|
|
174
|
+
}
|
|
175
|
+
expect(normalizeTypeText('Array /* v1.2 */ <string>')).toEqual([
|
|
176
|
+
'string[]',
|
|
177
|
+
]);
|
|
178
|
+
expect(typeTextTooOld({version: '4.7.4'})).toBe(
|
|
179
|
+
'TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads',
|
|
180
|
+
);
|
|
181
|
+
for (const version of ['4.8.4', '5.0.4', '6.0.3', ts.version]) {
|
|
182
|
+
expect(typeTextTooOld({version})).toBeNull();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('keeps a union around a function apart from one in its return, joined as the members are', () => {
|
|
187
|
+
for (const [a, b] of [
|
|
188
|
+
['(() => ReactNode) | null', '() => ReactNode | null'],
|
|
189
|
+
['(T extends string ? A : B) | C', 'T extends string ? A : B | C'],
|
|
190
|
+
]) {
|
|
191
|
+
expect(normalizeTypeText(a).join('|')).not.toBe(
|
|
192
|
+
normalizeTypeText(b).join('|'),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
* The first reference that does not resolve from the given files, the files
|
|
6
|
+
* they import, and so on, as far as `follow` allows. A reference fails when
|
|
7
|
+
* the program finds no module, no type package or no file for it, when a
|
|
8
|
+
* module does not export a name imported from it, or, in the files `mine`
|
|
9
|
+
* accepts, when a type name resolves to no declaration (TS2304). A module
|
|
10
|
+
* found without types (a JavaScript file) resolves: its names are `any`. A
|
|
11
|
+
* side-effect import counts where the compiler checks one
|
|
12
|
+
* (`noUncheckedSideEffectImports`, on by default from TypeScript 6).
|
|
13
|
+
* @param {any} ts the project's own `typescript`
|
|
14
|
+
* @param {any} program
|
|
15
|
+
* @param {any} checker
|
|
16
|
+
* @param {any[]} roots source files
|
|
17
|
+
* @param {(file: string) => boolean} follow which files it reads past them
|
|
18
|
+
* @param {(file: string) => boolean} mine whose type names it checks
|
|
19
|
+
* @returns {UnresolvedReference | null}
|
|
20
|
+
*/
|
|
21
|
+
export function unresolvedReference(ts: any, program: any, checker: any, roots: any[], follow: (file: string) => boolean, mine: (file: string) => boolean): UnresolvedReference | null;
|
|
22
|
+
/**
|
|
23
|
+
* The first reference that does not resolve from the program's global roots,
|
|
24
|
+
* whose types every file sees: a type package the program loads by name
|
|
25
|
+
* (`compilerOptions.types`, `*` expanded as TypeScript does, or every
|
|
26
|
+
* package in `typeRoots` where TypeScript loads them all) that cannot be
|
|
27
|
+
* found, or a reference in a declaration file the package's own config
|
|
28
|
+
* includes, wherever it sits, or in the package's own type packages, or in a
|
|
29
|
+
* file they import. Of those, only a file that acts globally starts the walk:
|
|
30
|
+
* a script, `declare global`, `declare module`, `export as namespace`, an
|
|
31
|
+
* import that takes no names (a side-effect import, `import {} from`), a
|
|
32
|
+
* bare `export *`, or a `/// <reference>`. A config from above the package,
|
|
33
|
+
* such as a monorepo's root config, may include the whole repository, so
|
|
34
|
+
* only the package's own declaration files start the walk then. A
|
|
35
|
+
* dependency's declarations (below `node_modules`) are not followed: `tsc`
|
|
36
|
+
* skips their errors (`skipLibCheck`), and they reach a component only
|
|
37
|
+
* through the globals they declare.
|
|
38
|
+
* @param {any} ts the project's own `typescript`
|
|
39
|
+
* @param {any} program
|
|
40
|
+
* @param {any} checker
|
|
41
|
+
* @param {string[]} declarations the declaration files the config includes
|
|
42
|
+
* @param {any} options the program's compiler options
|
|
43
|
+
* @param {(file: string) => boolean} isOwnFile whether a file is the
|
|
44
|
+
* package's own
|
|
45
|
+
* @returns {UnresolvedReference | null}
|
|
46
|
+
*/
|
|
47
|
+
export function unresolvedGlobals(ts: any, program: any, checker: any, declarations: string[], options: any, isOwnFile: (file: string) => boolean): UnresolvedReference | null;
|
|
48
|
+
export type UnresolvedReference = {
|
|
49
|
+
/**
|
|
50
|
+
* the reference as written, quoted
|
|
51
|
+
*/
|
|
52
|
+
name: string;
|
|
53
|
+
/**
|
|
54
|
+
* the file that writes it
|
|
55
|
+
*/
|
|
56
|
+
file: string;
|
|
57
|
+
/**
|
|
58
|
+
* a file imports it, a file
|
|
59
|
+
* uses it as a type name, or the config names it
|
|
60
|
+
*/
|
|
61
|
+
how: "imported" | "used" | "named";
|
|
62
|
+
};
|