@fluentic/style 0.1.0-beta.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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +409 -0
- package/atomic/atRule/counterStyle.ts +35 -0
- package/atomic/atRule/fontFace.ts +37 -0
- package/atomic/atRule/fontPaletteValues.ts +36 -0
- package/atomic/atRule/fontSrc.ts +13 -0
- package/atomic/atRule/keyframes.ts +43 -0
- package/atomic/atRule/positionTry.ts +73 -0
- package/atomic/atRule/property.ts +39 -0
- package/atomic/atRule/utils.ts +81 -0
- package/atomic/className.ts +93 -0
- package/atomic/debug/className/className.ts +33 -0
- package/atomic/debug/className/index.ts +1 -0
- package/atomic/debug/property/data.ts +59 -0
- package/atomic/debug/property/index.ts +1 -0
- package/atomic/debug/property/property.ts +59 -0
- package/atomic/debug/selector.ts +88 -0
- package/atomic/debug/value.ts +53 -0
- package/atomic/element.ts +29 -0
- package/atomic/layer/README.md +116 -0
- package/atomic/layer/index.ts +3 -0
- package/atomic/layer/layer.ts +95 -0
- package/atomic/layer/types.ts +37 -0
- package/atomic/layer/utils.ts +51 -0
- package/atomic/property/index.ts +2 -0
- package/atomic/property/presets.ts +34 -0
- package/atomic/property/property.ts +13 -0
- package/atomic/property/type_maps.ts +389 -0
- package/atomic/property/types.ts +7 -0
- package/atomic/rule.ts +116 -0
- package/atomic/theme.ts +48 -0
- package/atomic/token.ts +53 -0
- package/atomic/utils/css.ts +49 -0
- package/atomic/utils/debug.ts +37 -0
- package/atomic/utils/format.ts +192 -0
- package/atomic/utils/selector.ts +14 -0
- package/atomic/utils/types.ts +11 -0
- package/atomic/value/index.ts +2 -0
- package/atomic/value/unitless.ts +47 -0
- package/atomic/value/value.ts +17 -0
- package/atomic/var.ts +19 -0
- package/builder/data/check_selector.noop.ts +8 -0
- package/builder/data/check_selector.ts +30 -0
- package/builder/data/const.ts +25 -0
- package/builder/data/create.ts +96 -0
- package/builder/data/data.ts +63 -0
- package/builder/data/debug.ts +113 -0
- package/builder/data/index.ts +9 -0
- package/builder/data/is.ts +68 -0
- package/builder/data/merge/index.ts +2 -0
- package/builder/data/merge/scope.ts +300 -0
- package/builder/data/merge/style.ts +284 -0
- package/builder/data/merge/utils.ts +35 -0
- package/builder/data/selector.ts +11 -0
- package/builder/data/state.ts +134 -0
- package/builder/extract/index.ts +6 -0
- package/builder/extract/scope.ts +30 -0
- package/builder/extract/slot.ts +36 -0
- package/builder/extract/style.ts +89 -0
- package/builder/extract/theme.ts +16 -0
- package/builder/extract/token.ts +41 -0
- package/builder/extract/utils.ts +95 -0
- package/builder/extract/withTokens.ts +64 -0
- package/builder/index.ts +2 -0
- package/builder/style_builder.ts +234 -0
- package/builder/style_data.ts +81 -0
- package/builder/style_fns.ts +611 -0
- package/builder/types/alias.ts +83 -0
- package/builder/types/fns.ts +185 -0
- package/builder/types/index.ts +1 -0
- package/builder/types/types.ts +51 -0
- package/builder/utils.ts +19 -0
- package/compiler/compiler/cache.ts +155 -0
- package/compiler/compiler/compiler.ts +173 -0
- package/compiler/compiler/index.ts +3 -0
- package/compiler/compiler/types.ts +62 -0
- package/compiler/extract/collector.ts +25 -0
- package/compiler/extract/extract.ts +51 -0
- package/compiler/extract/index.ts +3 -0
- package/compiler/extract/types.ts +35 -0
- package/compiler/index.ts +2 -0
- package/compiler/transform/debug/index.ts +2 -0
- package/compiler/transform/debug/plugin.ts +1347 -0
- package/compiler/transform/debug/transform.ts +47 -0
- package/compiler/transform/debug/utils/debug_data.ts +187 -0
- package/compiler/transform/debug/utils/source_url.ts +29 -0
- package/compiler/transform/evaluator/evaluator.ts +1138 -0
- package/compiler/transform/evaluator/index.ts +3 -0
- package/compiler/transform/evaluator/tracer.ts +607 -0
- package/compiler/transform/evaluator/types.ts +22 -0
- package/compiler/transform/extract/chain/chain.ts +2343 -0
- package/compiler/transform/extract/chain/extract_chain.ts +89 -0
- package/compiler/transform/extract/chain/index.ts +3 -0
- package/compiler/transform/extract/chain/types.ts +37 -0
- package/compiler/transform/extract/index.ts +2 -0
- package/compiler/transform/extract/plugin.ts +665 -0
- package/compiler/transform/extract/transform.ts +45 -0
- package/compiler/transform/extract/utils/imports.ts +132 -0
- package/compiler/transform/extract/utils/replacement.ts +349 -0
- package/compiler/transform/extract/utils/slot.ts +186 -0
- package/compiler/transform/extract/utils/state.ts +48 -0
- package/compiler/transform/extract/utils/theme.ts +86 -0
- package/compiler/transform/extract/utils/token.ts +1 -0
- package/compiler/transform/index.ts +5 -0
- package/compiler/transform/syntax/index.ts +5 -0
- package/compiler/transform/syntax/isStaticStyleValue.ts +44 -0
- package/compiler/transform/syntax/isStyleChainCall.ts +16 -0
- package/compiler/transform/syntax/static_ids.ts +282 -0
- package/compiler/transform/syntax/types.ts +7 -0
- package/compiler/transform/syntax/utils.ts +31 -0
- package/compiler/transform/utils/babel.ts +100 -0
- package/compiler/transform/utils/import.ts +47 -0
- package/compiler/transform/utils/path.ts +13 -0
- package/compiler/transform/utils/selector.ts +252 -0
- package/compiler/utils/constants.ts +69 -0
- package/compiler/utils/file_resolver.ts +72 -0
- package/compiler/utils/import_source.ts +200 -0
- package/compiler/utils/imports.ts +24 -0
- package/compiler/utils/path.ts +40 -0
- package/compiler/utils/sourcemap.ts +61 -0
- package/config/build.ts +32 -0
- package/config/config/css.ts +32 -0
- package/config/config/css_extra.ts +22 -0
- package/config/config/debug.ts +26 -0
- package/config/config/dev.ts +145 -0
- package/config/config/runtime.ts +29 -0
- package/config/configure.ts +28 -0
- package/config/constants.ts +1 -0
- package/config/index.ts +2 -0
- package/config/types.ts +56 -0
- package/config/utils.ts +5 -0
- package/css/counterStyle.ts +20 -0
- package/css/fontFace.ts +25 -0
- package/css/fontPaletteValues.ts +20 -0
- package/css/index.ts +8 -0
- package/css/keyframes.ts +20 -0
- package/css/positionTry.ts +20 -0
- package/css/property.ts +32 -0
- package/css/utils.ts +56 -0
- package/dev/config.ts +16 -0
- package/dev/fns.ts +48 -0
- package/dev/index.ts +2 -0
- package/dev/trace.ts +413 -0
- package/dev/utils.ts +528 -0
- package/dist/assert-h_Zkqc4E.js +105 -0
- package/dist/assert-h_Zkqc4E.js.map +1 -0
- package/dist/className-C1Ht5Wvv.js +144 -0
- package/dist/className-C1Ht5Wvv.js.map +1 -0
- package/dist/className-DC2Cq8p3.js +251 -0
- package/dist/className-DC2Cq8p3.js.map +1 -0
- package/dist/compiler/index.mjs +2 -0
- package/dist/compiler-DweanHoB.mjs +6847 -0
- package/dist/compiler-DweanHoB.mjs.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config-BryWDfQX.js +25 -0
- package/dist/config-BryWDfQX.js.map +1 -0
- package/dist/config-DKHXWhe1.js +1 -0
- package/dist/config-Di2VYYKV.js +6 -0
- package/dist/config-Di2VYYKV.js.map +1 -0
- package/dist/config-DloHOG6I.js +13 -0
- package/dist/config-DloHOG6I.js.map +1 -0
- package/dist/css-BowBszUt.js +243 -0
- package/dist/css-BowBszUt.js.map +1 -0
- package/dist/css-ByOrugEX.js +805 -0
- package/dist/css-ByOrugEX.js.map +1 -0
- package/dist/css-DcazYor9.js +235 -0
- package/dist/css-DcazYor9.js.map +1 -0
- package/dist/css.js +2 -0
- package/dist/css_extra-DlOnsnR1.js +8 -0
- package/dist/css_extra-DlOnsnR1.js.map +1 -0
- package/dist/css_extra-oIi3UEPK.js +8 -0
- package/dist/css_extra-oIi3UEPK.js.map +1 -0
- package/dist/data-_te7t0M4.js +473 -0
- package/dist/data-_te7t0M4.js.map +1 -0
- package/dist/debug-BAw63qX6.js +15 -0
- package/dist/debug-BAw63qX6.js.map +1 -0
- package/dist/debug-DGki_v7g.js +15 -0
- package/dist/debug-DGki_v7g.js.map +1 -0
- package/dist/debug-n2aZQBSa.js +172 -0
- package/dist/debug-n2aZQBSa.js.map +1 -0
- package/dist/dev/rsc.js +183 -0
- package/dist/dev/rsc.js.map +1 -0
- package/dist/dev-CcphAa3R.js +376 -0
- package/dist/dev-CcphAa3R.js.map +1 -0
- package/dist/dev-DfBbuLeE.js +71 -0
- package/dist/dev-DfBbuLeE.js.map +1 -0
- package/dist/dev.js +2 -0
- package/dist/elementMarker-Bu7gDAkE.js +800 -0
- package/dist/elementMarker-Bu7gDAkE.js.map +1 -0
- package/dist/entry/dev/css.js +3 -0
- package/dist/entry/dev/jsx-dev-runtime.js +3 -0
- package/dist/entry/dev/jsx-runtime.js +3 -0
- package/dist/entry/dev.js +10 -0
- package/dist/entry/prod/css.js +3 -0
- package/dist/entry/prod/extract.js +3 -0
- package/dist/entry/prod/jsx-dev-runtime.js +3 -0
- package/dist/entry/prod/jsx-runtime.js +3 -0
- package/dist/entry/prod/runtime.js +5 -0
- package/dist/entry/prod.js +1230 -0
- package/dist/entry/prod.js.map +1 -0
- package/dist/entry/rsc-dev/css.js +3 -0
- package/dist/entry/rsc-dev/dev.js +544 -0
- package/dist/entry/rsc-dev/dev.js.map +1 -0
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +12 -0
- package/dist/entry/rsc-dev/jsx-dev-runtime.js.map +1 -0
- package/dist/entry/rsc-dev/jsx-runtime.js +3 -0
- package/dist/entry/rsc-dev.js +1429 -0
- package/dist/entry/rsc-dev.js.map +1 -0
- package/dist/entry/rsc-prod/css.js +3 -0
- package/dist/entry/rsc-prod/jsx-dev-runtime.js +3 -0
- package/dist/entry/rsc-prod/jsx-runtime.js +3 -0
- package/dist/entry/rsc-prod/runtime.js +5 -0
- package/dist/entry/rsc-prod.js +10 -0
- package/dist/extract-CzWJeQi8.js +121 -0
- package/dist/extract-CzWJeQi8.js.map +1 -0
- package/dist/extract-DEwSDJ9Z.js +2 -0
- package/dist/format-3nKBE_5t.js +144 -0
- package/dist/format-3nKBE_5t.js.map +1 -0
- package/dist/getClassName-BlvXHYuf.js +260 -0
- package/dist/getClassName-BlvXHYuf.js.map +1 -0
- package/dist/global-CvfmFLsK.js +11 -0
- package/dist/global-CvfmFLsK.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/jsx/jsx-dev-runtime.js +12 -0
- package/dist/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx/jsx-dev-runtime.server.js +11 -0
- package/dist/jsx/jsx-dev-runtime.server.js.map +1 -0
- package/dist/jsx/jsx-runtime.js +13 -0
- package/dist/jsx/jsx-runtime.js.map +1 -0
- package/dist/jsx/jsx-runtime.server.js +12 -0
- package/dist/jsx/jsx-runtime.server.js.map +1 -0
- package/dist/jsx-CwTeyUxr.js +39 -0
- package/dist/jsx-CwTeyUxr.js.map +1 -0
- package/dist/jsx-D2BksHSv.js +38 -0
- package/dist/jsx-D2BksHSv.js.map +1 -0
- package/dist/jsx_dev_runtime-B6xs4by8.js +12 -0
- package/dist/jsx_dev_runtime-B6xs4by8.js.map +1 -0
- package/dist/jsx_runtime-04xfnsi7.js +13 -0
- package/dist/jsx_runtime-04xfnsi7.js.map +1 -0
- package/dist/jsx_runtime-iHLDwpcW.js +12 -0
- package/dist/jsx_runtime-iHLDwpcW.js.map +1 -0
- package/dist/layer-D1SaH07m.js +94 -0
- package/dist/layer-D1SaH07m.js.map +1 -0
- package/dist/loader-DS61nRqr.mjs +81 -0
- package/dist/loader-DS61nRqr.mjs.map +1 -0
- package/dist/misc-B9kqEb2N.mjs +360 -0
- package/dist/misc-B9kqEb2N.mjs.map +1 -0
- package/dist/plugin/farm/index.mjs +176 -0
- package/dist/plugin/farm/index.mjs.map +1 -0
- package/dist/plugin/nextjs/index.mjs +282 -0
- package/dist/plugin/nextjs/index.mjs.map +1 -0
- package/dist/plugin/nextjs/loader.mjs +162 -0
- package/dist/plugin/nextjs/loader.mjs.map +1 -0
- package/dist/plugin/parcel/index.cjs +9 -0
- package/dist/plugin/parcel/index.mjs +5 -0
- package/dist/plugin/parcel/optimizer.cjs +28 -0
- package/dist/plugin/parcel/optimizer.cjs.map +1 -0
- package/dist/plugin/parcel/optimizer.mjs +29 -0
- package/dist/plugin/parcel/optimizer.mjs.map +1 -0
- package/dist/plugin/parcel/resolver.cjs +17 -0
- package/dist/plugin/parcel/resolver.cjs.map +1 -0
- package/dist/plugin/parcel/resolver.mjs +18 -0
- package/dist/plugin/parcel/resolver.mjs.map +1 -0
- package/dist/plugin/parcel/runtime.cjs +17 -0
- package/dist/plugin/parcel/runtime.cjs.map +1 -0
- package/dist/plugin/parcel/runtime.mjs +17 -0
- package/dist/plugin/parcel/runtime.mjs.map +1 -0
- package/dist/plugin/parcel/transformer.cjs +41 -0
- package/dist/plugin/parcel/transformer.cjs.map +1 -0
- package/dist/plugin/parcel/transformer.mjs +41 -0
- package/dist/plugin/parcel/transformer.mjs.map +1 -0
- package/dist/plugin/rspack/index.mjs +11 -0
- package/dist/plugin/rspack/index.mjs.map +1 -0
- package/dist/plugin/vite/index.mjs +176 -0
- package/dist/plugin/vite/index.mjs.map +1 -0
- package/dist/plugin/webpack/index.mjs +2 -0
- package/dist/plugin/webpack/loader.mjs +19 -0
- package/dist/plugin/webpack/loader.mjs.map +1 -0
- package/dist/presets-Bye3ea2x.js +139 -0
- package/dist/presets-Bye3ea2x.js.map +1 -0
- package/dist/property-CnLFt5kx.js +406 -0
- package/dist/property-CnLFt5kx.js.map +1 -0
- package/dist/registry-CyIj8LYK.mjs +22 -0
- package/dist/registry-CyIj8LYK.mjs.map +1 -0
- package/dist/rules-9HSO1pxL.js +767 -0
- package/dist/rules-9HSO1pxL.js.map +1 -0
- package/dist/runtime-CYqNCiaM.js +53 -0
- package/dist/runtime-CYqNCiaM.js.map +1 -0
- package/dist/selector/index.js +3 -0
- package/dist/server.js +63 -0
- package/dist/server.js.map +1 -0
- package/dist/shared-BAL9peIw.cjs +7646 -0
- package/dist/shared-BAL9peIw.cjs.map +1 -0
- package/dist/shared-CCpq1zqA.mjs +132 -0
- package/dist/shared-CCpq1zqA.mjs.map +1 -0
- package/dist/sidecar-4u6GnlQG.mjs +236 -0
- package/dist/sidecar-4u6GnlQG.mjs.map +1 -0
- package/dist/style-4rFUy-zW.js +752 -0
- package/dist/style-4rFUy-zW.js.map +1 -0
- package/dist/style-B1UUqjj5.js +743 -0
- package/dist/style-B1UUqjj5.js.map +1 -0
- package/dist/style-Cw3NtvR0.js +5 -0
- package/dist/style-DNqQ6H-7.js +1255 -0
- package/dist/style-DNqQ6H-7.js.map +1 -0
- package/dist/styleStore-Dea_WVbr.js +2000 -0
- package/dist/styleStore-Dea_WVbr.js.map +1 -0
- package/dist/styleStore-DyNXBcUK.js +54 -0
- package/dist/styleStore-DyNXBcUK.js.map +1 -0
- package/dist/token-CKXUECuU.js +76 -0
- package/dist/token-CKXUECuU.js.map +1 -0
- package/dist/token-u_tM-mtg.js +204 -0
- package/dist/token-u_tM-mtg.js.map +1 -0
- package/dist/trace-Bu_qOqRy.js +245 -0
- package/dist/trace-Bu_qOqRy.js.map +1 -0
- package/dist/trace-CU0rvNYr.js +244 -0
- package/dist/trace-CU0rvNYr.js.map +1 -0
- package/dist/utils-BbehLOby.js +2415 -0
- package/dist/utils-BbehLOby.js.map +1 -0
- package/dist/utils-C7xfDxtM.mjs +97 -0
- package/dist/utils-C7xfDxtM.mjs.map +1 -0
- package/dist/utils-CWNHx4EC.js +170 -0
- package/dist/utils-CWNHx4EC.js.map +1 -0
- package/dist/utils-CdI6vZsP.js +37 -0
- package/dist/utils-CdI6vZsP.js.map +1 -0
- package/dist/utils-D7FAOyg6.js +129 -0
- package/dist/utils-D7FAOyg6.js.map +1 -0
- package/dist/utils-DMFgOOtA.mjs +49 -0
- package/dist/utils-DMFgOOtA.mjs.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/dist/value-BR4e2MKt.js +910 -0
- package/dist/value-BR4e2MKt.js.map +1 -0
- package/dist/value-E8rEv2Oe.js +136 -0
- package/dist/value-E8rEv2Oe.js.map +1 -0
- package/dist/valueRef-lshFk1Cs.js +16 -0
- package/dist/valueRef-lshFk1Cs.js.map +1 -0
- package/dist/webpack-CxS2FDYU.mjs +107 -0
- package/dist/webpack-CxS2FDYU.mjs.map +1 -0
- package/dist/withTokens-LRidu3Vc.js +95 -0
- package/dist/withTokens-LRidu3Vc.js.map +1 -0
- package/entry/dev/config.ts +2 -0
- package/entry/dev/css.ts +3 -0
- package/entry/dev/index.ts +3 -0
- package/entry/dev/jsx_dev_runtime.ts +3 -0
- package/entry/dev/jsx_runtime.ts +3 -0
- package/entry/prod/config.ts +2 -0
- package/entry/prod/css.ts +3 -0
- package/entry/prod/extract.ts +1 -0
- package/entry/prod/index.ts +3 -0
- package/entry/prod/jsx_dev_runtime.ts +3 -0
- package/entry/prod/jsx_runtime.ts +3 -0
- package/entry/prod/runtime.ts +14 -0
- package/entry/rsc_dev/config.ts +6 -0
- package/entry/rsc_dev/css.ts +3 -0
- package/entry/rsc_dev/dev.ts +5 -0
- package/entry/rsc_dev/index.ts +3 -0
- package/entry/rsc_dev/jsx_dev_runtime.ts +3 -0
- package/entry/rsc_dev/jsx_runtime.ts +3 -0
- package/entry/rsc_dev/server.ts +11 -0
- package/entry/rsc_prod/config.ts +6 -0
- package/entry/rsc_prod/css.ts +3 -0
- package/entry/rsc_prod/index.ts +3 -0
- package/entry/rsc_prod/jsx_dev_runtime.ts +3 -0
- package/entry/rsc_prod/jsx_runtime.ts +3 -0
- package/entry/rsc_prod/runtime.ts +12 -0
- package/entry/rsc_prod/server.ts +13 -0
- package/entry/shared/config.ts +5 -0
- package/entry/shared/dev.ts +19 -0
- package/entry/shared/prod.ts +4 -0
- package/index.ts +36 -0
- package/jsx/extracted/jsx_dev_runtime.ts +11 -0
- package/jsx/extracted/jsx_runtime.ts +12 -0
- package/jsx/rsc/jsx_dev_runtime.ts +11 -0
- package/jsx/rsc/jsx_runtime.ts +12 -0
- package/jsx/rsc_extracted/jsx_dev_runtime.ts +2 -0
- package/jsx/rsc_extracted/jsx_runtime.ts +2 -0
- package/jsx/runtime/jsx_dev_runtime.ts +11 -0
- package/jsx/runtime/jsx_runtime.ts +12 -0
- package/jsx/types.ts +8 -0
- package/jsx/utils.ts +59 -0
- package/package.json +298 -0
- package/plugin/bundler/farm/index.ts +1 -0
- package/plugin/bundler/farm/plugin.ts +320 -0
- package/plugin/bundler/parcel/config.json +19 -0
- package/plugin/bundler/parcel/index.ts +1 -0
- package/plugin/bundler/parcel/optimizer.ts +36 -0
- package/plugin/bundler/parcel/plugin.ts +4 -0
- package/plugin/bundler/parcel/resolver.ts +36 -0
- package/plugin/bundler/parcel/runtime.ts +23 -0
- package/plugin/bundler/parcel/shared.ts +234 -0
- package/plugin/bundler/parcel/transformer.ts +67 -0
- package/plugin/bundler/rspack/index.ts +1 -0
- package/plugin/bundler/rspack/plugin.ts +14 -0
- package/plugin/bundler/vite/index.ts +1 -0
- package/plugin/bundler/vite/plugin.ts +133 -0
- package/plugin/bundler/vite/state.ts +153 -0
- package/plugin/bundler/webpack/index.ts +1 -0
- package/plugin/bundler/webpack/loader.ts +19 -0
- package/plugin/bundler/webpack/plugin.ts +240 -0
- package/plugin/bundler/webpack/shared/index.ts +2 -0
- package/plugin/bundler/webpack/shared/loader.ts +155 -0
- package/plugin/bundler/webpack/shared/registry.ts +16 -0
- package/plugin/bundler/webpack/utils.ts +96 -0
- package/plugin/nextjs/constants.ts +7 -0
- package/plugin/nextjs/html.ts +62 -0
- package/plugin/nextjs/index.ts +2 -0
- package/plugin/nextjs/loader.ts +222 -0
- package/plugin/nextjs/plugin.ts +532 -0
- package/plugin/nextjs/types.ts +33 -0
- package/plugin/nextjs/utils.ts +210 -0
- package/plugin/utils/cache/css_cache.ts +146 -0
- package/plugin/utils/cache/file.ts +40 -0
- package/plugin/utils/cache/index.ts +2 -0
- package/plugin/utils/compiler.ts +94 -0
- package/plugin/utils/constants.ts +7 -0
- package/plugin/utils/cssMarker.ts +14 -0
- package/plugin/utils/cssOutput.ts +65 -0
- package/plugin/utils/filter.ts +98 -0
- package/plugin/utils/imports.ts +5 -0
- package/plugin/utils/index.ts +10 -0
- package/plugin/utils/injection.ts +28 -0
- package/plugin/utils/misc.ts +5 -0
- package/plugin/utils/runtimeEntry.ts +57 -0
- package/plugin/utils/sidecar/index.ts +1 -0
- package/plugin/utils/sidecar/server.ts +143 -0
- package/plugin/utils/sidecar/sidecar.ts +167 -0
- package/plugin/utils/sidecar/utils.ts +109 -0
- package/plugin/utils/sourcemap.ts +52 -0
- package/plugin/utils/virtual.ts +81 -0
- package/runtime/core/cache/combine.ts +102 -0
- package/runtime/core/cache/index.ts +5 -0
- package/runtime/core/cache/item.ts +231 -0
- package/runtime/core/cache/pool.ts +310 -0
- package/runtime/core/cache/prop.ts +283 -0
- package/runtime/core/cache/propCache.ts +62 -0
- package/runtime/core/cache/resolvedItem.ts +31 -0
- package/runtime/core/cache/result.ts +115 -0
- package/runtime/core/cache/stateItem.ts +208 -0
- package/runtime/core/cache/tokenValues.ts +150 -0
- package/runtime/core/cache/utils/tree.ts +57 -0
- package/runtime/core/cache/utils/walk.ts +24 -0
- package/runtime/core/className.ts +101 -0
- package/runtime/core/combinedStyle.ts +101 -0
- package/runtime/core/createTransformElement.ts +39 -0
- package/runtime/core/elementMarker.ts +189 -0
- package/runtime/core/elementMarkerData.ts +27 -0
- package/runtime/core/getClassName.ts +47 -0
- package/runtime/core/getSheetRules.ts +7 -0
- package/runtime/core/getToken.ts +14 -0
- package/runtime/core/index.ts +5 -0
- package/runtime/core/jsx.ts +4 -0
- package/runtime/core/resolveClassNameRuntime.ts +33 -0
- package/runtime/env.ts +7 -0
- package/runtime/extract/getClassName.ts +476 -0
- package/runtime/extract/index.ts +4 -0
- package/runtime/extract/jsx.ts +55 -0
- package/runtime/index.ts +12 -0
- package/runtime/rsc/constants.ts +6 -0
- package/runtime/rsc/dev.ts +38 -0
- package/runtime/rsc/getClassName.ts +98 -0
- package/runtime/rsc/index.ts +3 -0
- package/runtime/rsc/jsx.ts +4 -0
- package/runtime/rsc/observer.ts +238 -0
- package/runtime/rsc/styleStore.ts +82 -0
- package/runtime/sheet/element.ts +13 -0
- package/runtime/sheet/global-noop.ts +13 -0
- package/runtime/sheet/global-prod.ts +13 -0
- package/runtime/sheet/global.ts +13 -0
- package/runtime/sheet/index.ts +3 -0
- package/runtime/sheet/insert.ts +37 -0
- package/runtime/sheet/rule.ts +77 -0
- package/runtime/sheet/rules.ts +131 -0
- package/runtime/sheet/theme.ts +34 -0
- package/runtime/style/index.ts +3 -0
- package/runtime/style/scope.ts +65 -0
- package/runtime/style/style.ts +34 -0
- package/runtime/style/token.ts +1 -0
- package/runtime/types.ts +42 -0
- package/selector/assert.ts +131 -0
- package/selector/index.ts +5 -0
- package/selector/presets/default.ts +27 -0
- package/selector/presets/index.ts +3 -0
- package/selector/presets/minimal.ts +37 -0
- package/selector/presets/selectors.ts +85 -0
- package/selector/selector.ts +68 -0
- package/selector/types.ts +24 -0
- package/selector/validate.ts +91 -0
- package/sheet/dev/dev_layer.ts +151 -0
- package/sheet/dev/dev_sort.ts +249 -0
- package/sheet/dev/index.ts +129 -0
- package/sheet/dev/utils.ts +130 -0
- package/sheet/index.ts +4 -0
- package/sheet/prod.ts +109 -0
- package/sheet/sheet.ts +10 -0
- package/sheet/sourcemap.ts +70 -0
- package/sheet/types.ts +31 -0
- package/sheet/utils/dom.ts +71 -0
- package/sheet/utils/index.ts +4 -0
- package/sheet/utils/layer.ts +14 -0
- package/sheet/utils/noop.ts +11 -0
- package/sheet/utils/rule.ts +3 -0
- package/sheet/utils/sourcemap.ts +221 -0
- package/style/index.ts +9 -0
- package/style/keyframes.ts +40 -0
- package/style/style.ts +112 -0
- package/style/theme.ts +36 -0
- package/style/token.ts +101 -0
- package/style/tokens.ts +64 -0
- package/style/transform.ts +9 -0
- package/style/types.ts +32 -0
- package/style/utils/expose.ts +43 -0
- package/style/utils/index.ts +1 -0
- package/style/value.ts +103 -0
- package/style/valueRef.ts +25 -0
- package/utils/global.ts +44 -0
- package/utils/hash.ts +22 -0
- package/utils/id.ts +20 -0
- package/utils/object.ts +87 -0
- package/utils/trace.ts +211 -0
- package/utils/type.ts +22 -0
|
@@ -0,0 +1,1347 @@
|
|
|
1
|
+
import { SELECTOR_MERGE } from '../../../builder/data/selector';
|
|
2
|
+
import { BUILDER_STATE } from '../../../builder/data/const';
|
|
3
|
+
import { TRACE_STYLE, TRACE_VALUE, type DebugLoc } from '../../../builder/data/debug';
|
|
4
|
+
import { isScopeData, isStyleData } from '../../../builder/data/is';
|
|
5
|
+
import type { RuntimeItem } from '../../../builder/data/state';
|
|
6
|
+
import type { CheckSelectorMode, SourcemapLocationMode } from '../../../config/types';
|
|
7
|
+
import type { StyleFnMeta } from '../../../style/style';
|
|
8
|
+
import { isStyleTokenData } from '../../../style/token';
|
|
9
|
+
import type { CompilerOptions } from '../../compiler/types';
|
|
10
|
+
import {
|
|
11
|
+
DEBUG_SOURCE_CONTENT_VAR,
|
|
12
|
+
DEBUG_SOURCE_URL_VAR,
|
|
13
|
+
DEFAULT_CONFIG,
|
|
14
|
+
FN_STYLE_KEYFRAMES,
|
|
15
|
+
FN_STYLE_MERGE,
|
|
16
|
+
FN_STYLE_PLAIN,
|
|
17
|
+
FN_STYLE_RAW,
|
|
18
|
+
FN_STYLE_SCOPE,
|
|
19
|
+
FN_CREATE_THEME,
|
|
20
|
+
IMPORT_PATHS,
|
|
21
|
+
} from '../../utils/constants';
|
|
22
|
+
import { createImportSourceMatcher, type ImportSourceMatcher } from '../../utils/import_source';
|
|
23
|
+
import {
|
|
24
|
+
COMPILED_STYLE_OBJECT_LOCATIONS,
|
|
25
|
+
type CompiledStyleObject,
|
|
26
|
+
type CompiledStyleObjectLocations,
|
|
27
|
+
type EvalScope,
|
|
28
|
+
evaluateNode,
|
|
29
|
+
} from '../evaluator/evaluator';
|
|
30
|
+
import type { EvalModuleBindings, ImportMap, ResolveImportFn } from '../evaluator/types';
|
|
31
|
+
import type { ExtractTracer } from '../extract/plugin';
|
|
32
|
+
import {
|
|
33
|
+
annotateAtRuleDeclaration,
|
|
34
|
+
annotateThemeCall,
|
|
35
|
+
annotateTokenDeclaration,
|
|
36
|
+
getImportedName,
|
|
37
|
+
isStyleChainCall,
|
|
38
|
+
} from '../syntax';
|
|
39
|
+
import type { BabelCore, BabelTypes, NodePath } from '../utils/babel';
|
|
40
|
+
import { babelPlugin } from '../utils/babel';
|
|
41
|
+
import { getProjectFileId } from '../utils/path';
|
|
42
|
+
import { getSelectorArgIndex, validateResolvedSelectorValue, validateSelectorDefinition } from '../utils/selector';
|
|
43
|
+
import { buildDebugDataObject, type DebugTraceProperty, hasDebugArgument } from './utils/debug_data';
|
|
44
|
+
import { getDebugSourceUrl } from './utils/source_url';
|
|
45
|
+
|
|
46
|
+
type PluginState = BabelCore.PluginPass & {
|
|
47
|
+
options: CompilerOptions;
|
|
48
|
+
projectDir: string;
|
|
49
|
+
styleNames: Set<string>;
|
|
50
|
+
styleMetas: Map<string, StyleFnMeta>;
|
|
51
|
+
bindings: EvalModuleBindings;
|
|
52
|
+
imports: ImportMap;
|
|
53
|
+
resolveImport: ResolveImportFn;
|
|
54
|
+
importSourceMatcher: ImportSourceMatcher;
|
|
55
|
+
checkSelector: CheckSelectorMode | undefined;
|
|
56
|
+
filePath: string;
|
|
57
|
+
fileId: string;
|
|
58
|
+
sourcemapTrace: SourcemapTrace;
|
|
59
|
+
programPath: NodePath<BabelTypes.Program> | null;
|
|
60
|
+
sourceUrlId: BabelTypes.Identifier | null;
|
|
61
|
+
sourceContentId: BabelTypes.Identifier | null;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
type PluginArgs = {
|
|
65
|
+
options: CompilerOptions;
|
|
66
|
+
projectDir: string;
|
|
67
|
+
sourceUrl: string;
|
|
68
|
+
sourceContent: string | null;
|
|
69
|
+
tracer: ExtractTracer;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type SourcemapTrace = SourcemapLocationMode;
|
|
73
|
+
|
|
74
|
+
type BabelBinding = {
|
|
75
|
+
identifier: BabelTypes.Identifier;
|
|
76
|
+
referencePaths: NodePath[];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function createDebugPlugin(args: PluginArgs) {
|
|
80
|
+
const { options, projectDir, sourceUrl, sourceContent } = args;
|
|
81
|
+
|
|
82
|
+
return babelPlugin<PluginState>((babel) => {
|
|
83
|
+
const { types: t } = babel;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
pre(this: PluginState) {
|
|
87
|
+
this.options = options;
|
|
88
|
+
this.projectDir = projectDir;
|
|
89
|
+
this.styleNames = new Set();
|
|
90
|
+
this.styleMetas = new Map();
|
|
91
|
+
this.bindings = new Map();
|
|
92
|
+
this.imports = new Map();
|
|
93
|
+
this.resolveImport = (source, fromFile) => args.tracer.resolveImport(babel, source, fromFile);
|
|
94
|
+
this.importSourceMatcher = createImportSourceMatcher(options.importSources ?? null);
|
|
95
|
+
this.checkSelector = options.dev?.checkSelector;
|
|
96
|
+
this.filePath = this.file?.opts?.filename ?? 'unknown';
|
|
97
|
+
this.fileId = getProjectFileId(projectDir, this.file?.opts?.filename);
|
|
98
|
+
this.sourcemapTrace = options.dev?.sourcemapMode ?? 'style';
|
|
99
|
+
this.programPath = null;
|
|
100
|
+
this.sourceUrlId = null;
|
|
101
|
+
this.sourceContentId = null;
|
|
102
|
+
},
|
|
103
|
+
visitor: {
|
|
104
|
+
Program: {
|
|
105
|
+
enter(path: NodePath<BabelTypes.Program>, state: PluginState) {
|
|
106
|
+
state.programPath = path;
|
|
107
|
+
},
|
|
108
|
+
exit(path: NodePath<BabelTypes.Program>, state: PluginState) {
|
|
109
|
+
insertDebugDeclarations(t, path, state, sourceUrl, sourceContent);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
ImportDeclaration(
|
|
114
|
+
path: NodePath<BabelTypes.ImportDeclaration>,
|
|
115
|
+
state: PluginState,
|
|
116
|
+
) {
|
|
117
|
+
const source = path.node.source.value;
|
|
118
|
+
if (typeof source !== 'string') return;
|
|
119
|
+
|
|
120
|
+
path.node.specifiers.forEach((spec) => {
|
|
121
|
+
if (spec.type === 'ImportSpecifier') {
|
|
122
|
+
state.imports.set(spec.local.name, { source, name: getImportedName(spec) });
|
|
123
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
124
|
+
state.imports.set(spec.local.name, { source, name: 'default' });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
path.node.specifiers.forEach((spec) => {
|
|
129
|
+
if (spec.type !== 'ImportSpecifier' && spec.type !== 'ImportDefaultSpecifier') return;
|
|
130
|
+
|
|
131
|
+
const imported = spec.type === 'ImportSpecifier'
|
|
132
|
+
? getImportedName(spec)
|
|
133
|
+
: 'default';
|
|
134
|
+
|
|
135
|
+
const meta = state.importSourceMatcher({ source, name: imported });
|
|
136
|
+
if (meta) {
|
|
137
|
+
state.styleNames.add(spec.local.name);
|
|
138
|
+
state.styleMetas.set(spec.local.name, meta);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
VariableDeclaration(path, state) {
|
|
144
|
+
path.node.declarations.forEach((decl) => {
|
|
145
|
+
annotateTokenDeclaration(decl, state, t);
|
|
146
|
+
annotateAtRuleDeclaration(decl, state, t);
|
|
147
|
+
|
|
148
|
+
if (decl.id.type !== 'Identifier' || !decl.init) return;
|
|
149
|
+
|
|
150
|
+
state.bindings.set(
|
|
151
|
+
decl.id.name,
|
|
152
|
+
evaluateNode(decl.init, getDebugEvalScope(state)),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
CallExpression(
|
|
158
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
159
|
+
state: PluginState,
|
|
160
|
+
) {
|
|
161
|
+
annotateThemeCall(path.node, state, t);
|
|
162
|
+
annotateThemeCallsite(t, path, state, sourceContent);
|
|
163
|
+
|
|
164
|
+
if (!state.styleNames.size) return;
|
|
165
|
+
validateStaticSelectorArg(path, state);
|
|
166
|
+
if (isStyleUtilityCall(path.node.callee, state.styleNames)) return;
|
|
167
|
+
const isScopeMerge = isScopeMergeCall(path.node.callee, state);
|
|
168
|
+
if (
|
|
169
|
+
(isScopeChainCall(path.node.callee, state.styleNames) && !isScopeMerge) ||
|
|
170
|
+
(
|
|
171
|
+
!isStyleChainCall(path.node.callee, state.styleNames) &&
|
|
172
|
+
!isScopeItemCall(path, state) &&
|
|
173
|
+
!isScopeMerge
|
|
174
|
+
)
|
|
175
|
+
) return;
|
|
176
|
+
const evaluated = evaluateNode(path.node, getDebugEvalScope(state));
|
|
177
|
+
if (evaluated.ok && isStyleTokenData(evaluated.value)) return;
|
|
178
|
+
if (hasDebugArgument(path.node.arguments)) return;
|
|
179
|
+
|
|
180
|
+
const sourceUrlRef = getSourceUrlId(t, state);
|
|
181
|
+
const sourceContentRef = sourceContent
|
|
182
|
+
? getSourceContentId(t, state)
|
|
183
|
+
: null;
|
|
184
|
+
|
|
185
|
+
path.node.arguments.push(
|
|
186
|
+
buildDebugDataObject(
|
|
187
|
+
t,
|
|
188
|
+
path.node,
|
|
189
|
+
state.fileId,
|
|
190
|
+
sourceUrlRef,
|
|
191
|
+
sourceContentRef,
|
|
192
|
+
options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat,
|
|
193
|
+
getDebugStyleArg(t, path, state, options.dev?.sourcemapMode ?? 'style'),
|
|
194
|
+
getDebugCallLoc(path, state),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
JSXOpeningElement(
|
|
200
|
+
path: NodePath<BabelTypes.JSXOpeningElement>,
|
|
201
|
+
state: PluginState,
|
|
202
|
+
) {
|
|
203
|
+
if (options.dev?.elementClassName === false) return;
|
|
204
|
+
if (!isHostJsxElement(path.node.name)) return;
|
|
205
|
+
|
|
206
|
+
const cssAttr = getJsxAttribute(path.node, 'css');
|
|
207
|
+
if (!cssAttr) return;
|
|
208
|
+
|
|
209
|
+
const loc = path.node.loc?.start;
|
|
210
|
+
if (!loc) return;
|
|
211
|
+
|
|
212
|
+
const sourceUrlRef = getSourceUrlId(t, state);
|
|
213
|
+
const sourceContentRef = sourceContent
|
|
214
|
+
? getSourceContentId(t, state)
|
|
215
|
+
: null;
|
|
216
|
+
|
|
217
|
+
const debugInfo = getElementDebugInfo(cssAttr);
|
|
218
|
+
const label = debugInfo.label || getShortFileLabel(state.fileId);
|
|
219
|
+
const debug = buildElementDebugDataObject(
|
|
220
|
+
t,
|
|
221
|
+
loc.line,
|
|
222
|
+
loc.column + 1,
|
|
223
|
+
label,
|
|
224
|
+
sourceUrlRef,
|
|
225
|
+
sourceContentRef,
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
wrapCssAttributeWithElementDebug(t, cssAttr, debug);
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function annotateThemeCallsite(
|
|
236
|
+
t: typeof BabelTypes,
|
|
237
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
238
|
+
state: PluginState,
|
|
239
|
+
sourceContent: string | null,
|
|
240
|
+
) {
|
|
241
|
+
if (!isCreateThemeCall(path.node, state)) return;
|
|
242
|
+
if (path.node.arguments[2]) return;
|
|
243
|
+
|
|
244
|
+
const loc = path.node.loc?.start;
|
|
245
|
+
if (!loc) return;
|
|
246
|
+
|
|
247
|
+
while (path.node.arguments.length < 2) {
|
|
248
|
+
path.node.arguments.push(t.identifier('undefined'));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const line = loc.line;
|
|
252
|
+
const column = loc.column + 1;
|
|
253
|
+
const sourceUrlRef = getSourceUrlId(t, state);
|
|
254
|
+
const sourceContentRef = sourceContent ? getSourceContentId(t, state) : null;
|
|
255
|
+
|
|
256
|
+
path.node.arguments.push(t.objectExpression([
|
|
257
|
+
t.objectProperty(
|
|
258
|
+
t.identifier('stack'),
|
|
259
|
+
t.binaryExpression(
|
|
260
|
+
'+',
|
|
261
|
+
t.binaryExpression(
|
|
262
|
+
'+',
|
|
263
|
+
t.binaryExpression(
|
|
264
|
+
'+',
|
|
265
|
+
t.stringLiteral('Error\\n at '),
|
|
266
|
+
sourceUrlRef,
|
|
267
|
+
),
|
|
268
|
+
t.stringLiteral(':' + line + ':' + column),
|
|
269
|
+
),
|
|
270
|
+
t.stringLiteral(''),
|
|
271
|
+
),
|
|
272
|
+
),
|
|
273
|
+
t.objectProperty(t.identifier('filePath'), sourceUrlRef),
|
|
274
|
+
t.objectProperty(t.identifier('sourceUrl'), sourceUrlRef),
|
|
275
|
+
...(sourceContentRef
|
|
276
|
+
? [t.objectProperty(t.identifier('sourceContent'), sourceContentRef)]
|
|
277
|
+
: []),
|
|
278
|
+
t.objectProperty(t.identifier('line'), t.numericLiteral(line)),
|
|
279
|
+
t.objectProperty(t.identifier('column'), t.numericLiteral(column)),
|
|
280
|
+
]));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function isCreateThemeCall(
|
|
284
|
+
node: BabelTypes.CallExpression,
|
|
285
|
+
state: PluginState,
|
|
286
|
+
) {
|
|
287
|
+
if (node.callee.type !== 'Identifier') return false;
|
|
288
|
+
|
|
289
|
+
const imp = state.imports.get(node.callee.name);
|
|
290
|
+
|
|
291
|
+
return !!imp && IMPORT_PATHS.includes(imp.source) && imp.name === FN_CREATE_THEME;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function isHostJsxElement(name: BabelTypes.JSXOpeningElement['name']) {
|
|
295
|
+
if (name.type !== 'JSXIdentifier') return false;
|
|
296
|
+
|
|
297
|
+
const first = name.name.charCodeAt(0);
|
|
298
|
+
return first >= 97 && first <= 122;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function getJsxAttribute(
|
|
302
|
+
node: BabelTypes.JSXOpeningElement,
|
|
303
|
+
name: string,
|
|
304
|
+
) {
|
|
305
|
+
for (const attr of node.attributes) {
|
|
306
|
+
if (attr.type !== 'JSXAttribute') continue;
|
|
307
|
+
if (attr.name.type !== 'JSXIdentifier') continue;
|
|
308
|
+
if (attr.name.name === name) return attr;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
type ElementDebugInfo = {
|
|
315
|
+
label: string;
|
|
316
|
+
loc: BabelTypes.SourceLocation['start'] | null;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
function getElementDebugInfo(attr: BabelTypes.JSXAttribute): ElementDebugInfo {
|
|
320
|
+
const value = attr.value;
|
|
321
|
+
if (!value || value.type !== 'JSXExpressionContainer') return { label: '', loc: null };
|
|
322
|
+
|
|
323
|
+
return getExpressionDebugInfo(value.expression);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function wrapCssAttributeWithElementDebug(
|
|
327
|
+
t: typeof BabelTypes,
|
|
328
|
+
attr: BabelTypes.JSXAttribute,
|
|
329
|
+
debug: BabelTypes.ObjectExpression,
|
|
330
|
+
) {
|
|
331
|
+
const value = attr.value;
|
|
332
|
+
if (!value || value.type !== 'JSXExpressionContainer') return;
|
|
333
|
+
|
|
334
|
+
const expression = value.expression;
|
|
335
|
+
if (expression.type === 'JSXEmptyExpression') return;
|
|
336
|
+
|
|
337
|
+
if (expression.type === 'ArrayExpression') {
|
|
338
|
+
expression.elements.unshift(debug);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
value.expression = t.arrayExpression([debug, expression]);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function buildElementDebugDataObject(
|
|
346
|
+
t: typeof BabelTypes,
|
|
347
|
+
line: number,
|
|
348
|
+
column: number,
|
|
349
|
+
label: string,
|
|
350
|
+
sourceUrlRef: BabelTypes.Expression,
|
|
351
|
+
sourceContentRef: BabelTypes.Expression | null,
|
|
352
|
+
) {
|
|
353
|
+
return t.objectExpression([
|
|
354
|
+
t.objectProperty(
|
|
355
|
+
t.identifier('$$elementDebug'),
|
|
356
|
+
t.booleanLiteral(true),
|
|
357
|
+
),
|
|
358
|
+
t.objectProperty(
|
|
359
|
+
t.identifier('loc'),
|
|
360
|
+
t.arrayExpression([
|
|
361
|
+
t.numericLiteral(line),
|
|
362
|
+
t.numericLiteral(column),
|
|
363
|
+
]),
|
|
364
|
+
),
|
|
365
|
+
t.objectProperty(
|
|
366
|
+
t.identifier('label'),
|
|
367
|
+
t.stringLiteral(label),
|
|
368
|
+
),
|
|
369
|
+
t.objectProperty(
|
|
370
|
+
t.identifier('sourceUrl'),
|
|
371
|
+
sourceUrlRef,
|
|
372
|
+
),
|
|
373
|
+
...sourceContentRef
|
|
374
|
+
? [
|
|
375
|
+
t.objectProperty(
|
|
376
|
+
t.identifier('code'),
|
|
377
|
+
sourceContentRef,
|
|
378
|
+
),
|
|
379
|
+
]
|
|
380
|
+
: [],
|
|
381
|
+
]);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getExpressionDebugInfo(node: BabelTypes.JSXExpressionContainer['expression']): ElementDebugInfo {
|
|
385
|
+
if (node.type === 'JSXEmptyExpression') return { label: '', loc: null };
|
|
386
|
+
|
|
387
|
+
if (node.type === 'ArrayExpression') {
|
|
388
|
+
for (const element of node.elements) {
|
|
389
|
+
if (!element || element.type === 'SpreadElement') continue;
|
|
390
|
+
|
|
391
|
+
const info = getExpressionDebugInfo(element);
|
|
392
|
+
if (info.label) return info;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return { label: '', loc: null };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (node.type === 'MemberExpression' && !node.computed) {
|
|
399
|
+
if (node.property.type === 'Identifier') {
|
|
400
|
+
return { label: node.property.name, loc: node.loc?.start ?? node.property.loc?.start ?? null };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (node.property.type === 'PrivateName') {
|
|
404
|
+
return { label: node.property.id.name, loc: node.loc?.start ?? node.property.loc?.start ?? null };
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (node.type === 'MemberExpression' && node.computed && node.property.type === 'StringLiteral') {
|
|
409
|
+
return { label: node.property.value, loc: node.loc?.start ?? node.property.loc?.start ?? null };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (node.type === 'Identifier') {
|
|
413
|
+
return { label: node.name, loc: node.loc?.start ?? null };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return { label: '', loc: null };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function getShortFileLabel(filePath: string) {
|
|
420
|
+
const normalized = filePath.split(/[?#]/, 1)[0] || filePath;
|
|
421
|
+
const fileName = normalized.split(/[\\/]/).pop() || 'element';
|
|
422
|
+
const index = fileName.lastIndexOf('.');
|
|
423
|
+
|
|
424
|
+
return index > 0 ? fileName.slice(0, index) : fileName;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function validateStaticSelectorArg(
|
|
428
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
429
|
+
state: PluginState,
|
|
430
|
+
) {
|
|
431
|
+
const methodName = getSelectorMethodName(path.node.callee);
|
|
432
|
+
if (!methodName) return;
|
|
433
|
+
|
|
434
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
435
|
+
if (!rootName) return;
|
|
436
|
+
|
|
437
|
+
const selector = state.styleMetas.get(rootName)?.selectors[methodName];
|
|
438
|
+
if (!selector) return;
|
|
439
|
+
if (!isStyleChainCall(path.node.callee, state.styleNames) && !isScopeItemCall(path, state)) return;
|
|
440
|
+
|
|
441
|
+
try {
|
|
442
|
+
validateSelectorDefinition(
|
|
443
|
+
state.checkSelector,
|
|
444
|
+
`style.${methodName}`,
|
|
445
|
+
selector,
|
|
446
|
+
getSelectorMethodNode(path.node.callee),
|
|
447
|
+
);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
450
|
+
const methodPath = getSelectorMethodPath(path);
|
|
451
|
+
throw (methodPath ?? path).buildCodeFrameError(message);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const argIndex = getSelectorArgIndex(selector, path.node.arguments as BabelTypes.Node[]);
|
|
455
|
+
if (argIndex === null) return;
|
|
456
|
+
|
|
457
|
+
try {
|
|
458
|
+
validateResolvedSelectorValue(
|
|
459
|
+
state.checkSelector,
|
|
460
|
+
`style.${methodName}`,
|
|
461
|
+
selector,
|
|
462
|
+
evaluateNode(
|
|
463
|
+
path.node.arguments[argIndex] as BabelTypes.Node | undefined,
|
|
464
|
+
getDebugEvalScope(state),
|
|
465
|
+
),
|
|
466
|
+
path.node.arguments[argIndex] as BabelTypes.Node | undefined,
|
|
467
|
+
);
|
|
468
|
+
} catch (error) {
|
|
469
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
470
|
+
const argPath = path.get(`arguments.${argIndex}`) as NodePath<BabelTypes.Node>;
|
|
471
|
+
throw argPath.buildCodeFrameError(message);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function getDebugEvalScope(state: PluginState): EvalScope {
|
|
476
|
+
return {
|
|
477
|
+
bindings: state.bindings,
|
|
478
|
+
imports: state.imports,
|
|
479
|
+
resolveImport: state.resolveImport,
|
|
480
|
+
filePath: state.filePath,
|
|
481
|
+
styleFilePath: state.filePath,
|
|
482
|
+
sourcemapTrace: state.sourcemapTrace,
|
|
483
|
+
styleNames: state.styleNames,
|
|
484
|
+
styleMetas: state.styleMetas,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function getStyleChainRootName(
|
|
489
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
490
|
+
styleNames: Set<string>,
|
|
491
|
+
): string | null {
|
|
492
|
+
if (callee.type === 'Identifier') {
|
|
493
|
+
return styleNames.has(callee.name) ? callee.name : null;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return null;
|
|
497
|
+
|
|
498
|
+
const object = callee.object;
|
|
499
|
+
|
|
500
|
+
if (object.type === 'Identifier') {
|
|
501
|
+
return styleNames.has(object.name) ? object.name : null;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (object.type === 'CallExpression') {
|
|
505
|
+
return getStyleChainRootName(object.callee, styleNames);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (object.type === 'MemberExpression') {
|
|
509
|
+
return getStyleChainRootName(object, styleNames);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function getSelectorMethodName(
|
|
516
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
517
|
+
) {
|
|
518
|
+
const node = getSelectorMethodNode(callee);
|
|
519
|
+
return node?.type === 'Identifier' ? node.name : null;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function getSelectorMethodNode(
|
|
523
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
524
|
+
) {
|
|
525
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return null;
|
|
526
|
+
return callee.property.type === 'Identifier' ? callee.property : null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function getSelectorMethodPath(
|
|
530
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
531
|
+
) {
|
|
532
|
+
const callee = path.get('callee');
|
|
533
|
+
if (!callee.isMemberExpression()) return null;
|
|
534
|
+
|
|
535
|
+
const property = callee.get('property');
|
|
536
|
+
if (Array.isArray(property)) return null;
|
|
537
|
+
if (!property.isIdentifier()) return null;
|
|
538
|
+
|
|
539
|
+
return property;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function getDebugStyleArg(
|
|
543
|
+
t: typeof BabelTypes,
|
|
544
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
545
|
+
state: PluginState,
|
|
546
|
+
sourcemapTrace: SourcemapTrace,
|
|
547
|
+
) {
|
|
548
|
+
const arg = getStyleObjectArg(path, state);
|
|
549
|
+
if (!arg) return arg;
|
|
550
|
+
|
|
551
|
+
if (arg.type !== 'ObjectExpression') {
|
|
552
|
+
return resolveDebugMergeObject(t, arg, path, state, sourcemapTrace) ?? arg;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
return flattenDebugObjectExpression(
|
|
556
|
+
t,
|
|
557
|
+
arg,
|
|
558
|
+
path,
|
|
559
|
+
state,
|
|
560
|
+
sourcemapTrace,
|
|
561
|
+
new Set(),
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function getDebugCallLoc(
|
|
566
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
567
|
+
state: PluginState,
|
|
568
|
+
) {
|
|
569
|
+
return (isSelectorStyleCall(path, state) || isScopeItemSelectorCall(path, state))
|
|
570
|
+
? getMergeStyleLoc(path.node.callee)
|
|
571
|
+
: null;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function getStyleObjectArg(
|
|
575
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
576
|
+
state: PluginState,
|
|
577
|
+
) {
|
|
578
|
+
const methodName = getSelectorMethodName(path.node.callee);
|
|
579
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
580
|
+
const selector = methodName && rootName
|
|
581
|
+
? state.styleMetas.get(rootName)?.selectors[methodName]
|
|
582
|
+
: null;
|
|
583
|
+
|
|
584
|
+
if (!selector) return path.node.arguments[0];
|
|
585
|
+
|
|
586
|
+
const selectorArgIndex = getSelectorArgIndex(selector, path.node.arguments as BabelTypes.Node[]);
|
|
587
|
+
const styleArgIndex = selectorArgIndex === null ? 0 : selectorArgIndex + 1;
|
|
588
|
+
|
|
589
|
+
return path.node.arguments[styleArgIndex];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function isSelectorStyleCall(
|
|
593
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
594
|
+
state: PluginState,
|
|
595
|
+
) {
|
|
596
|
+
const methodName = getSelectorMethodName(path.node.callee);
|
|
597
|
+
if (!methodName) return false;
|
|
598
|
+
|
|
599
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
600
|
+
if (!rootName) return false;
|
|
601
|
+
|
|
602
|
+
return !!state.styleMetas.get(rootName)?.selectors[methodName];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function resolveDebugMergeObject(
|
|
606
|
+
t: typeof BabelTypes,
|
|
607
|
+
arg: BabelTypes.Node,
|
|
608
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
609
|
+
state: PluginState,
|
|
610
|
+
sourcemapTrace: SourcemapTrace,
|
|
611
|
+
) {
|
|
612
|
+
if (!isMergeSelectorCall(path.node.callee, state) && !isScopeItemMergeCall(path, state)) return null;
|
|
613
|
+
|
|
614
|
+
const loc = getMergeStyleLoc(path.node.callee);
|
|
615
|
+
if (sourcemapTrace === 'style' && !loc) return null;
|
|
616
|
+
|
|
617
|
+
const localSource = resolveStyleDebugObject(t, arg, path, state, sourcemapTrace, new Set());
|
|
618
|
+
const source = (localSource?.properties.length ? localSource : null) ??
|
|
619
|
+
resolveImportedMergeDebugObject(t, arg, loc, state, sourcemapTrace);
|
|
620
|
+
if (!source) return null;
|
|
621
|
+
|
|
622
|
+
return createTraceDebugObject(t, source, loc ?? arg.loc?.start ?? null, sourcemapTrace);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function isScopeItemMergeCall(
|
|
626
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
627
|
+
state: PluginState,
|
|
628
|
+
) {
|
|
629
|
+
return getSelectorMethodName(path.node.callee) === FN_STYLE_MERGE && isScopeItemCall(path, state);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function isScopeItemSelectorCall(
|
|
633
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
634
|
+
state: PluginState,
|
|
635
|
+
) {
|
|
636
|
+
const callee = path.node.callee;
|
|
637
|
+
return callee.type === 'MemberExpression' &&
|
|
638
|
+
callee.object.type === 'CallExpression' &&
|
|
639
|
+
isScopeItemCall(path, state);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function resolveImportedMergeDebugObject(
|
|
643
|
+
t: typeof BabelTypes,
|
|
644
|
+
arg: BabelTypes.Node,
|
|
645
|
+
loc: BabelTypes.SourceLocation['start'] | null,
|
|
646
|
+
state: PluginState,
|
|
647
|
+
sourcemapTrace: SourcemapTrace,
|
|
648
|
+
) {
|
|
649
|
+
if (arg.type !== 'Identifier') return null;
|
|
650
|
+
|
|
651
|
+
const evaluated = evaluateNode(arg, getDebugEvalScope(state));
|
|
652
|
+
if (!evaluated.ok || (!isStyleData(evaluated.value) && !isScopeData(evaluated.value))) return null;
|
|
653
|
+
|
|
654
|
+
const locations = (evaluated.value as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
655
|
+
if (locations) {
|
|
656
|
+
return createLocationDebugObject(t, locations, loc, state, sourcemapTrace);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return createStyleDataDebugObject(
|
|
660
|
+
t,
|
|
661
|
+
evaluated.value[BUILDER_STATE].items,
|
|
662
|
+
loc,
|
|
663
|
+
state,
|
|
664
|
+
sourcemapTrace,
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function isScopeMergeCall(
|
|
669
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
670
|
+
state: PluginState,
|
|
671
|
+
) {
|
|
672
|
+
const methodName = getSelectorMethodName(callee);
|
|
673
|
+
if (!methodName) return false;
|
|
674
|
+
|
|
675
|
+
const rootName = getStyleChainRootName(callee, state.styleNames);
|
|
676
|
+
if (!rootName) return false;
|
|
677
|
+
|
|
678
|
+
const selector = state.styleMetas.get(rootName)?.selectors[methodName];
|
|
679
|
+
return selector?.selector.trim() === SELECTOR_MERGE && isScopeChainCall(callee, state.styleNames);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function isMergeSelectorCall(
|
|
683
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
684
|
+
state: PluginState,
|
|
685
|
+
) {
|
|
686
|
+
const methodName = getSelectorMethodName(callee);
|
|
687
|
+
if (!methodName) return false;
|
|
688
|
+
|
|
689
|
+
const rootName = getStyleChainRootName(callee, state.styleNames);
|
|
690
|
+
if (!rootName) return false;
|
|
691
|
+
|
|
692
|
+
return state.styleMetas.get(rootName)?.selectors[methodName]?.selector.trim() === SELECTOR_MERGE;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function getMergeStyleLoc(callee: BabelTypes.CallExpression['callee']) {
|
|
696
|
+
const node = getSelectorMethodNode(callee);
|
|
697
|
+
return node?.loc?.start ?? callee.loc?.start ?? null;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function resolveStyleDebugObject(
|
|
701
|
+
t: typeof BabelTypes,
|
|
702
|
+
node: BabelTypes.Node,
|
|
703
|
+
path: NodePath,
|
|
704
|
+
state: PluginState,
|
|
705
|
+
sourcemapTrace: SourcemapTrace,
|
|
706
|
+
seen: Set<string>,
|
|
707
|
+
): BabelTypes.ObjectExpression | null {
|
|
708
|
+
if (node.type === 'Identifier') {
|
|
709
|
+
if (seen.has(node.name)) return null;
|
|
710
|
+
|
|
711
|
+
const binding = path.scope.getBinding(node.name);
|
|
712
|
+
const init = binding?.path.isVariableDeclarator()
|
|
713
|
+
? binding.path.node.init
|
|
714
|
+
: null;
|
|
715
|
+
|
|
716
|
+
if (!init) return null;
|
|
717
|
+
|
|
718
|
+
seen.add(node.name);
|
|
719
|
+
try {
|
|
720
|
+
return resolveStyleDebugObject(t, init, path, state, sourcemapTrace, seen);
|
|
721
|
+
} finally {
|
|
722
|
+
seen.delete(node.name);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
if (node.type === 'ArrayExpression') {
|
|
727
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
728
|
+
|
|
729
|
+
for (const element of node.elements) {
|
|
730
|
+
if (!element || element.type === 'SpreadElement') continue;
|
|
731
|
+
|
|
732
|
+
const resolved = resolveStyleDebugObject(t, element, path, state, sourcemapTrace, seen);
|
|
733
|
+
if (resolved) properties.push(...resolved.properties);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return properties.length ? t.objectExpression(properties) : null;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (node.type !== 'CallExpression') return null;
|
|
740
|
+
|
|
741
|
+
if (
|
|
742
|
+
isStyleUtilityCall(node.callee, state.styleNames) &&
|
|
743
|
+
node.arguments[0]?.type === 'ObjectExpression'
|
|
744
|
+
) {
|
|
745
|
+
return flattenDebugObjectExpression(
|
|
746
|
+
t,
|
|
747
|
+
node.arguments[0],
|
|
748
|
+
path,
|
|
749
|
+
state,
|
|
750
|
+
sourcemapTrace,
|
|
751
|
+
seen,
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (!isStyleChainCall(node.callee, state.styleNames)) return null;
|
|
756
|
+
|
|
757
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
758
|
+
collectStyleChainDebugProperties(t, node, path, state, sourcemapTrace, seen, properties);
|
|
759
|
+
|
|
760
|
+
return properties.length ? t.objectExpression(properties) : null;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function collectStyleChainDebugProperties(
|
|
764
|
+
t: typeof BabelTypes,
|
|
765
|
+
node: BabelTypes.CallExpression,
|
|
766
|
+
path: NodePath,
|
|
767
|
+
state: PluginState,
|
|
768
|
+
sourcemapTrace: SourcemapTrace,
|
|
769
|
+
seen: Set<string>,
|
|
770
|
+
properties: BabelTypes.ObjectExpression['properties'],
|
|
771
|
+
) {
|
|
772
|
+
const callee = node.callee;
|
|
773
|
+
|
|
774
|
+
if (callee.type === 'MemberExpression' && callee.object.type === 'CallExpression') {
|
|
775
|
+
collectStyleChainDebugProperties(
|
|
776
|
+
t,
|
|
777
|
+
callee.object,
|
|
778
|
+
path,
|
|
779
|
+
state,
|
|
780
|
+
sourcemapTrace,
|
|
781
|
+
seen,
|
|
782
|
+
properties,
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
const arg = node.arguments[0];
|
|
787
|
+
if (!arg) return;
|
|
788
|
+
|
|
789
|
+
if (arg.type === 'ObjectExpression') {
|
|
790
|
+
const flattened = flattenDebugObjectExpression(t, arg, path, state, sourcemapTrace, seen);
|
|
791
|
+
properties.push(...flattened.properties);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (isMergeSelectorCall(callee, state)) {
|
|
796
|
+
const merged = resolveStyleDebugObject(t, arg, path, state, sourcemapTrace, seen);
|
|
797
|
+
if (merged) properties.push(...merged.properties);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function flattenDebugObjectExpression(
|
|
802
|
+
t: typeof BabelTypes,
|
|
803
|
+
node: BabelTypes.ObjectExpression,
|
|
804
|
+
path: NodePath,
|
|
805
|
+
state: PluginState,
|
|
806
|
+
sourcemapTrace: SourcemapTrace,
|
|
807
|
+
seen: Set<string>,
|
|
808
|
+
) {
|
|
809
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
810
|
+
|
|
811
|
+
for (const property of node.properties) {
|
|
812
|
+
if (property.type !== 'SpreadElement') {
|
|
813
|
+
properties.push(property);
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const resolved = resolveDebugSpreadObject(
|
|
818
|
+
t,
|
|
819
|
+
property,
|
|
820
|
+
path,
|
|
821
|
+
state,
|
|
822
|
+
sourcemapTrace,
|
|
823
|
+
seen,
|
|
824
|
+
);
|
|
825
|
+
|
|
826
|
+
if (resolved) {
|
|
827
|
+
properties.push(...resolved.properties);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
return t.objectExpression(properties);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function resolveDebugSpreadObject(
|
|
835
|
+
t: typeof BabelTypes,
|
|
836
|
+
spread: BabelTypes.SpreadElement,
|
|
837
|
+
path: NodePath,
|
|
838
|
+
state: PluginState,
|
|
839
|
+
sourcemapTrace: SourcemapTrace,
|
|
840
|
+
seen: Set<string>,
|
|
841
|
+
) {
|
|
842
|
+
const node = spread.argument;
|
|
843
|
+
if (node.type !== 'Identifier') return null;
|
|
844
|
+
if (seen.has(node.name)) return null;
|
|
845
|
+
|
|
846
|
+
const binding = path.scope.getBinding(node.name);
|
|
847
|
+
const init = binding?.path.isVariableDeclarator()
|
|
848
|
+
? binding.path.node.init
|
|
849
|
+
: null;
|
|
850
|
+
|
|
851
|
+
if (!init) {
|
|
852
|
+
return resolveImportedDebugSpreadObject(t, node, spread, state, sourcemapTrace);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
seen.add(node.name);
|
|
856
|
+
|
|
857
|
+
try {
|
|
858
|
+
if (init.type === 'ObjectExpression') {
|
|
859
|
+
return createSpreadDebugObject(t, init, spread, sourcemapTrace);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
if (
|
|
863
|
+
init.type === 'CallExpression' &&
|
|
864
|
+
isStyleUtilityCall(init.callee, state.styleNames) &&
|
|
865
|
+
init.arguments[0]?.type === 'ObjectExpression'
|
|
866
|
+
) {
|
|
867
|
+
return createSpreadDebugObject(t, init.arguments[0], spread, sourcemapTrace);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
return null;
|
|
871
|
+
} finally {
|
|
872
|
+
seen.delete(node.name);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function resolveImportedDebugSpreadObject(
|
|
877
|
+
t: typeof BabelTypes,
|
|
878
|
+
node: BabelTypes.Identifier,
|
|
879
|
+
spread: BabelTypes.SpreadElement,
|
|
880
|
+
state: PluginState,
|
|
881
|
+
sourcemapTrace: SourcemapTrace,
|
|
882
|
+
) {
|
|
883
|
+
const evaluated = evaluateNode(node, getDebugEvalScope(state));
|
|
884
|
+
if (!evaluated.ok || !evaluated.value || typeof evaluated.value !== 'object') return null;
|
|
885
|
+
|
|
886
|
+
const locations = (evaluated.value as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
887
|
+
if (!locations) return null;
|
|
888
|
+
|
|
889
|
+
return createLocationDebugObject(t, locations, spread.loc?.start ?? null, state, sourcemapTrace);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function createLocationDebugObject(
|
|
893
|
+
t: typeof BabelTypes,
|
|
894
|
+
locations: CompiledStyleObjectLocations,
|
|
895
|
+
styleLoc: BabelTypes.SourceLocation['start'] | null,
|
|
896
|
+
state: PluginState,
|
|
897
|
+
sourcemapTrace: SourcemapTrace,
|
|
898
|
+
) {
|
|
899
|
+
if (sourcemapTrace === 'style' && !styleLoc) return null;
|
|
900
|
+
|
|
901
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
902
|
+
|
|
903
|
+
for (const [key, loc] of Object.entries(locations)) {
|
|
904
|
+
const valueLoc = {
|
|
905
|
+
line: loc.line,
|
|
906
|
+
column: Math.max(loc.column - 1, 0),
|
|
907
|
+
} as BabelTypes.SourceLocation['start'];
|
|
908
|
+
const propertyLoc = sourcemapTrace === 'style' && styleLoc ? styleLoc : valueLoc;
|
|
909
|
+
const property = t.objectProperty(t.stringLiteral(key), t.nullLiteral()) as DebugTraceProperty;
|
|
910
|
+
|
|
911
|
+
property.loc = {
|
|
912
|
+
start: propertyLoc,
|
|
913
|
+
end: propertyLoc,
|
|
914
|
+
} as BabelTypes.SourceLocation;
|
|
915
|
+
|
|
916
|
+
if (styleLoc) {
|
|
917
|
+
property.__styleSourcemapStyleLoc = styleLoc;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
property.__styleSourcemapValueLoc = valueLoc;
|
|
921
|
+
|
|
922
|
+
if (loc.filePath && loc.filePath !== state.filePath) {
|
|
923
|
+
property.__styleSourcemapValueSourceUrl = getDebugSourceUrl(
|
|
924
|
+
loc.filePath,
|
|
925
|
+
loc.filePath,
|
|
926
|
+
state.projectDir,
|
|
927
|
+
state.options,
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
properties.push(property);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
return t.objectExpression(properties);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function createStyleDataDebugObject(
|
|
938
|
+
t: typeof BabelTypes,
|
|
939
|
+
items: readonly unknown[],
|
|
940
|
+
styleLoc: BabelTypes.SourceLocation['start'] | null,
|
|
941
|
+
state: PluginState,
|
|
942
|
+
sourcemapTrace: SourcemapTrace,
|
|
943
|
+
) {
|
|
944
|
+
if (sourcemapTrace === 'style' && !styleLoc) return null;
|
|
945
|
+
|
|
946
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
947
|
+
|
|
948
|
+
for (const item of items) {
|
|
949
|
+
if (Array.isArray(item) || !item || typeof item !== 'object') continue;
|
|
950
|
+
|
|
951
|
+
const runtimeItem = item as RuntimeItem;
|
|
952
|
+
const key = runtimeItem.property;
|
|
953
|
+
const valueLoc = getRuntimeItemValueLoc(runtimeItem);
|
|
954
|
+
if (!key || !valueLoc) continue;
|
|
955
|
+
|
|
956
|
+
const propertyLoc = sourcemapTrace === 'style' && styleLoc
|
|
957
|
+
? styleLoc
|
|
958
|
+
: debugLocToSourceLoc(valueLoc);
|
|
959
|
+
const property = t.objectProperty(t.stringLiteral(key), t.nullLiteral()) as DebugTraceProperty;
|
|
960
|
+
|
|
961
|
+
property.loc = {
|
|
962
|
+
start: propertyLoc,
|
|
963
|
+
end: propertyLoc,
|
|
964
|
+
} as BabelTypes.SourceLocation;
|
|
965
|
+
|
|
966
|
+
if (styleLoc) {
|
|
967
|
+
property.__styleSourcemapStyleLoc = styleLoc;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
property.__styleSourcemapValueLoc = debugLocToSourceLoc(valueLoc);
|
|
971
|
+
property.__styleSourcemapValueSourceUrl = valueLoc[3] || runtimeItem.debug?.sourceUrl;
|
|
972
|
+
|
|
973
|
+
properties.push(property);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
return properties.length ? t.objectExpression(properties) : null;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function getRuntimeItemValueLoc(item: RuntimeItem): DebugLoc | null {
|
|
980
|
+
if (item.debug && item.debugField) {
|
|
981
|
+
const loc = item.debug.fields?.[item.debugField];
|
|
982
|
+
if (Array.isArray(loc)) return withDebugSource(loc, item.debug.sourceUrl, item.debug.code);
|
|
983
|
+
if (loc) {
|
|
984
|
+
const valueLoc = loc[TRACE_VALUE] ?? loc[TRACE_STYLE] ?? null;
|
|
985
|
+
return valueLoc ? withDebugSource(valueLoc, item.debug.sourceUrl, item.debug.code) : null;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
return item.callsite
|
|
990
|
+
? [item.callsite.line, item.callsite.column, undefined, item.callsite.sourceUrl, item.callsite.sourceContent]
|
|
991
|
+
: null;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function withDebugSource(
|
|
995
|
+
loc: DebugLoc,
|
|
996
|
+
sourceUrl: string,
|
|
997
|
+
sourceContent: string | undefined,
|
|
998
|
+
): DebugLoc {
|
|
999
|
+
return loc[3] ? loc : [loc[0], loc[1], loc[2], sourceUrl, sourceContent];
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function debugLocToSourceLoc(loc: DebugLoc) {
|
|
1003
|
+
return {
|
|
1004
|
+
line: loc[0],
|
|
1005
|
+
column: Math.max(loc[1] - 1, 0),
|
|
1006
|
+
} as BabelTypes.SourceLocation['start'];
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function createSpreadDebugObject(
|
|
1010
|
+
t: typeof BabelTypes,
|
|
1011
|
+
source: BabelTypes.ObjectExpression,
|
|
1012
|
+
spread: BabelTypes.SpreadElement,
|
|
1013
|
+
sourcemapTrace: SourcemapTrace,
|
|
1014
|
+
) {
|
|
1015
|
+
const loc = spread.loc?.start;
|
|
1016
|
+
return createTraceDebugObject(t, source, loc ?? null, sourcemapTrace);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function createTraceDebugObject(
|
|
1020
|
+
t: typeof BabelTypes,
|
|
1021
|
+
source: BabelTypes.ObjectExpression,
|
|
1022
|
+
loc: BabelTypes.SourceLocation['start'] | null,
|
|
1023
|
+
sourcemapTrace: SourcemapTrace,
|
|
1024
|
+
) {
|
|
1025
|
+
if (sourcemapTrace === 'style' && !loc) return null;
|
|
1026
|
+
|
|
1027
|
+
const properties: BabelTypes.ObjectExpression['properties'] = [];
|
|
1028
|
+
|
|
1029
|
+
for (const property of source.properties) {
|
|
1030
|
+
if (property.type === 'SpreadElement') continue;
|
|
1031
|
+
if (property.type !== 'ObjectProperty') continue;
|
|
1032
|
+
if (property.computed) continue;
|
|
1033
|
+
|
|
1034
|
+
const clone = t.cloneNode(property);
|
|
1035
|
+
const sourceProperty = property as DebugTraceProperty;
|
|
1036
|
+
const clonedProperty = clone as DebugTraceProperty;
|
|
1037
|
+
clonedProperty.__styleSourcemapStyleLoc = sourceProperty.__styleSourcemapStyleLoc;
|
|
1038
|
+
clonedProperty.__styleSourcemapStyleSourceUrl = sourceProperty.__styleSourcemapStyleSourceUrl;
|
|
1039
|
+
clonedProperty.__styleSourcemapValueLoc = sourceProperty.__styleSourcemapValueLoc;
|
|
1040
|
+
clonedProperty.__styleSourcemapValueSourceUrl = sourceProperty.__styleSourcemapValueSourceUrl;
|
|
1041
|
+
|
|
1042
|
+
if (loc && !clonedProperty.__styleSourcemapStyleLoc) {
|
|
1043
|
+
clonedProperty.__styleSourcemapStyleLoc = loc;
|
|
1044
|
+
}
|
|
1045
|
+
if (!clonedProperty.__styleSourcemapValueLoc) {
|
|
1046
|
+
clonedProperty.__styleSourcemapValueLoc = property.loc?.start;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
if (sourcemapTrace === 'style' && loc) {
|
|
1050
|
+
clone.loc = {
|
|
1051
|
+
...property.loc,
|
|
1052
|
+
start: loc,
|
|
1053
|
+
} as BabelTypes.SourceLocation;
|
|
1054
|
+
}
|
|
1055
|
+
properties.push(clone);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
return t.objectExpression(properties);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function isStyleUtilityCall(
|
|
1062
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
1063
|
+
styleNames: Set<string>,
|
|
1064
|
+
) {
|
|
1065
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
1066
|
+
if (callee.object.type !== 'Identifier' || !styleNames.has(callee.object.name)) return false;
|
|
1067
|
+
if (callee.property.type !== 'Identifier') return false;
|
|
1068
|
+
|
|
1069
|
+
return callee.property.name === FN_STYLE_RAW ||
|
|
1070
|
+
callee.property.name === FN_STYLE_PLAIN ||
|
|
1071
|
+
callee.property.name === FN_STYLE_KEYFRAMES ||
|
|
1072
|
+
callee.property.name === FN_STYLE_MERGE;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function isScopeItemCall(
|
|
1076
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
1077
|
+
state: PluginState,
|
|
1078
|
+
) {
|
|
1079
|
+
if (!isScopeItemValueCall(path.node, state.styleNames)) return false;
|
|
1080
|
+
|
|
1081
|
+
if (isInsideScopeCallArg(path, state.styleNames)) return true;
|
|
1082
|
+
|
|
1083
|
+
const declarator = getEnclosingVariableDeclarator(path);
|
|
1084
|
+
if (!declarator || declarator.node.id.type !== 'Identifier') return false;
|
|
1085
|
+
|
|
1086
|
+
if (isExportedVariableDeclarator(declarator)) return true;
|
|
1087
|
+
if (isExportedBindingName(declarator, declarator.node.id.name)) return true;
|
|
1088
|
+
|
|
1089
|
+
const binding = declarator.scope.getBinding(declarator.node.id.name);
|
|
1090
|
+
if (!binding) return false;
|
|
1091
|
+
|
|
1092
|
+
return isBindingUsedInScopeArg(binding, state.styleNames, new Set());
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function isScopeItemValueCall(
|
|
1096
|
+
node: BabelTypes.CallExpression,
|
|
1097
|
+
styleNames: Set<string>,
|
|
1098
|
+
) {
|
|
1099
|
+
if (isStyleChainCall(node.callee, styleNames)) return true;
|
|
1100
|
+
|
|
1101
|
+
return node.callee.type === 'MemberExpression' ||
|
|
1102
|
+
node.callee.type === 'Identifier';
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function isInsideScopeCallArg(
|
|
1106
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
1107
|
+
styleNames: Set<string>,
|
|
1108
|
+
) {
|
|
1109
|
+
let current: NodePath | null = path.parentPath;
|
|
1110
|
+
|
|
1111
|
+
while (current) {
|
|
1112
|
+
if (current.isCallExpression() && isScopeChainCall(current.node.callee, styleNames)) {
|
|
1113
|
+
return isDescendantOfCallArgument(path, current);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
if (current.isStatement()) return false;
|
|
1117
|
+
|
|
1118
|
+
current = current.parentPath;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
return false;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function isBindingUsedInScopeArg(
|
|
1125
|
+
binding: BabelBinding,
|
|
1126
|
+
styleNames: Set<string>,
|
|
1127
|
+
seen: Set<string>,
|
|
1128
|
+
): boolean {
|
|
1129
|
+
if (seen.has(binding.identifier.name)) return false;
|
|
1130
|
+
seen.add(binding.identifier.name);
|
|
1131
|
+
|
|
1132
|
+
return binding.referencePaths.some((referencePath) => {
|
|
1133
|
+
if (isReferenceInsideScopeArg(referencePath, styleNames)) return true;
|
|
1134
|
+
|
|
1135
|
+
const declarator = getEnclosingVariableDeclarator(referencePath);
|
|
1136
|
+
if (!declarator || declarator.node.id.type !== 'Identifier') return false;
|
|
1137
|
+
|
|
1138
|
+
const nextBinding = declarator.scope.getBinding(declarator.node.id.name);
|
|
1139
|
+
return nextBinding
|
|
1140
|
+
? isBindingUsedInScopeArg(nextBinding, styleNames, seen)
|
|
1141
|
+
: false;
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
function isReferenceInsideScopeArg(
|
|
1146
|
+
path: NodePath,
|
|
1147
|
+
styleNames: Set<string>,
|
|
1148
|
+
) {
|
|
1149
|
+
let current: NodePath | null = path.parentPath;
|
|
1150
|
+
|
|
1151
|
+
while (current) {
|
|
1152
|
+
if (current.isCallExpression() && isScopeChainCall(current.node.callee, styleNames)) {
|
|
1153
|
+
return isDescendantOfCallArgument(path, current);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
if (current.isStatement()) return false;
|
|
1157
|
+
|
|
1158
|
+
current = current.parentPath;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
function isDescendantOfCallArgument(
|
|
1165
|
+
child: NodePath,
|
|
1166
|
+
parent: NodePath<BabelTypes.CallExpression>,
|
|
1167
|
+
) {
|
|
1168
|
+
let current: NodePath | null = child;
|
|
1169
|
+
let previous: NodePath | null = null;
|
|
1170
|
+
|
|
1171
|
+
while (current && current !== parent) {
|
|
1172
|
+
previous = current;
|
|
1173
|
+
current = current.parentPath;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
if (current !== parent || !previous) return false;
|
|
1177
|
+
|
|
1178
|
+
return parent.get('arguments').some((argPath) => argPath === previous);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function getEnclosingVariableDeclarator(
|
|
1182
|
+
path: NodePath,
|
|
1183
|
+
) {
|
|
1184
|
+
let current: NodePath | null = path;
|
|
1185
|
+
|
|
1186
|
+
while (current && !current.isStatement()) {
|
|
1187
|
+
if (current.isVariableDeclarator()) return current;
|
|
1188
|
+
current = current.parentPath;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function isExportedVariableDeclarator(
|
|
1195
|
+
declarator: NodePath<BabelTypes.VariableDeclarator>,
|
|
1196
|
+
) {
|
|
1197
|
+
const declaration = declarator.parentPath;
|
|
1198
|
+
return declaration?.isVariableDeclaration() &&
|
|
1199
|
+
declaration.parentPath?.isExportNamedDeclaration();
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function isExportedBindingName(
|
|
1203
|
+
declarator: NodePath<BabelTypes.VariableDeclarator>,
|
|
1204
|
+
name: string,
|
|
1205
|
+
) {
|
|
1206
|
+
const program = declarator.findParent((parent) => parent.isProgram());
|
|
1207
|
+
if (!program?.isProgram()) return false;
|
|
1208
|
+
|
|
1209
|
+
return program.node.body.some((statement) => {
|
|
1210
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source) return false;
|
|
1211
|
+
|
|
1212
|
+
return statement.specifiers.some((specifier) => {
|
|
1213
|
+
return specifier.type === 'ExportSpecifier' &&
|
|
1214
|
+
specifier.local.type === 'Identifier' &&
|
|
1215
|
+
specifier.local.name === name;
|
|
1216
|
+
});
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
function isScopeChainCall(
|
|
1221
|
+
callee: BabelTypes.CallExpression['callee'],
|
|
1222
|
+
styleNames: Set<string>,
|
|
1223
|
+
): boolean {
|
|
1224
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
1225
|
+
|
|
1226
|
+
const object = callee.object;
|
|
1227
|
+
const property = callee.property;
|
|
1228
|
+
|
|
1229
|
+
if (
|
|
1230
|
+
object.type === 'Identifier' &&
|
|
1231
|
+
styleNames.has(object.name) &&
|
|
1232
|
+
property.type === 'Identifier' &&
|
|
1233
|
+
property.name === FN_STYLE_SCOPE
|
|
1234
|
+
) {
|
|
1235
|
+
return true;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
if (object.type === 'CallExpression') {
|
|
1239
|
+
return isScopeChainCall(object.callee, styleNames);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
if (object.type === 'MemberExpression') {
|
|
1243
|
+
return isScopeChainCall(object, styleNames);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
return false;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
function getSourceUrlId(
|
|
1250
|
+
t: typeof BabelTypes,
|
|
1251
|
+
state: PluginState,
|
|
1252
|
+
) {
|
|
1253
|
+
if (state.sourceUrlId) return t.cloneNode(state.sourceUrlId);
|
|
1254
|
+
if (!state.programPath) return t.stringLiteral('');
|
|
1255
|
+
|
|
1256
|
+
state.sourceUrlId = state.programPath.scope.generateUidIdentifier(DEBUG_SOURCE_URL_VAR);
|
|
1257
|
+
|
|
1258
|
+
return t.cloneNode(state.sourceUrlId);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
function getSourceContentId(
|
|
1262
|
+
t: typeof BabelTypes,
|
|
1263
|
+
state: PluginState,
|
|
1264
|
+
) {
|
|
1265
|
+
if (state.sourceContentId) return t.cloneNode(state.sourceContentId);
|
|
1266
|
+
if (!state.programPath) return null;
|
|
1267
|
+
|
|
1268
|
+
state.sourceContentId = state.programPath.scope.generateUidIdentifier(DEBUG_SOURCE_CONTENT_VAR);
|
|
1269
|
+
|
|
1270
|
+
return t.cloneNode(state.sourceContentId);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function insertDebugDeclarations(
|
|
1274
|
+
t: typeof BabelTypes,
|
|
1275
|
+
programPath: NodePath<BabelTypes.Program>,
|
|
1276
|
+
state: PluginState,
|
|
1277
|
+
sourceUrl: string,
|
|
1278
|
+
sourceContent: string | null,
|
|
1279
|
+
) {
|
|
1280
|
+
const declarations: BabelTypes.Statement[] = [];
|
|
1281
|
+
|
|
1282
|
+
if (state.sourceUrlId) {
|
|
1283
|
+
declarations.push(createDebugSourceDeclaration(
|
|
1284
|
+
t,
|
|
1285
|
+
state.sourceUrlId,
|
|
1286
|
+
sourceUrl,
|
|
1287
|
+
state.sourceContentId,
|
|
1288
|
+
sourceContent,
|
|
1289
|
+
));
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
if (!declarations.length) return;
|
|
1293
|
+
|
|
1294
|
+
const bodyPaths = programPath.get('body');
|
|
1295
|
+
const insertAt = getSourceContentInsertIndex(bodyPaths);
|
|
1296
|
+
|
|
1297
|
+
if (insertAt >= bodyPaths.length) {
|
|
1298
|
+
programPath.pushContainer('body', declarations);
|
|
1299
|
+
} else {
|
|
1300
|
+
bodyPaths[insertAt].insertBefore(declarations);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
function createDebugSourceDeclaration(
|
|
1305
|
+
t: typeof BabelTypes,
|
|
1306
|
+
sourceUrlId: BabelTypes.Identifier,
|
|
1307
|
+
sourceUrl: string,
|
|
1308
|
+
sourceContentId: BabelTypes.Identifier | null,
|
|
1309
|
+
sourceContent: string | null,
|
|
1310
|
+
) {
|
|
1311
|
+
const declarators = [
|
|
1312
|
+
t.variableDeclarator(
|
|
1313
|
+
t.cloneNode(sourceUrlId),
|
|
1314
|
+
t.stringLiteral(sourceUrl),
|
|
1315
|
+
),
|
|
1316
|
+
];
|
|
1317
|
+
|
|
1318
|
+
if (sourceContentId && sourceContent) {
|
|
1319
|
+
declarators.push(
|
|
1320
|
+
t.variableDeclarator(
|
|
1321
|
+
t.cloneNode(sourceContentId),
|
|
1322
|
+
t.stringLiteral(sourceContent),
|
|
1323
|
+
),
|
|
1324
|
+
);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
return t.variableDeclaration('const', declarators);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function getSourceContentInsertIndex(
|
|
1331
|
+
bodyPaths: NodePath<BabelTypes.Statement>[],
|
|
1332
|
+
) {
|
|
1333
|
+
let index = 0;
|
|
1334
|
+
|
|
1335
|
+
for (; index < bodyPaths.length; index++) {
|
|
1336
|
+
const node = bodyPaths[index].node;
|
|
1337
|
+
if (!isDirectiveStatement(node) && node.type !== 'ImportDeclaration') break;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
return index;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function isDirectiveStatement(node: BabelTypes.Statement) {
|
|
1344
|
+
return node.type === 'ExpressionStatement' &&
|
|
1345
|
+
node.expression.type === 'StringLiteral' &&
|
|
1346
|
+
typeof (node as BabelTypes.ExpressionStatement & { directive?: string; }).directive === 'string';
|
|
1347
|
+
}
|