@conloca/astro-cms 0.1.15 → 0.2.0
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 +259 -247
- 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/ts/src/cms-handler.d.ts +18 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/ts/src/cms-handler.js +245 -0
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +160 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +170 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.js +22 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
- 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/ts/src/components/RenderWithHydration.d.ts +21 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.js +39 -0
- 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 +18 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js +25 -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 +41 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js +232 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/ts/src/discovery/merge-registry.js +333 -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/ts/src/discovery/scan-components.d.ts +94 -0
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-components.js +397 -0
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.js +113 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.js +34 -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 +4 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/ts/src/hydration.js +5 -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 +11 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +41 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.js +136 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-script.js +89 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-utils.js +84 -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/ts/src/lib/route-utils.d.ts +61 -0
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/route-utils.js +96 -0
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/ts/src/lib/routing-config.d.ts +38 -0
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/ts/src/lib/routing-config.js +106 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts +6 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/ts/src/lib/serialize-props.js +8 -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/ts/src/lib/virtual-module-generators.d.ts +33 -0
- 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/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/ts/src/lib/withHydration.js +50 -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/ts/src/loader.js +118 -0
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts +61 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/ts/src/locales-helpers.js +50 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts +3 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/ts/src/mime-types.js +20 -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 +8 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/ts/src/path-validation.js +13 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/ts/src/plugin-spa.d.ts +182 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/ts/src/plugin-spa.js +1165 -0
- 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 +13 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/ts/src/safe-json-stringify.js +7 -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/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js +264 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
- 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 +15 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +67 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/ts/src/types.d.ts +543 -0
- 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 +74 -0
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +198 -56
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +10 -0
- package/src/cms-handler.ts +280 -0
- package/src/collections.ts +262 -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 +48 -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/src/lib/withHydration.ts +71 -0
- package/src/loader.ts +145 -0
- package/src/locales-helpers.ts +68 -0
- 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 +1480 -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 +84 -0
- package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections.d.mts +0 -36
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -65
- package/dist/collections.mjs.map +0 -1
- package/dist/components.d.mts +0 -46
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -226
- package/dist/components.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -3
- package/dist/index.d.mts +0 -139
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -66
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -26
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -267
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -85
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -19
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.mjs +0 -4
- package/dist/node/index.d.mts +0 -52
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.mjs +0 -753
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
- package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
- package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
- package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { type Node, type ObjectLiteralExpression, SyntaxKind, type ts } from 'ts-morph';
|
|
2
|
+
import { spendWork, withWorkBudget } from './reading-budget.js';
|
|
3
|
+
import {
|
|
4
|
+
holdsNothing,
|
|
5
|
+
inheritsNothing,
|
|
6
|
+
propertyKey,
|
|
7
|
+
resolveObjectLiteral,
|
|
8
|
+
resolveValueExpression,
|
|
9
|
+
setsPrototype,
|
|
10
|
+
} from './source-reference.js';
|
|
11
|
+
import { asObjectLiteral, literalPrimitive, namedMember, unwrapExpression, writtenValue } from './syntax.js';
|
|
12
|
+
import type { JsonValue } from './types.js';
|
|
13
|
+
|
|
14
|
+
// Keep the existing reader entry points; implementations import their owning layers directly.
|
|
15
|
+
export {
|
|
16
|
+
limitOutput,
|
|
17
|
+
MAX_OUTPUT,
|
|
18
|
+
MAX_OUTPUT_BYTES,
|
|
19
|
+
MAX_WORK,
|
|
20
|
+
OutputBudgetExceeded,
|
|
21
|
+
spendWork,
|
|
22
|
+
WorkBudgetExceeded,
|
|
23
|
+
} from './reading-budget.js';
|
|
24
|
+
export { expressionKey, holdsNothing, inheritsNothing, propertyKey, setsPrototype } from './source-reference.js';
|
|
25
|
+
export { asObjectLiteral, type NamedMember, namedMember, unwrapExpression, writtenValue } from './syntax.js';
|
|
26
|
+
|
|
27
|
+
/** Whether a reading left anything out. Set on the way down, never cleared. */
|
|
28
|
+
interface Drops {
|
|
29
|
+
dropped: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Reads a TypeScript expression as a JSON value, or `undefined` when it is
|
|
34
|
+
* computed rather than written down — in whole or in part.
|
|
35
|
+
*
|
|
36
|
+
* `undefined` is load-bearing: a config full of function calls must produce an
|
|
37
|
+
* absent value, never an invented one. Callers turn that absence into an
|
|
38
|
+
* explicit marker so the agent is told what is unknown instead of being handed
|
|
39
|
+
* a guess. A value with a part left out — `{ id: makeId(), label: 'x' }` — is
|
|
40
|
+
* no value here either, because handed on without that fact it passes for the
|
|
41
|
+
* whole; a caller that can admit the gap asks `literalValueReading` for the
|
|
42
|
+
* part that did read.
|
|
43
|
+
*/
|
|
44
|
+
export function literalValue(node: Node): JsonValue | undefined {
|
|
45
|
+
const reading = literalValueReading(node);
|
|
46
|
+
return reading && !reading.dropped ? reading.value : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A value read as plain data, and whether any part of it — at any depth — had to be left out. */
|
|
50
|
+
export interface ValueReading {
|
|
51
|
+
value: JsonValue;
|
|
52
|
+
dropped: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* `literalValue`, keeping the part that read when something had to be left
|
|
57
|
+
* out, and saying so. Every key the value holds is the runtime's own last
|
|
58
|
+
* write of it; `dropped` says the value may hold more than it shows.
|
|
59
|
+
*/
|
|
60
|
+
export function literalValueReading(node: Node): ValueReading | undefined {
|
|
61
|
+
const drops = { dropped: false };
|
|
62
|
+
const value = readValue(node, drops);
|
|
63
|
+
return value === undefined ? undefined : { value, dropped: drops.dropped };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readValue(node: Node, drops: Drops): JsonValue | undefined {
|
|
67
|
+
// `options: [...] as const` is how Puck's own docs write a field's legal
|
|
68
|
+
// values — reading through the wrapper is the difference between those
|
|
69
|
+
// values and silence.
|
|
70
|
+
const expression = unwrapExpression(node);
|
|
71
|
+
|
|
72
|
+
const primitive = literalPrimitive(expression);
|
|
73
|
+
if (primitive !== undefined) return primitive;
|
|
74
|
+
|
|
75
|
+
const array = expression.asKind(SyntaxKind.ArrayLiteralExpression);
|
|
76
|
+
if (array) {
|
|
77
|
+
const values: JsonValue[] = [];
|
|
78
|
+
for (const element of array.getElements()) {
|
|
79
|
+
// Each place an array is named reads it anew, so every item costs work.
|
|
80
|
+
spendWork();
|
|
81
|
+
const value = readValue(element, drops);
|
|
82
|
+
// A computed element would silently shift every later index, so the
|
|
83
|
+
// whole array is unknown rather than partially wrong.
|
|
84
|
+
if (value === undefined) return undefined;
|
|
85
|
+
values.push(value);
|
|
86
|
+
}
|
|
87
|
+
return values;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const object = expression.asKind(SyntaxKind.ObjectLiteralExpression);
|
|
91
|
+
if (object) return readObject(object, drops);
|
|
92
|
+
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Why a walk could not read the last write of a key. */
|
|
97
|
+
export type UnreadWrite =
|
|
98
|
+
/** The owner could not take the value written. */
|
|
99
|
+
| 'value'
|
|
100
|
+
/** A method or a getter writes the key with code this reader does not run. */
|
|
101
|
+
| 'code'
|
|
102
|
+
/** A setter writes it last: undefined on its own, and code beside a getter. */
|
|
103
|
+
| 'setter'
|
|
104
|
+
/**
|
|
105
|
+
* `['__proto__']` — an own key at runtime, but one no record of ours can
|
|
106
|
+
* hold, because assigning it replaces the record's prototype instead of
|
|
107
|
+
* adding a key.
|
|
108
|
+
*/
|
|
109
|
+
| 'reserved';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* One object literal walked in source order, by the runtime's own rules. The
|
|
113
|
+
* owner decides what a value is; the walk decides which write of a key is the
|
|
114
|
+
* last one, and what the owner could not see.
|
|
115
|
+
*/
|
|
116
|
+
export interface LiteralWalk<V> {
|
|
117
|
+
/** Every key whose last write the owner could read, with what it read, in the order the runtime keeps them. */
|
|
118
|
+
entries: Map<string, V>;
|
|
119
|
+
/** Keys whose last write could not be read, each with the reason. */
|
|
120
|
+
unread: Map<string, UnreadWrite>;
|
|
121
|
+
/** Keys written before a write the walk cannot name, which may have replaced them, that nothing later settled. */
|
|
122
|
+
cleared: Set<string>;
|
|
123
|
+
/** A write the walk cannot name — a computed key it cannot resolve, a spread it cannot follow — so the object may hold any key. */
|
|
124
|
+
lost: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* The member of this literal behind the last such write — the spread, or the
|
|
127
|
+
* member whose computed name could not be worked out — so a reason can point
|
|
128
|
+
* at it. A spread whose own walk lost something is named here too.
|
|
129
|
+
*/
|
|
130
|
+
lostAt?: Node;
|
|
131
|
+
/** `__proto__` hands the object a prototype, so a key it does not write itself may be inherited. */
|
|
132
|
+
inherits: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** A spread shown to carry nothing — `...null`, or `{ ...overrides }` where the call omitted `overrides`. */
|
|
136
|
+
export const SPREADS_NOTHING: unique symbol = Symbol('spreads nothing');
|
|
137
|
+
|
|
138
|
+
/** What an owner hands a walk: who it is, how to read one value, and where a spread leads. */
|
|
139
|
+
export interface LiteralWalkHooks<V> {
|
|
140
|
+
/**
|
|
141
|
+
* Names the owner. A walk is remembered per owner and literal for the length
|
|
142
|
+
* of one reading — unless it was cut short, see `walkLiteral` — so two owners
|
|
143
|
+
* that read the same literal differently never share an answer, which holds
|
|
144
|
+
* only while both hooks answer from the node they are handed and nothing else.
|
|
145
|
+
*/
|
|
146
|
+
kind: string;
|
|
147
|
+
/** What one member writes — the value of `key: value`, or the name a shorthand stands for — or undefined where the owner cannot take it. */
|
|
148
|
+
read(value: Node): V | undefined;
|
|
149
|
+
/** The literal a spread reaches, `SPREADS_NOTHING` where it provably carries none, or undefined where it cannot be followed. */
|
|
150
|
+
spread(expression: Node): ObjectLiteralExpression | typeof SPREADS_NOTHING | undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Whether a walk saw every write of its object: nothing unread, lost or inherited. */
|
|
154
|
+
export function walkIsWhole<V>(walk: LiteralWalk<V>): boolean {
|
|
155
|
+
return walk.unread.size === 0 && !walk.lost && !walk.inherits;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** How many characters of source a reason quotes before it cuts the quote short. */
|
|
159
|
+
const EXCERPT_LENGTH = 60;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Source text as a reason quotes it: on one line, cut short on a whole
|
|
163
|
+
* character — an emoji is two 16-bit string units, and cutting between them
|
|
164
|
+
* leaves half of one — and marked where it was cut. Text with nothing in it is
|
|
165
|
+
* named as such rather than quoted as a gap in the sentence.
|
|
166
|
+
*/
|
|
167
|
+
export function excerpt(text: string): string {
|
|
168
|
+
const oneLine = text.replace(/\s+/g, ' ').trim();
|
|
169
|
+
if (oneLine === '') return 'an empty expression';
|
|
170
|
+
let kept = '';
|
|
171
|
+
let count = 0;
|
|
172
|
+
for (const character of oneLine) {
|
|
173
|
+
if (count++ === EXCERPT_LENGTH) return `${kept}…`;
|
|
174
|
+
kept += character;
|
|
175
|
+
}
|
|
176
|
+
return kept;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* One `readPuckConfig` call from start to finish: the walks already made, and
|
|
181
|
+
* the work spent so far. Walks are remembered only here, because a project
|
|
182
|
+
* read again later may have changed underneath the answer.
|
|
183
|
+
*/
|
|
184
|
+
interface ReadingSession {
|
|
185
|
+
walks: Map<string, Map<ts.Node, LiteralWalk<unknown>>>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let session: ReadingSession | undefined;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Runs one reading of a config with its walks remembered and its work counted.
|
|
192
|
+
* A literal spread into ten objects is walked once rather than ten times, and
|
|
193
|
+
* a chain of such spreads costs its length rather than its width to the power
|
|
194
|
+
* of its depth.
|
|
195
|
+
*/
|
|
196
|
+
export function withReadingSession<T>(read: () => T): T {
|
|
197
|
+
if (session) return read();
|
|
198
|
+
session = { walks: new Map() };
|
|
199
|
+
try {
|
|
200
|
+
return withWorkBudget(read);
|
|
201
|
+
} finally {
|
|
202
|
+
session = undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Literals whose walk is under way, each with its owner. A spread or a value
|
|
208
|
+
* that leads back to one of them is source that could never have loaded —
|
|
209
|
+
* `const A = { ...B }` beside `const B = { ...A }` — and is a write the walk
|
|
210
|
+
* cannot name rather than a loop.
|
|
211
|
+
*/
|
|
212
|
+
const walking: { kind: string; node: ts.Node }[] = [];
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* How many walks may nest before the next is given up as a write the walk
|
|
216
|
+
* cannot name. Cycles end on their own above; this only keeps a chain written
|
|
217
|
+
* thousands deep from exhausting the stack.
|
|
218
|
+
*/
|
|
219
|
+
const MAX_WALK_NESTING = 256;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* How many walks have been cut short so far — by the nesting limit, or by
|
|
223
|
+
* leading back into a walk under way. A walk that sees the count move while it
|
|
224
|
+
* runs holds a cut somewhere inside it, and a cut depends on how deep the
|
|
225
|
+
* reading already was when it got there, so that walk is never remembered:
|
|
226
|
+
* remembered, it would hand the cut to a later reading that starts shallow
|
|
227
|
+
* enough to read the whole chain.
|
|
228
|
+
*/
|
|
229
|
+
let cutWalks = 0;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Walks an object literal's members in source order — the one walk every
|
|
233
|
+
* owner of a literal shares, so each rule below is written once and holds
|
|
234
|
+
* wherever a literal is read:
|
|
235
|
+
*
|
|
236
|
+
* - A spread applies where it is written. One the owner can follow merges its
|
|
237
|
+
* own walk there; one of `null` or `undefined` writes nothing; any other may
|
|
238
|
+
* write any key, so every key before it is cleared and the walk is `lost`.
|
|
239
|
+
* - A computed key standing for a `const` is that key. Any other clears every
|
|
240
|
+
* key before it, the same way.
|
|
241
|
+
* - A method, getter or setter writes its key with code, so the key is unread.
|
|
242
|
+
* A setter alone reads back undefined, which is no value either.
|
|
243
|
+
* - `__proto__: x` hands the object a prototype, unless `x` holds nothing.
|
|
244
|
+
* - A shorthand is read as the name it stands for.
|
|
245
|
+
* - The last write of a key wins, and an unreadable one takes the earlier
|
|
246
|
+
* value with it.
|
|
247
|
+
*/
|
|
248
|
+
export function walkLiteral<V>(literal: ObjectLiteralExpression, hooks: LiteralWalkHooks<V>): LiteralWalk<V> {
|
|
249
|
+
const node = literal.compilerNode;
|
|
250
|
+
const remembered = session?.walks.get(hooks.kind)?.get(node);
|
|
251
|
+
if (remembered) return remembered as LiteralWalk<V>;
|
|
252
|
+
if (walking.length >= MAX_WALK_NESTING || walking.some((open) => open.kind === hooks.kind && open.node === node)) {
|
|
253
|
+
cutWalks++;
|
|
254
|
+
const cut = emptyWalk<V>();
|
|
255
|
+
cut.lost = true;
|
|
256
|
+
return cut;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const cutsBefore = cutWalks;
|
|
260
|
+
walking.push({ kind: hooks.kind, node });
|
|
261
|
+
let walk: LiteralWalk<V>;
|
|
262
|
+
try {
|
|
263
|
+
walk = walkMembers(literal, hooks);
|
|
264
|
+
} finally {
|
|
265
|
+
walking.pop();
|
|
266
|
+
}
|
|
267
|
+
if (session && cutWalks === cutsBefore) {
|
|
268
|
+
const walks = session.walks.get(hooks.kind) ?? new Map<ts.Node, LiteralWalk<unknown>>();
|
|
269
|
+
session.walks.set(hooks.kind, walks);
|
|
270
|
+
walks.set(node, walk);
|
|
271
|
+
}
|
|
272
|
+
return walk;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function emptyWalk<V>(): LiteralWalk<V> {
|
|
276
|
+
return { entries: new Map(), unread: new Map(), cleared: new Set(), lost: false, inherits: false };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function walkMembers<V>(literal: ObjectLiteralExpression, hooks: LiteralWalkHooks<V>): LiteralWalk<V> {
|
|
280
|
+
const walk = emptyWalk<V>();
|
|
281
|
+
for (const property of literal.getProperties()) {
|
|
282
|
+
spendWork();
|
|
283
|
+
const spread = property.asKind(SyntaxKind.SpreadAssignment);
|
|
284
|
+
if (spread) {
|
|
285
|
+
const expression = spread.getExpression();
|
|
286
|
+
const source = holdsNothing(expression) ? SPREADS_NOTHING : hooks.spread(expression);
|
|
287
|
+
if (source === SPREADS_NOTHING) continue;
|
|
288
|
+
if (source) applySpread(walk, walkLiteral(source, hooks), property);
|
|
289
|
+
else writeUnnamed(walk, property);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const member = namedMember(property);
|
|
294
|
+
const key = member && propertyKey(member);
|
|
295
|
+
if (!member || key === undefined) {
|
|
296
|
+
writeUnnamed(walk, property);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (setsPrototype(member)) {
|
|
300
|
+
if (!inheritsNothing(member)) walk.inherits = true;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (key === '__proto__') {
|
|
304
|
+
writeKey(walk, key, undefined, 'reserved');
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const value = writtenValue(member);
|
|
308
|
+
if (value) writeKey(walk, key, hooks.read(value), 'value');
|
|
309
|
+
else writeKey(walk, key, undefined, member.isKind(SyntaxKind.SetAccessor) ? 'setter' : 'code');
|
|
310
|
+
}
|
|
311
|
+
return walk;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Whether the walked object may hold a key the walk could not read — unread,
|
|
316
|
+
* cleared, or reachable through a write it cannot name or a prototype —
|
|
317
|
+
* as opposed to one it provably does not write at all.
|
|
318
|
+
*/
|
|
319
|
+
export function mayHoldUnread<V>(walk: LiteralWalk<V>, key: string): boolean {
|
|
320
|
+
return !walk.entries.has(key) && (walk.unread.has(key) || walk.lost || walk.inherits);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** One write of a key: the last write wins, and one the owner could not read takes the earlier value with it. */
|
|
324
|
+
function writeKey<V>(walk: LiteralWalk<V>, key: string, value: V | undefined, why: UnreadWrite): void {
|
|
325
|
+
walk.cleared.delete(key);
|
|
326
|
+
if (value === undefined) {
|
|
327
|
+
walk.entries.delete(key);
|
|
328
|
+
walk.unread.set(key, why);
|
|
329
|
+
} else {
|
|
330
|
+
walk.unread.delete(key);
|
|
331
|
+
walk.entries.set(key, value);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** A write the walk cannot name, made by the member `at`, which may be any key — so every key written before it is cleared. */
|
|
336
|
+
function writeUnnamed<V>(walk: LiteralWalk<V>, at: Node): void {
|
|
337
|
+
for (const key of [...walk.entries.keys(), ...walk.unread.keys()]) walk.cleared.add(key);
|
|
338
|
+
walk.entries.clear();
|
|
339
|
+
walk.unread.clear();
|
|
340
|
+
walk.lost = true;
|
|
341
|
+
walk.lostAt = at;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* A spread source's walk, applied where the spread sits. A spread copies the
|
|
346
|
+
* source's own keys only, so its prototype is not carried over; a key the
|
|
347
|
+
* source could not name may be any key here too.
|
|
348
|
+
*/
|
|
349
|
+
function applySpread<V>(walk: LiteralWalk<V>, source: LiteralWalk<V>, spread: Node): void {
|
|
350
|
+
if (source.lost) {
|
|
351
|
+
writeUnnamed(walk, spread);
|
|
352
|
+
for (const key of source.cleared) walk.cleared.add(key);
|
|
353
|
+
}
|
|
354
|
+
for (const [key, why] of source.unread) writeKey(walk, key, undefined, why);
|
|
355
|
+
for (const [key, value] of source.entries) writeKey(walk, key, value, 'value');
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** An object read as plain data, and whether any of its entries — at any depth — had to be left out. */
|
|
359
|
+
export interface ObjectReading {
|
|
360
|
+
value: Record<string, JsonValue>;
|
|
361
|
+
dropped: boolean;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Plain data written in place: values read as written and names not followed,
|
|
366
|
+
* so a spread merges only an object written where it sits; a spread of
|
|
367
|
+
* anything else may write any key, and clears what came before it.
|
|
368
|
+
*/
|
|
369
|
+
const WRITTEN_DATA: LiteralWalkHooks<ValueReading> = {
|
|
370
|
+
kind: 'plain data',
|
|
371
|
+
read: literalValueReading,
|
|
372
|
+
spread: asObjectLiteral,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Plain data with every name in it followed to the `const` it stands for — an
|
|
377
|
+
* annotation written `ai: { ...BASE_AI, schema: SCHEMA }` reads the same as
|
|
378
|
+
* one written out in place.
|
|
379
|
+
*/
|
|
380
|
+
const NAMED_DATA: LiteralWalkHooks<ValueReading> = {
|
|
381
|
+
kind: 'plain data, names followed',
|
|
382
|
+
read: (value) => {
|
|
383
|
+
const literal = resolveObjectLiteral(value);
|
|
384
|
+
return literal ? objectReading(literal, NAMED_DATA) : resolveLiteralValueReading(value);
|
|
385
|
+
},
|
|
386
|
+
spread: resolveObjectLiteral,
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* An object read as plain data, with the names in it followed: the part that
|
|
391
|
+
* read, and whether anything was left out — a computed value, a method, a key
|
|
392
|
+
* it could not spell, a spread or a name it could not follow, a prototype.
|
|
393
|
+
* Every key the value holds is the runtime's own last write of it, so a caller
|
|
394
|
+
* that owes an admission makes one for the rest rather than presenting a wrong
|
|
395
|
+
* value. Undefined where the node does not lead to an object literal at all.
|
|
396
|
+
*/
|
|
397
|
+
export function literalObjectReading(object: Node): ObjectReading | undefined {
|
|
398
|
+
const literal = resolveObjectLiteral(object);
|
|
399
|
+
return literal && objectReading(literal, NAMED_DATA);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Plain data written in place, walked; the drop is carried to the reading holding it. */
|
|
403
|
+
function readObject(literal: ObjectLiteralExpression, drops: Drops): Record<string, JsonValue> {
|
|
404
|
+
const reading = objectReading(literal, WRITTEN_DATA);
|
|
405
|
+
if (reading.dropped) drops.dropped = true;
|
|
406
|
+
return reading.value;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function objectReading(literal: ObjectLiteralExpression, hooks: LiteralWalkHooks<ValueReading>): ObjectReading {
|
|
410
|
+
const walk = walkLiteral(literal, hooks);
|
|
411
|
+
let dropped = !walkIsWhole(walk);
|
|
412
|
+
const entries: [string, JsonValue][] = [];
|
|
413
|
+
for (const [key, reading] of walk.entries) {
|
|
414
|
+
// The walk is remembered, but each place the object is named gets its own
|
|
415
|
+
// copy, so every entry copied costs work.
|
|
416
|
+
spendWork();
|
|
417
|
+
if (reading.dropped) dropped = true;
|
|
418
|
+
entries.push([key, reading.value]);
|
|
419
|
+
}
|
|
420
|
+
// `fromEntries` defines each key rather than assigning it, and the walk never
|
|
421
|
+
// hands over `__proto__`, so the record keeps its own prototype.
|
|
422
|
+
return { value: Object.fromEntries(entries), dropped };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The JSON value an expression amounts to, following a name to its `const`
|
|
427
|
+
* declaration when the value is not written in place.
|
|
428
|
+
*
|
|
429
|
+
* `options: sizeOptions` is the shape this exists for: the legal values are two
|
|
430
|
+
* lines up, and reading the name as unreadable loses them. Only `const`
|
|
431
|
+
* declarations count — a `let` can be reassigned after the line being read.
|
|
432
|
+
* `LABELS.hero` is read out of the object `LABELS` stands for, the last write
|
|
433
|
+
* of the key winning as it does at runtime; a key a spread, getter or unknown
|
|
434
|
+
* computed name may have overwritten is no value at all.
|
|
435
|
+
*
|
|
436
|
+
* A value with a part left out is no value here, as for `literalValue`;
|
|
437
|
+
* `resolveLiteralValueReading` keeps the part that read.
|
|
438
|
+
*
|
|
439
|
+
* Known limits, both inherited from the walk: two barrels exporting the same
|
|
440
|
+
* name resolve to whichever one the compiler picked, and a `const` array is
|
|
441
|
+
* followed rather than frozen — `const o = [...]; o.push(x)` elsewhere in the
|
|
442
|
+
* module reads here as the value before the push.
|
|
443
|
+
*/
|
|
444
|
+
export function resolveLiteralValue(node: Node): JsonValue | undefined {
|
|
445
|
+
const reading = resolveLiteralValueReading(node);
|
|
446
|
+
return reading && !reading.dropped ? reading.value : undefined;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* `resolveLiteralValue`, keeping the part that read when something had to be
|
|
451
|
+
* left out, and saying so — `items: ITEMS` where each item's `id` is computed
|
|
452
|
+
* — so an owner admits the gap instead of presenting the rest as the whole.
|
|
453
|
+
*/
|
|
454
|
+
export function resolveLiteralValueReading(node: Node): ValueReading | undefined {
|
|
455
|
+
const direct = literalValueReading(node);
|
|
456
|
+
if (direct) return direct;
|
|
457
|
+
const initializer = resolveValueExpression(node);
|
|
458
|
+
return initializer ? literalValueReading(initializer) : undefined;
|
|
459
|
+
}
|