@conloca/astro-cms 0.1.16 → 0.2.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 +254 -301
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/{src → ts/src}/cms-handler.js +11 -131
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +161 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +178 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/hydration.js +1 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +13 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +45 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.js +33 -15
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.js +13 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/withHydration.js +1 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/{src → ts/src}/loader.js +33 -4
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/{src → ts/src}/locales-helpers.js +1 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/{src → ts/src}/mime-types.js +1 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/{src → ts/src}/path-validation.js +1 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.js +301 -88
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +16 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +117 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/{src → ts/src}/types.d.ts +26 -110
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +12 -93
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +161 -73
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +11 -0
- package/src/cms-handler.ts +281 -0
- package/src/collections.ts +271 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +53 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
- package/src/loader.ts +145 -0
- package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1496 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +134 -0
- package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections-Bd7EME4b.mjs +0 -129
- package/dist/collections-Bd7EME4b.mjs.map +0 -1
- package/dist/collections.d.mts +0 -35
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -2
- package/dist/components.d.mts +0 -41
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -223
- package/dist/components.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -2
- package/dist/index.d.mts +0 -108
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -67
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -25
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -314
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts +0 -30
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -84
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
- package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
- package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -18
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.d.ts +0 -3
- package/dist/node/content.d.ts.map +0 -1
- package/dist/node/content.js +0 -2
- package/dist/node/content.mjs +0 -2
- package/dist/node/index.d.mts +0 -200
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts +0 -4
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.mjs +0 -2513
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-BHoNpzH6.mjs +0 -72
- package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
- package/dist/src/cms-handler.d.ts.map +0 -1
- package/dist/src/collections.d.ts +0 -32
- package/dist/src/collections.d.ts.map +0 -1
- package/dist/src/collections.js +0 -50
- package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.js +0 -129
- package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
- package/dist/src/components.d.ts +0 -4
- package/dist/src/components.d.ts.map +0 -1
- package/dist/src/components.js +0 -3
- package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
- package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
- package/dist/src/discovery/merge-registry.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.d.ts +0 -42
- package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.js +0 -81
- package/dist/src/discovery/scan-components.d.ts.map +0 -1
- package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
- package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
- package/dist/src/hydration.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -25
- package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
- package/dist/src/lib/hydration-script.d.ts.map +0 -1
- package/dist/src/lib/hydration-utils.d.ts.map +0 -1
- package/dist/src/lib/page-api.d.ts +0 -77
- package/dist/src/lib/page-api.d.ts.map +0 -1
- package/dist/src/lib/page-api.js +0 -121
- package/dist/src/lib/route-utils.d.ts.map +0 -1
- package/dist/src/lib/routing-config.d.ts.map +0 -1
- package/dist/src/lib/serialize-props.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.js +0 -263
- package/dist/src/lib/withHydration.d.ts.map +0 -1
- package/dist/src/loader.d.ts +0 -14
- package/dist/src/loader.d.ts.map +0 -1
- package/dist/src/locales-helpers.d.ts.map +0 -1
- package/dist/src/mime-types.d.ts.map +0 -1
- package/dist/src/path-validation.d.ts.map +0 -1
- package/dist/src/plugin-spa.d.ts.map +0 -1
- package/dist/src/safe-json-stringify.d.ts.map +0 -1
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -1
- package/dist/types-CS9neadI.d.mts.map +0 -1
- package/dist/withHydration-C256ox_6.mjs +0 -49
- package/dist/withHydration-C256ox_6.mjs.map +0 -1
- package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
- /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
- /package/dist/{src → ts/src}/hydration.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
- /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
- /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
- /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
- /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the component a wrapper call builds — `export const Grid =
|
|
3
|
+
* withLayout(GridInternal)` — on paper, by merging the argument's written-down
|
|
4
|
+
* literal with the wrapper's written-down additions. The wrapper is never run:
|
|
5
|
+
* this reader is handed arbitrary site source, and a manifest is not worth
|
|
6
|
+
* executing a stranger's module for.
|
|
7
|
+
*
|
|
8
|
+
* The shape a wrapper must have is deliberately narrow — one `return` of an
|
|
9
|
+
* object literal, every parameter bound by an argument that resolves to a
|
|
10
|
+
* literal, no destructuring, no rest, no nesting. Each of those rules is here
|
|
11
|
+
* because probing real and adversarial configs showed that dropping it
|
|
12
|
+
* produces a confident wrong answer rather than a gap: a body reading an unbound
|
|
13
|
+
* `opts.label ?? 'fallback'` summarizes as the argument's own label, which is a
|
|
14
|
+
* lie an agent has no way to catch. Everything outside the shape is refused,
|
|
15
|
+
* and every refusal carries the reason, so the caller reports "could not read,
|
|
16
|
+
* because X" instead of a component that appears to accept nothing.
|
|
17
|
+
*
|
|
18
|
+
* The same machinery, read a second way, is how a FIELD declared through a
|
|
19
|
+
* helper is recovered: `buttons: ctaButtonArrayField()` returns one object
|
|
20
|
+
* literal too, and only what that literal is read AS differs. The rules for
|
|
21
|
+
* the body hold for both; the rules for binding do not. A builder is called
|
|
22
|
+
* for its whole answer rather than to decorate an argument, so it may take no
|
|
23
|
+
* parameters, an argument the call omits binds undefined — `{ ...overrides }`
|
|
24
|
+
* then spreads nothing, and a key read off it is left unread and admitted —
|
|
25
|
+
* and a plain value such as `'Title'` binds as itself. The `opts.label ??
|
|
26
|
+
* 'fallback'` above is a wrapper's hazard; in a builder that expression is
|
|
27
|
+
* left unread, and the field admits it.
|
|
28
|
+
*
|
|
29
|
+
* The component walk the wrapper reading ends in is also how the config reads
|
|
30
|
+
* every component, written in place or reached by name: `readComponentWithSpreads`
|
|
31
|
+
* walks a component literal by the same rules with nothing bound, and a spread
|
|
32
|
+
* of a wrapper-built component — `Grid: { ...Grid, label: … }` — merges the
|
|
33
|
+
* wrapper's reading where the spread sits, as `readWrapperCallReading` hands
|
|
34
|
+
* it over.
|
|
35
|
+
*
|
|
36
|
+
* Known limit: a wrapper that MUTATES a shared config at import time —
|
|
37
|
+
* `Object.assign(base, extra)` — defeats any reader that works from source,
|
|
38
|
+
* because the text says one thing and the module's load order does another.
|
|
39
|
+
* Nothing here detects it; it is covered by watching what the site actually
|
|
40
|
+
* renders, not by reading.
|
|
41
|
+
*
|
|
42
|
+
* Known limit: a slot's nesting rules may be written on the field or on the
|
|
43
|
+
* slot the component's `render` draws — `<Items disallow={['Hero']} />` — and
|
|
44
|
+
* the render's are the ones the canvas enforces. Only the field form is read,
|
|
45
|
+
* `render` being code; a slot writing no rules of its own is admitted rather
|
|
46
|
+
* than reported as taking anything, and what really nests inside it is
|
|
47
|
+
* answered the same way, by watching what the site renders.
|
|
48
|
+
*/
|
|
49
|
+
import { Node, SyntaxKind, VariableDeclarationKind, } from 'ts-morph';
|
|
50
|
+
import { carryKey, readField, readFieldSet } from './field-projection.js';
|
|
51
|
+
import { asObjectLiteral, excerpt, holdsNothing, namedMember, propertyKey, SPREADS_NOTHING, setsPrototype, spendWork, unwrapExpression, writtenValue, } from './literal.js';
|
|
52
|
+
import { lookUpKey, resolveLiteralValue, resolveLiteralValueReading, resolveObjectLiteral, } from './resolve-reference.js';
|
|
53
|
+
/** The component keys this reader takes a value from, as opposed to the behaviour markers. */
|
|
54
|
+
const DATA_KEYS = new Set(['label', 'fields', 'defaultProps', 'ai']);
|
|
55
|
+
/**
|
|
56
|
+
* Config keys whose value is a function encoding behaviour we cannot read.
|
|
57
|
+
* Each becomes a marker so the agent knows the description is incomplete HERE
|
|
58
|
+
* rather than assuming it is complete everywhere.
|
|
59
|
+
*
|
|
60
|
+
* A Map rather than an object literal: a plain object answers for `toString`
|
|
61
|
+
* and `constructor` as readily as for the three keys written here, so a
|
|
62
|
+
* component carrying either name would be handed the prototype's value and
|
|
63
|
+
* write a marker named `undefined` onto the manifest.
|
|
64
|
+
*
|
|
65
|
+
* A computed key this reader cannot name may be any of the three, setting a
|
|
66
|
+
* behaviour or erasing one, so it takes each marker with it and lists the key
|
|
67
|
+
* in `unreadableKeys` — whether the marker applies cannot be read. A later
|
|
68
|
+
* write of the key, spelled out, settles it again.
|
|
69
|
+
*/
|
|
70
|
+
const BEHAVIOUR_MARKERS = new Map([
|
|
71
|
+
['resolveFields', 'dynamicFields'],
|
|
72
|
+
['resolveData', 'derivedProps'],
|
|
73
|
+
['resolvePermissions', 'hasPlacementRules'],
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* Same cap, and the same reason, as the walk in `resolve-reference`: the alias
|
|
77
|
+
* chain being followed comes from someone else's source, so the walk stops on
|
|
78
|
+
* its own terms rather than on the compiler's.
|
|
79
|
+
*/
|
|
80
|
+
const MAX_ALIAS_HOPS = 5;
|
|
81
|
+
/**
|
|
82
|
+
* How far a chain of spreads or member accesses may be followed.
|
|
83
|
+
*
|
|
84
|
+
* It bounds depth, not total work: a wide object with fifty spreads side by
|
|
85
|
+
* side is read in full, and only a chain that keeps descending is stopped. A
|
|
86
|
+
* spread that leads back to where it started — `const A = { ...B }` beside
|
|
87
|
+
* `const B = { ...A }` — is source that could not have loaded at runtime
|
|
88
|
+
* either, and following it forever takes the caller down with it rather than
|
|
89
|
+
* reporting anything. Set well past what any config written on purpose
|
|
90
|
+
* reaches, so the cap only ever catches a cycle.
|
|
91
|
+
*/
|
|
92
|
+
const MAX_SPREAD_DEPTH = 16;
|
|
93
|
+
/**
|
|
94
|
+
* A refusal is thrown rather than returned so that a rule broken six calls deep
|
|
95
|
+
* — an unresolvable spread inside a nested object — reaches the caller with its
|
|
96
|
+
* own reason instead of arriving as a bare `undefined` that says nothing.
|
|
97
|
+
*/
|
|
98
|
+
class Refusal extends Error {
|
|
99
|
+
}
|
|
100
|
+
function refuse(why) {
|
|
101
|
+
throw new Refusal(why);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* What a cap says when it is reached. It reports how far the walk went rather
|
|
105
|
+
* than accusing the config of a cycle outright: a chain this long is almost
|
|
106
|
+
* always one, but "stopped after 16" is what was actually observed.
|
|
107
|
+
*/
|
|
108
|
+
function capped(what) {
|
|
109
|
+
return refuse(`followed ${what} ${MAX_SPREAD_DEPTH} deep and stopped (usually a cycle: an object that spreads or names itself)`);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The manifest component a `wrapper(inner)` call amounts to.
|
|
113
|
+
*
|
|
114
|
+
* Both of our own sites build their layout primitives this way, and those are
|
|
115
|
+
* exactly the components carrying the slot nesting rules an agent needs, so a
|
|
116
|
+
* reader that stops at the call reports the most structural components on the
|
|
117
|
+
* site as unknown.
|
|
118
|
+
*/
|
|
119
|
+
export function readWrapperCall(call) {
|
|
120
|
+
const { reading, reason } = readWrapperCallReading(call);
|
|
121
|
+
return reading ? { component: reading.component } : { reason };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The same reading, kept whole for a caller that MERGES it — `Grid: { ...Grid,
|
|
125
|
+
* label: … }`, where the spread source is a wrapper call.
|
|
126
|
+
*
|
|
127
|
+
* A merge needs more than the component: a key the source wrote in a shape this
|
|
128
|
+
* reader could not take has to overwrite what sits beside it, and only the
|
|
129
|
+
* reading knows which keys were written.
|
|
130
|
+
*/
|
|
131
|
+
export function readWrapperCallReading(call) {
|
|
132
|
+
const { read, reason } = caught(() => readCall(call));
|
|
133
|
+
return read ? { reading: read } : { reason };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The manifest field a field-builder call such as `ctaButtonArrayField()`
|
|
137
|
+
* amounts to.
|
|
138
|
+
*
|
|
139
|
+
* A site may declare many of its fields by calling a helper like this one, and
|
|
140
|
+
* a reader that stops at the call reports every one of them as a prop with no
|
|
141
|
+
* shape at all — no type, no bounds, no item fields — which is the difference
|
|
142
|
+
* between an agent that can fill a button array in and one that can only guess
|
|
143
|
+
* at it. The call is the same summarizable shape a wrapper is, so it is read
|
|
144
|
+
* with the same machinery; only the returned literal is read as a field.
|
|
145
|
+
*
|
|
146
|
+
* The depth is how far into a field set the call already sits, so a builder
|
|
147
|
+
* reached from inside another builder's item fields cannot restart the cap that
|
|
148
|
+
* stops a cycle.
|
|
149
|
+
*/
|
|
150
|
+
export function readFieldBuilderCall(call, depth = 0) {
|
|
151
|
+
const { read, reason } = caught(() => readBuilderCall(call, depth));
|
|
152
|
+
return read ? { field: read } : { reason };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The component a written-down literal amounts to, with everything it spreads
|
|
156
|
+
* over applied — `const X = { ...Base }`, where Base spreads something of its
|
|
157
|
+
* own.
|
|
158
|
+
*
|
|
159
|
+
* This is how the config reader reads every component entry, written in place or
|
|
160
|
+
* reached by name: reading one with a spread-blind reader answers "accepts
|
|
161
|
+
* nothing" with no marker to say the spread was skipped. Nothing is bound — a
|
|
162
|
+
* literal reached by name has no wrapper parameters in scope — so a caller that
|
|
163
|
+
* can follow a spread this walker cannot, to a wrapper CALL rather than a
|
|
164
|
+
* literal, hands that in.
|
|
165
|
+
*/
|
|
166
|
+
export function readComponentWithSpreads(literal, spreads) {
|
|
167
|
+
const { read, reason } = caught(() => readLiteral(literal, new Map(), 0, spreads));
|
|
168
|
+
return read ? { component: read.component } : { reason };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Whether a call reaches a function the source declares — the one kind of call
|
|
172
|
+
* read as a wrapper. A `let` or `var` counts too: the wrapper is written in the
|
|
173
|
+
* config even though its body is not trusted, and its own refusal says why. A
|
|
174
|
+
* call to anything else is a value this reader cannot follow, not a wrapper it
|
|
175
|
+
* refused.
|
|
176
|
+
*/
|
|
177
|
+
export function callsDeclaredFunction(call) {
|
|
178
|
+
const { read, reason } = caught(() => calleeDeclaration(call));
|
|
179
|
+
return read !== undefined || reason === DECLARED_WITH_LET_OR_VAR;
|
|
180
|
+
}
|
|
181
|
+
/** Why a call is refused whose function is declared, but with `let` or `var`. */
|
|
182
|
+
const DECLARED_WITH_LET_OR_VAR = 'the function called is declared with let or var, so what it holds when the call runs may not be the function written there';
|
|
183
|
+
/** Turns a refusal thrown deep in a reading into the reason it carries; anything else is a real bug. */
|
|
184
|
+
function caught(read) {
|
|
185
|
+
try {
|
|
186
|
+
return { read: read() };
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
if (error instanceof Refusal)
|
|
190
|
+
return { reason: error.message };
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** The reading itself, which refuses by throwing so every rule reports its own reason. */
|
|
195
|
+
function readCall(call) {
|
|
196
|
+
const literals = callArgumentLiterals(call);
|
|
197
|
+
const fn = calleeDeclaration(call);
|
|
198
|
+
const parameters = calleeParameters(fn);
|
|
199
|
+
// A wrapper with nothing to wrap builds its component out of code rather than
|
|
200
|
+
// out of an argument, which is not the shape this reader can see through.
|
|
201
|
+
if (parameters.length === 0)
|
|
202
|
+
refuse('the wrapper takes no parameters, so it builds its component from code rather than from what the call passes');
|
|
203
|
+
// Every parameter must be bound by an argument this reader could resolve. An
|
|
204
|
+
// unbound one is a value the wrapper reads and this reader cannot see, and a
|
|
205
|
+
// body that consults it would be summarized with that branch silently
|
|
206
|
+
// missing — the one wrong answer the probe caught in the wild.
|
|
207
|
+
if (parameters.length !== literals.length) {
|
|
208
|
+
refuse(`the wrapper takes ${parameters.length} parameters but the call passes ${literals.length}`);
|
|
209
|
+
}
|
|
210
|
+
const environment = new Map();
|
|
211
|
+
parameters.forEach((declaration, index) => {
|
|
212
|
+
const literal = literals[index];
|
|
213
|
+
if (literal)
|
|
214
|
+
environment.set(declaration.getName(), { declaration, literal });
|
|
215
|
+
});
|
|
216
|
+
return readLiteral(returnedLiteral(fn, environment, 'component'), environment, 0);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The field a builder call declares, refusing by throwing so every rule reports
|
|
220
|
+
* its own reason.
|
|
221
|
+
*
|
|
222
|
+
* A builder is called for its whole answer rather than to decorate an argument,
|
|
223
|
+
* so — unlike a wrapper — it may take nothing at all, and an argument the call
|
|
224
|
+
* omits is bound rather than refused.
|
|
225
|
+
*/
|
|
226
|
+
function readBuilderCall(call, depth) {
|
|
227
|
+
const fn = calleeDeclaration(call);
|
|
228
|
+
const parameters = calleeParameters(fn);
|
|
229
|
+
const environment = bindArguments(parameters, call.getArguments().map(argumentBinding));
|
|
230
|
+
return readFieldWithEnv(returnedLiteral(fn, environment, 'field'), environment, depth);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The literal each argument names, in order. A value that is not an object is
|
|
234
|
+
* refused here: a wrapper is handed a component, and a body spreading anything
|
|
235
|
+
* else produces nothing a component could be read out of.
|
|
236
|
+
*/
|
|
237
|
+
function callArgumentLiterals(call) {
|
|
238
|
+
const args = call.getArguments();
|
|
239
|
+
if (args.length === 0)
|
|
240
|
+
refuse('the call passes no arguments, so there is no component for the wrapper to build on');
|
|
241
|
+
return args.map((argument) => {
|
|
242
|
+
const binding = argumentBinding(argument);
|
|
243
|
+
if (binding.literal)
|
|
244
|
+
return binding.literal;
|
|
245
|
+
return refuse(`the call passes ${excerpt(unwrapExpression(argument).getText())}, which is not an object written out in the source or a name for one`);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* What one argument binds: the object literal it names, or the plain value it
|
|
250
|
+
* writes down.
|
|
251
|
+
*
|
|
252
|
+
* A nested call is refused rather than followed. A parameter is bound to a
|
|
253
|
+
* literal, and substituting an inner wrapper's returned literal rebinds the
|
|
254
|
+
* parameter to a body that spreads that same parameter, so the merge never
|
|
255
|
+
* terminates. Binding it to the inner call's READING instead — the way the
|
|
256
|
+
* config merges a wrapper-built component it spreads — is not done here.
|
|
257
|
+
*/
|
|
258
|
+
function argumentBinding(argument) {
|
|
259
|
+
const expression = unwrapExpression(argument);
|
|
260
|
+
const literal = resolveObjectLiteral(expression);
|
|
261
|
+
if (literal)
|
|
262
|
+
return { literal };
|
|
263
|
+
const value = resolveLiteralValue(expression);
|
|
264
|
+
if (value !== undefined)
|
|
265
|
+
return { value };
|
|
266
|
+
if (expression.isKind(SyntaxKind.CallExpression)) {
|
|
267
|
+
refuse(`the call passes another call's result, ${excerpt(expression.getText())}, which this reader would have to run to know`);
|
|
268
|
+
}
|
|
269
|
+
return refuse(`the call passes ${excerpt(expression.getText())}, which is neither a value written out in the source nor a name for one`);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The function's parameters, bound to what the call passes for each.
|
|
273
|
+
*
|
|
274
|
+
* An argument the call omits binds undefined, which is a fact rather than a
|
|
275
|
+
* guess — and the shape a field builder's plain call takes, with nothing
|
|
276
|
+
* passed: `{ ...overrides }` spreads nothing. A key read off the omitted
|
|
277
|
+
* argument is another matter: `overrides?.max` is undefined at runtime, while
|
|
278
|
+
* `overrides.max` throws before the builder returns, and this reader tells
|
|
279
|
+
* neither apart from a value it cannot see — the key is left unread and
|
|
280
|
+
* admitted. A parameter carrying a DEFAULT is the opposite of an omitted
|
|
281
|
+
* one, the default being an expression this reader would have to evaluate to
|
|
282
|
+
* know what was bound, so it is refused with every other shape whose bound
|
|
283
|
+
* value cannot be seen.
|
|
284
|
+
*/
|
|
285
|
+
function bindArguments(parameters, args) {
|
|
286
|
+
if (args.length > parameters.length) {
|
|
287
|
+
refuse(`the function takes ${parameters.length} parameters but the call passes ${args.length}`);
|
|
288
|
+
}
|
|
289
|
+
const environment = new Map();
|
|
290
|
+
parameters.forEach((declaration, index) => {
|
|
291
|
+
const argument = args[index];
|
|
292
|
+
if (!argument && declaration.hasInitializer()) {
|
|
293
|
+
refuse('the call leaves out an argument whose parameter has a default value, which this reader would have to run code to work out');
|
|
294
|
+
}
|
|
295
|
+
environment.set(declaration.getName(), { declaration, ...(argument ?? {}) });
|
|
296
|
+
});
|
|
297
|
+
return environment;
|
|
298
|
+
}
|
|
299
|
+
/** The declaration a callee identifier names, refusing anything that is not a function written down as a const. */
|
|
300
|
+
function calleeDeclaration(call) {
|
|
301
|
+
const identifier = unwrapExpression(call.getExpression()).asKind(SyntaxKind.Identifier);
|
|
302
|
+
if (!identifier)
|
|
303
|
+
refuse('the call is not to a function named directly, so which function runs cannot be read');
|
|
304
|
+
let symbol = identifier.getSymbol();
|
|
305
|
+
// An overloaded wrapper declares its signatures first and its body last, and
|
|
306
|
+
// a signature says nothing at all about what the call returns.
|
|
307
|
+
let signatureOnly;
|
|
308
|
+
for (let hop = 0; symbol && hop < MAX_ALIAS_HOPS; hop++) {
|
|
309
|
+
for (const declaration of symbol.getDeclarations()) {
|
|
310
|
+
if (Node.isFunctionDeclaration(declaration)) {
|
|
311
|
+
if (declaration.getBody())
|
|
312
|
+
return declaration;
|
|
313
|
+
signatureOnly ??= declaration;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (!Node.isVariableDeclaration(declaration))
|
|
317
|
+
continue;
|
|
318
|
+
// Only `const` is trusted, for the reason `resolve-reference` trusts only
|
|
319
|
+
// `const`: a let or var holds whatever was assigned to it last, which is
|
|
320
|
+
// code this reader never sees.
|
|
321
|
+
if (declaration.getVariableStatement()?.getDeclarationKind() !== VariableDeclarationKind.Const) {
|
|
322
|
+
refuse(DECLARED_WITH_LET_OR_VAR);
|
|
323
|
+
}
|
|
324
|
+
const initializer = declaration.getInitializer();
|
|
325
|
+
const written = initializer && unwrapExpression(initializer);
|
|
326
|
+
if (written && (Node.isArrowFunction(written) || Node.isFunctionExpression(written)))
|
|
327
|
+
return written;
|
|
328
|
+
}
|
|
329
|
+
symbol = symbol.getAliasedSymbol();
|
|
330
|
+
}
|
|
331
|
+
if (signatureOnly)
|
|
332
|
+
return signatureOnly;
|
|
333
|
+
return refuse('the function called is not declared anywhere this reader can see');
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The single object literal the callee's body returns — `what` naming the thing
|
|
337
|
+
* the call was read for, so a refusal says what the caller did not get.
|
|
338
|
+
*
|
|
339
|
+
* Exactly one statement, exactly one return: a body doing anything else is
|
|
340
|
+
* computing part of its answer, and the part this reader can see would be
|
|
341
|
+
* reported as the whole.
|
|
342
|
+
*/
|
|
343
|
+
function returnedLiteral(fn, environment, what) {
|
|
344
|
+
// An async or generator callee hands back a promise or an iterator. Whatever
|
|
345
|
+
// its body returns, the value the config binds is not the thing being read.
|
|
346
|
+
if (fn.isAsync())
|
|
347
|
+
refuse(`the function is async, so the call returns a promise rather than a ${what}`);
|
|
348
|
+
if (!Node.isArrowFunction(fn) && fn.isGenerator()) {
|
|
349
|
+
refuse(`the function is a generator, so the call returns an iterator rather than a ${what}`);
|
|
350
|
+
}
|
|
351
|
+
const body = fn.getBody();
|
|
352
|
+
if (!body)
|
|
353
|
+
refuse('the function has no body to read');
|
|
354
|
+
// Concise arrow: `config => ({ … })`, or `config => config`, where the return
|
|
355
|
+
// is the body itself.
|
|
356
|
+
const concise = asObjectLiteral(body);
|
|
357
|
+
if (concise)
|
|
358
|
+
return concise;
|
|
359
|
+
if (!Node.isBlock(body))
|
|
360
|
+
return passthroughLiteral(body, environment);
|
|
361
|
+
const statements = body.getStatements();
|
|
362
|
+
if (statements.length !== 1)
|
|
363
|
+
refuse(`the function's body has ${statements.length} statements, and only a body that is a single return can be read without running it`);
|
|
364
|
+
const returned = statements[0]?.asKind(SyntaxKind.ReturnStatement);
|
|
365
|
+
if (!returned)
|
|
366
|
+
refuse("the only statement in the function's body is not a return");
|
|
367
|
+
const expression = returned.getExpression();
|
|
368
|
+
if (!expression)
|
|
369
|
+
refuse('the function returns nothing');
|
|
370
|
+
return asObjectLiteral(expression) ?? passthroughLiteral(expression, environment);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* `return config;` — a wrapper that only registers or annotates its argument,
|
|
374
|
+
* which reads as the argument itself. Written in both shapes a body can take,
|
|
375
|
+
* so `(config) => config` is the same wrapper as its block-bodied twin.
|
|
376
|
+
*/
|
|
377
|
+
function passthroughLiteral(expression, environment) {
|
|
378
|
+
const identifier = unwrapExpression(expression).asKind(SyntaxKind.Identifier);
|
|
379
|
+
const bound = identifier && boundLiteral(identifier, environment);
|
|
380
|
+
if (bound)
|
|
381
|
+
return bound;
|
|
382
|
+
return refuse('the function returns something other than an object written out in its body or the argument it was passed');
|
|
383
|
+
}
|
|
384
|
+
/** The parameters the callee binds, refusing every shape whose runtime value is not the argument itself. */
|
|
385
|
+
function calleeParameters(fn) {
|
|
386
|
+
const parameters = fn.getParameters();
|
|
387
|
+
for (const parameter of parameters) {
|
|
388
|
+
// `function w(...config)` binds an ARRAY of the arguments, and
|
|
389
|
+
// `(config, extra)` with a rest tail swallows the remainder into one. The
|
|
390
|
+
// shape the body then spreads is not the shape this reader would
|
|
391
|
+
// substitute, and the count check would not catch the difference.
|
|
392
|
+
if (parameter.isRestParameter()) {
|
|
393
|
+
refuse('the function takes a rest parameter, which gathers the arguments into an array rather than binding each one');
|
|
394
|
+
}
|
|
395
|
+
// `function withPick({ label, fields })` binds names this reader would have
|
|
396
|
+
// to model a destructuring for; the argument's own keys are not what the
|
|
397
|
+
// body reads.
|
|
398
|
+
if (!Node.isIdentifier(parameter.getNameNode()))
|
|
399
|
+
refuse('a parameter of the function is destructured, which this reader does not follow');
|
|
400
|
+
}
|
|
401
|
+
return parameters;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* The binding a name stands for in THIS call, and nothing else.
|
|
405
|
+
*
|
|
406
|
+
* The symbol check is the whole point. An identifier that merely shares a name
|
|
407
|
+
* with a parameter — a module-level `const config` in the file a spread leads
|
|
408
|
+
* into — resolves to its own declaration, because handing it the wrapper's
|
|
409
|
+
* argument invents a field set out of the argument's own top-level keys.
|
|
410
|
+
*/
|
|
411
|
+
function boundBinding(identifier, environment) {
|
|
412
|
+
const binding = environment.get(identifier.getText());
|
|
413
|
+
if (!binding)
|
|
414
|
+
return undefined;
|
|
415
|
+
// The name of a shorthand — `{ label }` — is a property as far as the
|
|
416
|
+
// checker is concerned; the value it stands for is a symbol of its own.
|
|
417
|
+
const shorthand = identifier.getParentIfKind(SyntaxKind.ShorthandPropertyAssignment);
|
|
418
|
+
const symbol = shorthand?.getNameNode() === identifier ? shorthand.getValueSymbol() : identifier.getSymbol();
|
|
419
|
+
return symbol?.getDeclarations().includes(binding.declaration) ? binding : undefined;
|
|
420
|
+
}
|
|
421
|
+
/** The literal bound to a parameter of this call, where the argument named one. */
|
|
422
|
+
function boundLiteral(identifier, environment) {
|
|
423
|
+
return boundBinding(identifier, environment)?.literal;
|
|
424
|
+
}
|
|
425
|
+
function readLiteral(literal, environment, depth, spreads) {
|
|
426
|
+
if (depth > MAX_SPREAD_DEPTH)
|
|
427
|
+
capped('a chain of component spreads');
|
|
428
|
+
const component = { fields: {} };
|
|
429
|
+
const written = new Set();
|
|
430
|
+
for (const property of literal.getProperties()) {
|
|
431
|
+
spendWork();
|
|
432
|
+
const spread = property.asKind(SyntaxKind.SpreadAssignment);
|
|
433
|
+
if (spread) {
|
|
434
|
+
const source = resolveInEnv(spread.getExpression(), environment);
|
|
435
|
+
const base = source ? readLiteral(source, environment, depth + 1, spreads) : spreadReading(spread, spreads);
|
|
436
|
+
applyComponentReading(component, base);
|
|
437
|
+
for (const key of base.written)
|
|
438
|
+
written.add(key);
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const member = namedMember(property);
|
|
442
|
+
if (!member)
|
|
443
|
+
continue;
|
|
444
|
+
const name = propertyKey(member);
|
|
445
|
+
if (name === undefined) {
|
|
446
|
+
// A computed key — `[k]: value` — writes a name this reader cannot read,
|
|
447
|
+
// and it may be any key read here. Leaving the earlier readings standing
|
|
448
|
+
// would report a label or a field set the runtime has already
|
|
449
|
+
// overwritten, or behaviour it has written or erased, so every one goes
|
|
450
|
+
// and each is admitted.
|
|
451
|
+
for (const key of DATA_KEYS) {
|
|
452
|
+
clearComponentMember(component, key);
|
|
453
|
+
written.add(key);
|
|
454
|
+
}
|
|
455
|
+
for (const [key, marker] of BEHAVIOUR_MARKERS) {
|
|
456
|
+
delete component[marker];
|
|
457
|
+
admitKey(component, key, true);
|
|
458
|
+
written.add(key);
|
|
459
|
+
}
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
// Puck reads `fields`, `label` and every behaviour key through the
|
|
463
|
+
// prototype, and nothing a prototype carries is written here to be read.
|
|
464
|
+
if (setsPrototype(member))
|
|
465
|
+
refuse('the component sets its prototype with __proto__, so what it inherits cannot be read');
|
|
466
|
+
const marker = BEHAVIOUR_MARKERS.get(name);
|
|
467
|
+
if (marker) {
|
|
468
|
+
// The last write decides, as for every key: `undefined` or `null`
|
|
469
|
+
// written after a spread leaves Puck nothing to run, and anything else —
|
|
470
|
+
// a write this reader cannot see through included — may be code. Either
|
|
471
|
+
// way the key is spelled out, which settles an earlier admission.
|
|
472
|
+
written.add(name);
|
|
473
|
+
if (writesNothing(member))
|
|
474
|
+
delete component[marker];
|
|
475
|
+
else
|
|
476
|
+
component[marker] = true;
|
|
477
|
+
admitKey(component, name, false);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (!DATA_KEYS.has(name))
|
|
481
|
+
continue;
|
|
482
|
+
written.add(name);
|
|
483
|
+
// A shorthand names its value and is followed like the name written out.
|
|
484
|
+
// A method or a getter carries no value this reader can take — and at
|
|
485
|
+
// runtime it still overwrites whatever a spread above it put there, so the
|
|
486
|
+
// earlier reading has to go with it.
|
|
487
|
+
const value = writtenValue(member);
|
|
488
|
+
if (value)
|
|
489
|
+
readComponentMember(component, name, value, environment);
|
|
490
|
+
else
|
|
491
|
+
clearComponentMember(component, name);
|
|
492
|
+
}
|
|
493
|
+
return { component, written };
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* `resolveData: undefined`, `resolveFields: void 0`, `{ resolvePermissions }`
|
|
497
|
+
* beside a `const` bound to `null` — a behaviour key that provably holds no
|
|
498
|
+
* function, and so marks nothing. A getter or method stays marked: its body is
|
|
499
|
+
* never run, so what it returns is not known.
|
|
500
|
+
*/
|
|
501
|
+
function writesNothing(member) {
|
|
502
|
+
const value = writtenValue(member);
|
|
503
|
+
return value !== undefined && holdsNothing(value);
|
|
504
|
+
}
|
|
505
|
+
/** The reading a spread source amounts to when it is no literal this walker can reach. */
|
|
506
|
+
function spreadReading(spread, spreads) {
|
|
507
|
+
const { reading, reason } = spreads?.(spread.getExpression()) ?? {};
|
|
508
|
+
if (reading)
|
|
509
|
+
return reading;
|
|
510
|
+
return refuse(reason ??
|
|
511
|
+
`the component spreads ${excerpt(spread.getText())}, which this reader cannot follow to an object written in the source`);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Applies one reading over another at the position its spread sits — the
|
|
515
|
+
* runtime's own rule, every key the source writes winning over what was read
|
|
516
|
+
* above it, together with the admission the source made for it. A behaviour
|
|
517
|
+
* key follows the same rule: the source's write of it decides whether there is
|
|
518
|
+
* code for Puck to run.
|
|
519
|
+
*/
|
|
520
|
+
function applyComponentReading(component, base) {
|
|
521
|
+
for (const name of base.written) {
|
|
522
|
+
const marker = BEHAVIOUR_MARKERS.get(name);
|
|
523
|
+
if (marker) {
|
|
524
|
+
if (base.component[marker])
|
|
525
|
+
component[marker] = true;
|
|
526
|
+
else
|
|
527
|
+
delete component[marker];
|
|
528
|
+
admitKey(component, name, isAdmitted(base.component, name));
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (name === 'fields') {
|
|
532
|
+
component.fields = base.component.fields;
|
|
533
|
+
if (base.component.fieldsUnreadable)
|
|
534
|
+
component.fieldsUnreadable = true;
|
|
535
|
+
else
|
|
536
|
+
delete component.fieldsUnreadable;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (isValueKey(name)) {
|
|
540
|
+
carryKey(component, base.component, name);
|
|
541
|
+
admitKey(component, name, isAdmitted(base.component, name));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
/** The keys `unreadableKeys` can name, in the order it lists them. */
|
|
546
|
+
const ADMITTABLE_KEYS = [
|
|
547
|
+
'label',
|
|
548
|
+
'defaultProps',
|
|
549
|
+
'ai',
|
|
550
|
+
'resolveFields',
|
|
551
|
+
'resolveData',
|
|
552
|
+
'resolvePermissions',
|
|
553
|
+
];
|
|
554
|
+
/** Whether a reading lists a key in `unreadableKeys`. */
|
|
555
|
+
function isAdmitted(component, key) {
|
|
556
|
+
return component.unreadableKeys?.some((admitted) => admitted === key) ?? false;
|
|
557
|
+
}
|
|
558
|
+
function isValueKey(name) {
|
|
559
|
+
return name === 'label' || name === 'defaultProps' || name === 'ai';
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Records whether a key's last write went unread. The admission follows the
|
|
563
|
+
* value's own rule — a later readable write settles it, a later unreadable one
|
|
564
|
+
* raises it again — and the list goes with its last entry, so a component read
|
|
565
|
+
* whole carries no empty `unreadableKeys`.
|
|
566
|
+
*/
|
|
567
|
+
function admitKey(component, key, unread) {
|
|
568
|
+
const keys = new Set(component.unreadableKeys);
|
|
569
|
+
if (unread)
|
|
570
|
+
keys.add(key);
|
|
571
|
+
else
|
|
572
|
+
keys.delete(key);
|
|
573
|
+
const listed = ADMITTABLE_KEYS.filter((admitted) => keys.has(admitted));
|
|
574
|
+
if (listed.length > 0)
|
|
575
|
+
component.unreadableKeys = listed;
|
|
576
|
+
else
|
|
577
|
+
delete component.unreadableKeys;
|
|
578
|
+
}
|
|
579
|
+
/** One `label` / `fields` / `defaultProps` / `ai` entry of a component, read with the call's parameters in scope. */
|
|
580
|
+
function readComponentMember(component, name, initializer, environment) {
|
|
581
|
+
switch (name) {
|
|
582
|
+
case 'label': {
|
|
583
|
+
// `label: SHARED_LABEL` is the sidebar name written one line up rather
|
|
584
|
+
// than in place; a reader that stops at the name leaves the component
|
|
585
|
+
// nameless in the manifest.
|
|
586
|
+
// The argument first: `config.label` names what the call passed, and a
|
|
587
|
+
// name typed after another const must not be read as that const.
|
|
588
|
+
const value = boundValue(initializer, environment) ?? resolveLiteralValue(initializer);
|
|
589
|
+
if (typeof value === 'string') {
|
|
590
|
+
component.label = value;
|
|
591
|
+
admitKey(component, name, false);
|
|
592
|
+
}
|
|
593
|
+
else
|
|
594
|
+
clearComponentMember(component, name);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
case 'fields': {
|
|
598
|
+
// A wrapper that maps over the field set — `Object.fromEntries(…)` — is
|
|
599
|
+
// still worth reading for everything else it says, so this is an
|
|
600
|
+
// admission rather than a refusal.
|
|
601
|
+
const set = readFieldSet(initializer, 0, boundSources(environment));
|
|
602
|
+
if (!set)
|
|
603
|
+
clearComponentMember(component, name);
|
|
604
|
+
else {
|
|
605
|
+
component.fields = set.fields;
|
|
606
|
+
if (set.unreadable)
|
|
607
|
+
component.fieldsUnreadable = true;
|
|
608
|
+
else
|
|
609
|
+
delete component.fieldsUnreadable;
|
|
610
|
+
}
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
case 'defaultProps':
|
|
614
|
+
case 'ai': {
|
|
615
|
+
// Read with the argument in scope: `ai: { hint: config.label }` reads the
|
|
616
|
+
// label the argument declares, or admits it is unknown — never empty as
|
|
617
|
+
// fact. What did read is kept, and the admission says it is not the
|
|
618
|
+
// whole of it. A reading with a gap and nothing else is no reading: an
|
|
619
|
+
// empty object beside the admission would pass for one written empty.
|
|
620
|
+
const reading = readValueObject(initializer, environment);
|
|
621
|
+
if (!reading || (reading.dropped && Object.keys(reading.value).length === 0)) {
|
|
622
|
+
clearComponentMember(component, name);
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
if (name === 'ai')
|
|
626
|
+
component.ai = reading.value;
|
|
627
|
+
else
|
|
628
|
+
component.defaultProps = reading.value;
|
|
629
|
+
admitKey(component, name, reading.dropped);
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* A write this reader cannot see through. The last write wins at runtime, so
|
|
637
|
+
* whatever a spread put there earlier has to go with it rather than stand as a
|
|
638
|
+
* stale value — `{ ...config, label: makeLabel() }` is not the argument's label
|
|
639
|
+
* — and the key is admitted, so its absence is not read as "none".
|
|
640
|
+
*/
|
|
641
|
+
function clearComponentMember(component, name) {
|
|
642
|
+
if (name === 'fields') {
|
|
643
|
+
component.fields = {};
|
|
644
|
+
component.fieldsUnreadable = true;
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (!isValueKey(name))
|
|
648
|
+
return;
|
|
649
|
+
delete component[name];
|
|
650
|
+
admitKey(component, name, true);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* The literal a field builder returns, read as a field with the call's
|
|
654
|
+
* arguments in scope.
|
|
655
|
+
*
|
|
656
|
+
* `readField` walks the literal in source order and follows a name to the
|
|
657
|
+
* `const` it stands for; what it cannot see on its own is the CALL — a
|
|
658
|
+
* parameter is bound by the caller rather than written down, so `label: label`
|
|
659
|
+
* and `{ ...overrides }` mean nothing to it. Both are handed over here, and a
|
|
660
|
+
* spread of an argument then merges where it is written, exactly as at runtime:
|
|
661
|
+
* reporting `max: 4` where `ctaButtonArrayField({ max: 2 })` overrides it is
|
|
662
|
+
* the confident wrong answer this module exists to avoid.
|
|
663
|
+
*
|
|
664
|
+
* A spread that leads nowhere at all — anywhere in the field, nested field sets
|
|
665
|
+
* included — is still refused rather than admitted. The caller of a builder has
|
|
666
|
+
* a reason to hand back, and "could not read, because X" beats a field claiming
|
|
667
|
+
* bounds that something invisible may have replaced.
|
|
668
|
+
*/
|
|
669
|
+
function readFieldWithEnv(literal, environment, depth) {
|
|
670
|
+
return readField(literal, depth, boundSources(environment, (expression) => refuse(`the field spreads ${excerpt(expression.getText())}, which this reader cannot follow and which may overwrite what is beside it`)));
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Where spreads and names lead with a call's parameters in scope: `...config`
|
|
674
|
+
* reaches the argument, `config.fields` the key it declares, and `...config.x`
|
|
675
|
+
* where the argument provably declares no `x` spreads nothing. A spread that
|
|
676
|
+
* leads nowhere is handed to `lost`, whose undefined the field and field-set
|
|
677
|
+
* readers admit — unless the caller would rather refuse.
|
|
678
|
+
*/
|
|
679
|
+
function boundSources(environment, lost = () => undefined) {
|
|
680
|
+
return {
|
|
681
|
+
builder: readFieldBuilderCall,
|
|
682
|
+
spread: (expression) => spreadsNothing(expression, environment)
|
|
683
|
+
? SPREADS_NOTHING
|
|
684
|
+
: (resolveInEnv(expression, environment) ?? lost(expression)),
|
|
685
|
+
bound: (node) => boundValue(node, environment),
|
|
686
|
+
object: (expression) => resolveInEnv(expression, environment),
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* A value the call binds: a parameter named directly (`label: label`) or a key
|
|
691
|
+
* read out of one (`opts.label`), a name the argument writes for it followed to
|
|
692
|
+
* its `const`. Undefined for anything that does not start at a parameter of
|
|
693
|
+
* this call: a module const is the source's own, and read as such.
|
|
694
|
+
*/
|
|
695
|
+
function boundValue(node, environment) {
|
|
696
|
+
const expression = unwrapExpression(node);
|
|
697
|
+
const identifier = expression.asKind(SyntaxKind.Identifier);
|
|
698
|
+
if (identifier)
|
|
699
|
+
return boundBinding(identifier, environment)?.value;
|
|
700
|
+
if (!Node.isPropertyAccessExpression(expression) || !startsAtParameter(expression, environment))
|
|
701
|
+
return undefined;
|
|
702
|
+
const target = resolveInEnv(expression.getExpression(), environment);
|
|
703
|
+
const found = target && lookUpInEnv(target, expression.getName(), environment);
|
|
704
|
+
return found && typeof found !== 'string' ? resolveLiteralValue(found) : undefined;
|
|
705
|
+
}
|
|
706
|
+
/** Whether a chain of key reads — `opts.a.b` — starts at a parameter this call binds. */
|
|
707
|
+
function startsAtParameter(expression, environment) {
|
|
708
|
+
let root = unwrapExpression(expression);
|
|
709
|
+
while (Node.isPropertyAccessExpression(root))
|
|
710
|
+
root = unwrapExpression(root.getExpression());
|
|
711
|
+
const identifier = root.asKind(SyntaxKind.Identifier);
|
|
712
|
+
return identifier !== undefined && boundBinding(identifier, environment) !== undefined;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Whether a spread provably carries nothing: the call omitted the argument it
|
|
716
|
+
* spreads, or it reaches a key the bound argument was shown not to declare.
|
|
717
|
+
*/
|
|
718
|
+
function spreadsNothing(node, environment) {
|
|
719
|
+
const identifier = unwrapExpression(node).asKind(SyntaxKind.Identifier);
|
|
720
|
+
if (identifier) {
|
|
721
|
+
const binding = boundBinding(identifier, environment);
|
|
722
|
+
return binding !== undefined && binding.literal === undefined && binding.value === undefined;
|
|
723
|
+
}
|
|
724
|
+
return isAbsentKeyAccess(node, environment);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* `defaultProps` and `ai`, and the plain objects inside them: read in source
|
|
728
|
+
* order with spreads resolved against the call's parameters, so `{
|
|
729
|
+
* ...config.defaultProps, layout: … }` means what it means at runtime.
|
|
730
|
+
*
|
|
731
|
+
* Never all-or-nothing. An entry whose value cannot be read is left out; a
|
|
732
|
+
* spread leading nowhere, or a key this reader cannot name, takes the entries
|
|
733
|
+
* before it; `__proto__` hides what the object inherits. Each marks the
|
|
734
|
+
* reading `dropped`, so the owner admits it instead of presenting the rest as
|
|
735
|
+
* the whole. Undefined only where the object itself cannot be reached.
|
|
736
|
+
*/
|
|
737
|
+
function readValueObject(node, environment, depth = 0) {
|
|
738
|
+
if (depth > MAX_SPREAD_DEPTH)
|
|
739
|
+
capped('a chain of spreads in defaultProps or ai');
|
|
740
|
+
const literal = resolveInEnv(node, environment);
|
|
741
|
+
if (!literal)
|
|
742
|
+
return undefined;
|
|
743
|
+
const walk = { value: {}, dropped: false, written: new Set(), lost: false };
|
|
744
|
+
for (const property of literal.getProperties()) {
|
|
745
|
+
spendWork();
|
|
746
|
+
const spread = property.asKind(SyntaxKind.SpreadAssignment);
|
|
747
|
+
if (spread) {
|
|
748
|
+
// `{ ...config.defaultProps }` where the argument declares none is an
|
|
749
|
+
// empty spread at runtime, not a value this reader failed to follow.
|
|
750
|
+
if (spreadsNothing(spread.getExpression(), environment))
|
|
751
|
+
continue;
|
|
752
|
+
const base = readValueObject(spread.getExpression(), environment, depth + 1);
|
|
753
|
+
if (base)
|
|
754
|
+
applyValueWalk(walk, base);
|
|
755
|
+
else
|
|
756
|
+
loseEveryKey(walk);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const member = namedMember(property);
|
|
760
|
+
const key = member && propertyKey(member);
|
|
761
|
+
if (!member || key === undefined) {
|
|
762
|
+
loseEveryKey(walk);
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
// Never written into a record of ours — assigning it replaces the record's
|
|
766
|
+
// prototype — and, written as one, it hides every key the object inherits.
|
|
767
|
+
if (key === '__proto__') {
|
|
768
|
+
walk.dropped = true;
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
walk.written.add(key);
|
|
772
|
+
const initializer = writtenValue(member);
|
|
773
|
+
const value = initializer && readValueEntry(initializer, environment, depth, walk);
|
|
774
|
+
if (value === undefined) {
|
|
775
|
+
// The last write wins at runtime, so a key set in a shape this reader
|
|
776
|
+
// cannot read takes the earlier value with it.
|
|
777
|
+
delete walk.value[key];
|
|
778
|
+
walk.dropped = true;
|
|
779
|
+
}
|
|
780
|
+
else
|
|
781
|
+
walk.value[key] = value;
|
|
782
|
+
}
|
|
783
|
+
return walk;
|
|
784
|
+
}
|
|
785
|
+
/** One entry of a plain-data object, dropped marks carried up to the object holding it. */
|
|
786
|
+
function readValueEntry(node, environment, depth, walk) {
|
|
787
|
+
const expression = unwrapExpression(node);
|
|
788
|
+
const array = expression.asKind(SyntaxKind.ArrayLiteralExpression);
|
|
789
|
+
if (array) {
|
|
790
|
+
const values = [];
|
|
791
|
+
for (const element of array.getElements()) {
|
|
792
|
+
spendWork();
|
|
793
|
+
// A missing element would shift every later index, so the whole array
|
|
794
|
+
// is unknown rather than partially wrong.
|
|
795
|
+
const value = readValueEntry(element, environment, depth, walk);
|
|
796
|
+
if (value === undefined)
|
|
797
|
+
return undefined;
|
|
798
|
+
values.push(value);
|
|
799
|
+
}
|
|
800
|
+
return values;
|
|
801
|
+
}
|
|
802
|
+
const object = resolveInEnv(expression, environment);
|
|
803
|
+
if (object) {
|
|
804
|
+
// A literal written inside this one walks strictly downward and cannot
|
|
805
|
+
// cycle, so it costs no depth — but it carries the count, because a cycle
|
|
806
|
+
// reached through it would otherwise start over on every lap. A name for
|
|
807
|
+
// one may lead back, and costs a level.
|
|
808
|
+
const nested = readValueObject(object, environment, asObjectLiteral(expression) ? depth : depth + 1);
|
|
809
|
+
if (nested?.dropped)
|
|
810
|
+
walk.dropped = true;
|
|
811
|
+
return nested?.value;
|
|
812
|
+
}
|
|
813
|
+
const bound = boundValue(expression, environment);
|
|
814
|
+
if (bound !== undefined)
|
|
815
|
+
return bound;
|
|
816
|
+
// `items: ITEMS` names an array whose parts may be computed — an item's `id:
|
|
817
|
+
// defaultId()` — and the part that read is kept and admitted, exactly as the
|
|
818
|
+
// same array written in place is.
|
|
819
|
+
const reading = resolveLiteralValueReading(expression);
|
|
820
|
+
if (reading?.dropped)
|
|
821
|
+
walk.dropped = true;
|
|
822
|
+
return reading?.value;
|
|
823
|
+
}
|
|
824
|
+
/** Applies a spread source's reading at the position the spread sits, as `applyComponentReading` does for components. */
|
|
825
|
+
function applyValueWalk(walk, base) {
|
|
826
|
+
if (base.lost) {
|
|
827
|
+
walk.value = {};
|
|
828
|
+
walk.lost = true;
|
|
829
|
+
}
|
|
830
|
+
for (const key of base.written) {
|
|
831
|
+
walk.written.add(key);
|
|
832
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: astro-cms compiles against ES2020, where Object.hasOwn does not exist
|
|
833
|
+
if (Object.prototype.hasOwnProperty.call(base.value, key))
|
|
834
|
+
walk.value[key] = base.value[key];
|
|
835
|
+
else
|
|
836
|
+
delete walk.value[key];
|
|
837
|
+
}
|
|
838
|
+
if (base.dropped)
|
|
839
|
+
walk.dropped = true;
|
|
840
|
+
}
|
|
841
|
+
/** A write this reader cannot name, which may be any key — so every one read before it goes. */
|
|
842
|
+
function loseEveryKey(walk) {
|
|
843
|
+
walk.value = {};
|
|
844
|
+
walk.lost = true;
|
|
845
|
+
walk.dropped = true;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* The object literal an expression names, with the wrapper's parameters and
|
|
849
|
+
* their subobjects in scope: `config`, `config.fields`, `config.defaultProps`.
|
|
850
|
+
*/
|
|
851
|
+
function resolveInEnv(node, environment, depth = 0) {
|
|
852
|
+
if (depth > MAX_SPREAD_DEPTH)
|
|
853
|
+
capped('a chain of property reads like `a.b.c`');
|
|
854
|
+
const expression = unwrapExpression(node);
|
|
855
|
+
const identifier = expression.asKind(SyntaxKind.Identifier);
|
|
856
|
+
if (identifier)
|
|
857
|
+
return boundLiteral(identifier, environment) ?? resolveObjectLiteral(expression);
|
|
858
|
+
if (Node.isPropertyAccessExpression(expression)) {
|
|
859
|
+
const target = resolveInEnv(expression.getExpression(), environment, depth + 1);
|
|
860
|
+
if (!target)
|
|
861
|
+
return undefined;
|
|
862
|
+
const found = lookUpInEnv(target, expression.getName(), environment);
|
|
863
|
+
return typeof found === 'string' ? undefined : resolveObjectLiteral(found);
|
|
864
|
+
}
|
|
865
|
+
return resolveObjectLiteral(expression);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* What an object literal assigns to one key — `lookUpKey`'s rules, with its
|
|
869
|
+
* spreads reaching what this call binds. A key an argument inherits through a
|
|
870
|
+
* spread is a key it has; one a getter, a computed name it cannot resolve, or
|
|
871
|
+
* a prototype may supply is unknown rather than absent.
|
|
872
|
+
*/
|
|
873
|
+
function lookUpInEnv(literal, name, environment) {
|
|
874
|
+
return lookUpKey(literal, name, (expression) => resolveInEnv(expression, environment));
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Whether a member access reaches a key the object was shown not to declare —
|
|
878
|
+
* the one case `{ ...config.defaultProps }` may be read as an empty spread.
|
|
879
|
+
* Anything less certain answers false: a spread this reader could not open may
|
|
880
|
+
* well declare the key.
|
|
881
|
+
*/
|
|
882
|
+
function isAbsentKeyAccess(node, environment) {
|
|
883
|
+
const expression = unwrapExpression(node);
|
|
884
|
+
if (!Node.isPropertyAccessExpression(expression))
|
|
885
|
+
return false;
|
|
886
|
+
const target = resolveInEnv(expression.getExpression(), environment);
|
|
887
|
+
return target !== undefined && lookUpInEnv(target, expression.getName(), environment) === 'absent';
|
|
888
|
+
}
|
|
889
|
+
//# sourceMappingURL=read-wrapper.js.map
|