@jesscss/core 2.0.0-alpha.4 → 2.0.0-alpha.6
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/lib/index.cjs +20159 -0
- package/lib/index.d.cts +5993 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.ts +5992 -21
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19926 -22
- package/lib/index.js.map +1 -1
- package/package.json +15 -14
- package/src/__tests__/define-function-record.test.ts +58 -0
- package/src/__tests__/define-function-simple.test.ts +55 -0
- package/src/__tests__/define-function-split-sequence.test.ts +547 -0
- package/src/__tests__/define-function-type-parity.test.ts +9 -0
- package/src/__tests__/define-function.test.ts +763 -0
- package/src/__tests__/num-operations.test.ts +91 -0
- package/src/__tests__/safe-parse.test.ts +374 -0
- package/src/context.ts +896 -0
- package/src/conversions.ts +282 -0
- package/src/debug-log.ts +29 -0
- package/src/define-function.ts +1006 -0
- package/src/deprecation.ts +67 -0
- package/src/globals.d.ts +26 -0
- package/src/index.ts +31 -0
- package/src/jess-error.ts +773 -0
- package/src/logger/deprecation-processing.ts +109 -0
- package/src/logger.ts +31 -0
- package/src/plugin.ts +292 -0
- package/src/tree/LOOKUP_CHAINS.md +35 -0
- package/src/tree/README.md +18 -0
- package/src/tree/__tests__/__snapshots__/extend-eval-integration.test.ts.snap +1455 -0
- package/src/tree/__tests__/ampersand.test.ts +382 -0
- package/src/tree/__tests__/at-rule.test.ts +2047 -0
- package/src/tree/__tests__/basic-render.test.ts +212 -0
- package/src/tree/__tests__/block.test.ts +40 -0
- package/src/tree/__tests__/call.test.ts +346 -0
- package/src/tree/__tests__/color.test.ts +537 -0
- package/src/tree/__tests__/condition.test.ts +186 -0
- package/src/tree/__tests__/control.test.ts +564 -0
- package/src/tree/__tests__/declaration.test.ts +253 -0
- package/src/tree/__tests__/dependency-graph.test.ts +177 -0
- package/src/tree/__tests__/detached-rulesets.test.ts +213 -0
- package/src/tree/__tests__/dimension.test.ts +236 -0
- package/src/tree/__tests__/expression.test.ts +73 -0
- package/src/tree/__tests__/ext-node.test.ts +31 -0
- package/src/tree/__tests__/extend-eval-integration.test.ts +1033 -0
- package/src/tree/__tests__/extend-import-style.test.ts +929 -0
- package/src/tree/__tests__/extend-less-fixtures.test.ts +851 -0
- package/src/tree/__tests__/extend-list.test.ts +31 -0
- package/src/tree/__tests__/extend-roots.test.ts +1045 -0
- package/src/tree/__tests__/extend-rules.test.ts +740 -0
- package/src/tree/__tests__/func.test.ts +171 -0
- package/src/tree/__tests__/import-js.test.ts +33 -0
- package/src/tree/__tests__/import-style-test-helpers.ts +56 -0
- package/src/tree/__tests__/import-style.test.ts +1967 -0
- package/src/tree/__tests__/interpolated-reference.test.ts +44 -0
- package/src/tree/__tests__/interpolated.test.ts +41 -0
- package/src/tree/__tests__/list.test.ts +177 -0
- package/src/tree/__tests__/log.test.ts +83 -0
- package/src/tree/__tests__/mixin-recursion.test.ts +639 -0
- package/src/tree/__tests__/mixin.test.ts +2171 -0
- package/src/tree/__tests__/negative.test.ts +45 -0
- package/src/tree/__tests__/nesting-collapse.test.ts +519 -0
- package/src/tree/__tests__/node-flags-perf.test.ts +195 -0
- package/src/tree/__tests__/node-flags.test.ts +410 -0
- package/src/tree/__tests__/node-graph.test.ts +598 -0
- package/src/tree/__tests__/node-mutation.test.ts +182 -0
- package/src/tree/__tests__/operation.test.ts +18 -0
- package/src/tree/__tests__/paren.test.ts +90 -0
- package/src/tree/__tests__/preserve-mode-output.test.ts +50 -0
- package/src/tree/__tests__/quoted.test.ts +72 -0
- package/src/tree/__tests__/range.test.ts +59 -0
- package/src/tree/__tests__/reference.test.ts +743 -0
- package/src/tree/__tests__/rest.test.ts +29 -0
- package/src/tree/__tests__/rules-raw.test.ts +14 -0
- package/src/tree/__tests__/rules.test.ts +1271 -0
- package/src/tree/__tests__/ruleset.test.ts +597 -0
- package/src/tree/__tests__/selector-attr.test.ts +50 -0
- package/src/tree/__tests__/selector-basic.test.ts +44 -0
- package/src/tree/__tests__/selector-capture.test.ts +22 -0
- package/src/tree/__tests__/selector-complex.test.ts +120 -0
- package/src/tree/__tests__/selector-compound.test.ts +74 -0
- package/src/tree/__tests__/selector-interpolated.test.ts +50 -0
- package/src/tree/__tests__/selector-list.test.ts +59 -0
- package/src/tree/__tests__/selector-pseudo.test.ts +23 -0
- package/src/tree/__tests__/selector.test.ts +182 -0
- package/src/tree/__tests__/sequence.test.ts +226 -0
- package/src/tree/__tests__/serialize-types.test.ts +529 -0
- package/src/tree/__tests__/spaced.test.ts +8 -0
- package/src/tree/__tests__/url.test.ts +72 -0
- package/src/tree/__tests__/var-declaration.test.ts +90 -0
- package/src/tree/ampersand.ts +538 -0
- package/src/tree/any.ts +169 -0
- package/src/tree/at-rule.ts +760 -0
- package/src/tree/block.ts +72 -0
- package/src/tree/bool.ts +46 -0
- package/src/tree/call.ts +593 -0
- package/src/tree/collection.ts +52 -0
- package/src/tree/color.ts +629 -0
- package/src/tree/combinator.ts +30 -0
- package/src/tree/comment.ts +36 -0
- package/src/tree/condition.ts +194 -0
- package/src/tree/control.ts +452 -0
- package/src/tree/declaration-custom.ts +56 -0
- package/src/tree/declaration-var.ts +87 -0
- package/src/tree/declaration.ts +742 -0
- package/src/tree/default-guard.ts +35 -0
- package/src/tree/dimension.ts +392 -0
- package/src/tree/expression.ts +97 -0
- package/src/tree/extend-list.ts +51 -0
- package/src/tree/extend.ts +391 -0
- package/src/tree/function.ts +254 -0
- package/src/tree/import-js.ts +130 -0
- package/src/tree/import-style.ts +875 -0
- package/{lib/tree/index.js → src/tree/index.ts} +49 -22
- package/src/tree/interpolated.ts +346 -0
- package/src/tree/js-array.ts +21 -0
- package/src/tree/js-expr.ts +50 -0
- package/src/tree/js-function.ts +31 -0
- package/src/tree/js-object.ts +22 -0
- package/src/tree/list.ts +415 -0
- package/src/tree/log.ts +89 -0
- package/src/tree/mixin.ts +331 -0
- package/src/tree/negative.ts +58 -0
- package/src/tree/nil.ts +57 -0
- package/src/tree/node-base.ts +1716 -0
- package/src/tree/node-type.ts +122 -0
- package/src/tree/node.ts +118 -0
- package/src/tree/number.ts +54 -0
- package/src/tree/operation.ts +187 -0
- package/src/tree/paren.ts +132 -0
- package/src/tree/query-condition.ts +47 -0
- package/src/tree/quoted.ts +119 -0
- package/src/tree/range.ts +101 -0
- package/src/tree/reference.ts +1099 -0
- package/src/tree/rest.ts +55 -0
- package/src/tree/rules-raw.ts +52 -0
- package/src/tree/rules.ts +2896 -0
- package/src/tree/ruleset.ts +1217 -0
- package/src/tree/selector-attr.ts +172 -0
- package/src/tree/selector-basic.ts +75 -0
- package/src/tree/selector-capture.ts +85 -0
- package/src/tree/selector-complex.ts +189 -0
- package/src/tree/selector-compound.ts +205 -0
- package/src/tree/selector-interpolated.ts +95 -0
- package/src/tree/selector-list.ts +245 -0
- package/src/tree/selector-pseudo.ts +173 -0
- package/src/tree/selector-simple.ts +10 -0
- package/src/tree/selector.ts +152 -0
- package/src/tree/sequence.ts +463 -0
- package/src/tree/tree.ts +130 -0
- package/src/tree/url.ts +95 -0
- package/src/tree/util/EXTEND_ARCHITECTURE_ANALYSIS.md +215 -0
- package/src/tree/util/EXTEND_AUDIT.md +233 -0
- package/src/tree/util/EXTEND_BASELINE.md +64 -0
- package/src/tree/util/EXTEND_CALL_GRAPH_ANALYSIS.md +244 -0
- package/src/tree/util/EXTEND_DOCS.md +24 -0
- package/src/tree/util/EXTEND_FINAL_SUMMARY.md +95 -0
- package/src/tree/util/EXTEND_FUNCTION_AUDIT.md +1433 -0
- package/src/tree/util/EXTEND_OPTIMIZATION_PLAN.md +114 -0
- package/src/tree/util/EXTEND_REFACTORING_SUMMARY.md +152 -0
- package/src/tree/util/EXTEND_RULES.md +74 -0
- package/src/tree/util/EXTEND_UNUSED_FUNCTIONS.md +127 -0
- package/src/tree/util/EXTEND_UNUSED_FUNCTIONS_ANALYSIS.md +227 -0
- package/src/tree/util/NODE_COPY_REDUCTION_PLAN.md +12 -0
- package/src/tree/util/__tests__/EXTEND_TEST_INDEX.md +59 -0
- package/src/tree/util/__tests__/OPTIMIZATION-ANALYSIS.md +130 -0
- package/src/tree/util/__tests__/WALK_AND_CONSUME_DESIGN.md +138 -0
- package/src/tree/util/__tests__/_archive/2026-02-09__OPTIMIZATION-ANALYSIS.md +9 -0
- package/src/tree/util/__tests__/_archive/README.md +4 -0
- package/src/tree/util/__tests__/bitset.test.ts +142 -0
- package/src/tree/util/__tests__/debug-log.ts +50 -0
- package/src/tree/util/__tests__/extend-comment-handling.test.ts +187 -0
- package/src/tree/util/__tests__/extend-core-unit.test.ts +941 -0
- package/src/tree/util/__tests__/extend-pipeline-bench.test.ts +154 -0
- package/src/tree/util/__tests__/extend-pipeline-bench.ts +190 -0
- package/src/tree/util/__tests__/fast-reject.test.ts +377 -0
- package/src/tree/util/__tests__/is-node.test.ts +63 -0
- package/src/tree/util/__tests__/list-like.test.ts +63 -0
- package/src/tree/util/__tests__/outputwriter.test.ts +523 -0
- package/src/tree/util/__tests__/print.test.ts +183 -0
- package/src/tree/util/__tests__/process-extends.test.ts +226 -0
- package/src/tree/util/__tests__/process-leading-is.test.ts +205 -0
- package/src/tree/util/__tests__/recursion-helper.test.ts +184 -0
- package/src/tree/util/__tests__/selector-match-unit.test.ts +1427 -0
- package/src/tree/util/__tests__/sourcemap.test.ts +117 -0
- package/src/tree/util/ampersand-template.ts +9 -0
- package/src/tree/util/bitset.ts +194 -0
- package/src/tree/util/calculate.ts +11 -0
- package/src/tree/util/cast.ts +89 -0
- package/src/tree/util/cloning.ts +8 -0
- package/src/tree/util/collections.ts +299 -0
- package/src/tree/util/compare.ts +90 -0
- package/src/tree/util/cursor.ts +171 -0
- package/src/tree/util/extend-core.ts +2139 -0
- package/src/tree/util/extend-roots.ts +1108 -0
- package/src/tree/util/field-helpers.ts +354 -0
- package/src/tree/util/is-node.ts +43 -0
- package/src/tree/util/list-like.ts +93 -0
- package/src/tree/util/mixin-instance-primitives.ts +2020 -0
- package/src/tree/util/print.ts +303 -0
- package/src/tree/util/process-leading-is.ts +421 -0
- package/src/tree/util/recursion-helper.ts +54 -0
- package/src/tree/util/regex.ts +2 -0
- package/src/tree/util/registry-utils.ts +1953 -0
- package/src/tree/util/ruleset-trace.ts +17 -0
- package/src/tree/util/scoped-body-eval.ts +320 -0
- package/src/tree/util/selector-match-core.ts +2005 -0
- package/src/tree/util/selector-utils.ts +757 -0
- package/src/tree/util/serialize-helper.ts +535 -0
- package/src/tree/util/serialize-types.ts +318 -0
- package/src/tree/util/should-operate.ts +78 -0
- package/src/tree/util/sourcemap.ts +37 -0
- package/src/types/config.ts +247 -0
- package/src/types/index.ts +12 -0
- package/{lib/types/modes.d.ts → src/types/modes.ts} +2 -1
- package/src/types.d.ts +9 -0
- package/src/types.ts +68 -0
- package/src/use-webpack-resolver.ts +56 -0
- package/src/visitor/__tests__/visitor.test.ts +136 -0
- package/src/visitor/index.ts +263 -0
- package/{lib/visitor/less-visitor.js → src/visitor/less-visitor.ts} +3 -2
- package/lib/context.d.ts +0 -352
- package/lib/context.d.ts.map +0 -1
- package/lib/context.js +0 -636
- package/lib/context.js.map +0 -1
- package/lib/conversions.d.ts +0 -73
- package/lib/conversions.d.ts.map +0 -1
- package/lib/conversions.js +0 -253
- package/lib/conversions.js.map +0 -1
- package/lib/debug-log.d.ts +0 -2
- package/lib/debug-log.d.ts.map +0 -1
- package/lib/debug-log.js +0 -27
- package/lib/debug-log.js.map +0 -1
- package/lib/define-function.d.ts +0 -587
- package/lib/define-function.d.ts.map +0 -1
- package/lib/define-function.js +0 -726
- package/lib/define-function.js.map +0 -1
- package/lib/deprecation.d.ts +0 -34
- package/lib/deprecation.d.ts.map +0 -1
- package/lib/deprecation.js +0 -57
- package/lib/deprecation.js.map +0 -1
- package/lib/jess-error.d.ts +0 -343
- package/lib/jess-error.d.ts.map +0 -1
- package/lib/jess-error.js +0 -508
- package/lib/jess-error.js.map +0 -1
- package/lib/logger/deprecation-processing.d.ts +0 -41
- package/lib/logger/deprecation-processing.d.ts.map +0 -1
- package/lib/logger/deprecation-processing.js +0 -81
- package/lib/logger/deprecation-processing.js.map +0 -1
- package/lib/logger.d.ts +0 -10
- package/lib/logger.d.ts.map +0 -1
- package/lib/logger.js +0 -20
- package/lib/logger.js.map +0 -1
- package/lib/plugin.d.ts +0 -94
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -174
- package/lib/plugin.js.map +0 -1
- package/lib/tree/ampersand.d.ts +0 -94
- package/lib/tree/ampersand.d.ts.map +0 -1
- package/lib/tree/ampersand.js +0 -269
- package/lib/tree/ampersand.js.map +0 -1
- package/lib/tree/any.d.ts +0 -58
- package/lib/tree/any.d.ts.map +0 -1
- package/lib/tree/any.js +0 -104
- package/lib/tree/any.js.map +0 -1
- package/lib/tree/at-rule.d.ts +0 -53
- package/lib/tree/at-rule.d.ts.map +0 -1
- package/lib/tree/at-rule.js +0 -503
- package/lib/tree/at-rule.js.map +0 -1
- package/lib/tree/block.d.ts +0 -22
- package/lib/tree/block.d.ts.map +0 -1
- package/lib/tree/block.js +0 -24
- package/lib/tree/block.js.map +0 -1
- package/lib/tree/bool.d.ts +0 -18
- package/lib/tree/bool.d.ts.map +0 -1
- package/lib/tree/bool.js +0 -28
- package/lib/tree/bool.js.map +0 -1
- package/lib/tree/call.d.ts +0 -66
- package/lib/tree/call.d.ts.map +0 -1
- package/lib/tree/call.js +0 -306
- package/lib/tree/call.js.map +0 -1
- package/lib/tree/collection.d.ts +0 -30
- package/lib/tree/collection.d.ts.map +0 -1
- package/lib/tree/collection.js +0 -37
- package/lib/tree/collection.js.map +0 -1
- package/lib/tree/color.d.ts +0 -101
- package/lib/tree/color.d.ts.map +0 -1
- package/lib/tree/color.js +0 -513
- package/lib/tree/color.js.map +0 -1
- package/lib/tree/combinator.d.ts +0 -13
- package/lib/tree/combinator.d.ts.map +0 -1
- package/lib/tree/combinator.js +0 -12
- package/lib/tree/combinator.js.map +0 -1
- package/lib/tree/comment.d.ts +0 -20
- package/lib/tree/comment.d.ts.map +0 -1
- package/lib/tree/comment.js +0 -19
- package/lib/tree/comment.js.map +0 -1
- package/lib/tree/condition.d.ts +0 -31
- package/lib/tree/condition.d.ts.map +0 -1
- package/lib/tree/condition.js +0 -103
- package/lib/tree/condition.js.map +0 -1
- package/lib/tree/control.d.ts +0 -104
- package/lib/tree/control.d.ts.map +0 -1
- package/lib/tree/control.js +0 -430
- package/lib/tree/control.js.map +0 -1
- package/lib/tree/declaration-custom.d.ts +0 -18
- package/lib/tree/declaration-custom.d.ts.map +0 -1
- package/lib/tree/declaration-custom.js +0 -24
- package/lib/tree/declaration-custom.js.map +0 -1
- package/lib/tree/declaration-var.d.ts +0 -35
- package/lib/tree/declaration-var.d.ts.map +0 -1
- package/lib/tree/declaration-var.js +0 -63
- package/lib/tree/declaration-var.js.map +0 -1
- package/lib/tree/declaration.d.ts +0 -78
- package/lib/tree/declaration.d.ts.map +0 -1
- package/lib/tree/declaration.js +0 -286
- package/lib/tree/declaration.js.map +0 -1
- package/lib/tree/default-guard.d.ts +0 -15
- package/lib/tree/default-guard.d.ts.map +0 -1
- package/lib/tree/default-guard.js +0 -19
- package/lib/tree/default-guard.js.map +0 -1
- package/lib/tree/dimension.d.ts +0 -34
- package/lib/tree/dimension.d.ts.map +0 -1
- package/lib/tree/dimension.js +0 -294
- package/lib/tree/dimension.js.map +0 -1
- package/lib/tree/expression.d.ts +0 -25
- package/lib/tree/expression.d.ts.map +0 -1
- package/lib/tree/expression.js +0 -32
- package/lib/tree/expression.js.map +0 -1
- package/lib/tree/extend-list.d.ts +0 -23
- package/lib/tree/extend-list.d.ts.map +0 -1
- package/lib/tree/extend-list.js +0 -23
- package/lib/tree/extend-list.js.map +0 -1
- package/lib/tree/extend.d.ts +0 -47
- package/lib/tree/extend.d.ts.map +0 -1
- package/lib/tree/extend.js +0 -296
- package/lib/tree/extend.js.map +0 -1
- package/lib/tree/function.d.ts +0 -48
- package/lib/tree/function.d.ts.map +0 -1
- package/lib/tree/function.js +0 -74
- package/lib/tree/function.js.map +0 -1
- package/lib/tree/import-js.d.ts +0 -35
- package/lib/tree/import-js.d.ts.map +0 -1
- package/lib/tree/import-js.js +0 -45
- package/lib/tree/import-js.js.map +0 -1
- package/lib/tree/import-style.d.ts +0 -156
- package/lib/tree/import-style.d.ts.map +0 -1
- package/lib/tree/import-style.js +0 -566
- package/lib/tree/import-style.js.map +0 -1
- package/lib/tree/index.d.ts +0 -71
- package/lib/tree/index.d.ts.map +0 -1
- package/lib/tree/index.js.map +0 -1
- package/lib/tree/interpolated-reference.d.ts +0 -24
- package/lib/tree/interpolated-reference.d.ts.map +0 -1
- package/lib/tree/interpolated-reference.js +0 -37
- package/lib/tree/interpolated-reference.js.map +0 -1
- package/lib/tree/interpolated.d.ts +0 -62
- package/lib/tree/interpolated.d.ts.map +0 -1
- package/lib/tree/interpolated.js +0 -204
- package/lib/tree/interpolated.js.map +0 -1
- package/lib/tree/js-array.d.ts +0 -10
- package/lib/tree/js-array.d.ts.map +0 -1
- package/lib/tree/js-array.js +0 -10
- package/lib/tree/js-array.js.map +0 -1
- package/lib/tree/js-expr.d.ts +0 -23
- package/lib/tree/js-expr.d.ts.map +0 -1
- package/lib/tree/js-expr.js +0 -28
- package/lib/tree/js-expr.js.map +0 -1
- package/lib/tree/js-function.d.ts +0 -20
- package/lib/tree/js-function.d.ts.map +0 -1
- package/lib/tree/js-function.js +0 -16
- package/lib/tree/js-function.js.map +0 -1
- package/lib/tree/js-object.d.ts +0 -10
- package/lib/tree/js-object.d.ts.map +0 -1
- package/lib/tree/js-object.js +0 -10
- package/lib/tree/js-object.js.map +0 -1
- package/lib/tree/list.d.ts +0 -38
- package/lib/tree/list.d.ts.map +0 -1
- package/lib/tree/list.js +0 -83
- package/lib/tree/list.js.map +0 -1
- package/lib/tree/log.d.ts +0 -29
- package/lib/tree/log.d.ts.map +0 -1
- package/lib/tree/log.js +0 -56
- package/lib/tree/log.js.map +0 -1
- package/lib/tree/mixin.d.ts +0 -87
- package/lib/tree/mixin.d.ts.map +0 -1
- package/lib/tree/mixin.js +0 -112
- package/lib/tree/mixin.js.map +0 -1
- package/lib/tree/negative.d.ts +0 -17
- package/lib/tree/negative.d.ts.map +0 -1
- package/lib/tree/negative.js +0 -22
- package/lib/tree/negative.js.map +0 -1
- package/lib/tree/nil.d.ts +0 -30
- package/lib/tree/nil.d.ts.map +0 -1
- package/lib/tree/nil.js +0 -35
- package/lib/tree/nil.js.map +0 -1
- package/lib/tree/node-base.d.ts +0 -361
- package/lib/tree/node-base.d.ts.map +0 -1
- package/lib/tree/node-base.js +0 -930
- package/lib/tree/node-base.js.map +0 -1
- package/lib/tree/node.d.ts +0 -10
- package/lib/tree/node.d.ts.map +0 -1
- package/lib/tree/node.js +0 -45
- package/lib/tree/node.js.map +0 -1
- package/lib/tree/number.d.ts +0 -21
- package/lib/tree/number.d.ts.map +0 -1
- package/lib/tree/number.js +0 -27
- package/lib/tree/number.js.map +0 -1
- package/lib/tree/operation.d.ts +0 -26
- package/lib/tree/operation.d.ts.map +0 -1
- package/lib/tree/operation.js +0 -103
- package/lib/tree/operation.js.map +0 -1
- package/lib/tree/paren.d.ts +0 -19
- package/lib/tree/paren.d.ts.map +0 -1
- package/lib/tree/paren.js +0 -92
- package/lib/tree/paren.js.map +0 -1
- package/lib/tree/query-condition.d.ts +0 -17
- package/lib/tree/query-condition.d.ts.map +0 -1
- package/lib/tree/query-condition.js +0 -39
- package/lib/tree/query-condition.js.map +0 -1
- package/lib/tree/quoted.d.ts +0 -28
- package/lib/tree/quoted.d.ts.map +0 -1
- package/lib/tree/quoted.js +0 -75
- package/lib/tree/quoted.js.map +0 -1
- package/lib/tree/range.d.ts +0 -33
- package/lib/tree/range.d.ts.map +0 -1
- package/lib/tree/range.js +0 -47
- package/lib/tree/range.js.map +0 -1
- package/lib/tree/reference.d.ts +0 -76
- package/lib/tree/reference.d.ts.map +0 -1
- package/lib/tree/reference.js +0 -521
- package/lib/tree/reference.js.map +0 -1
- package/lib/tree/rest.d.ts +0 -15
- package/lib/tree/rest.d.ts.map +0 -1
- package/lib/tree/rest.js +0 -32
- package/lib/tree/rest.js.map +0 -1
- package/lib/tree/rules-raw.d.ts +0 -17
- package/lib/tree/rules-raw.d.ts.map +0 -1
- package/lib/tree/rules-raw.js +0 -37
- package/lib/tree/rules-raw.js.map +0 -1
- package/lib/tree/rules.d.ts +0 -262
- package/lib/tree/rules.d.ts.map +0 -1
- package/lib/tree/rules.js +0 -2359
- package/lib/tree/rules.js.map +0 -1
- package/lib/tree/ruleset.d.ts +0 -92
- package/lib/tree/ruleset.d.ts.map +0 -1
- package/lib/tree/ruleset.js +0 -528
- package/lib/tree/ruleset.js.map +0 -1
- package/lib/tree/selector-attr.d.ts +0 -31
- package/lib/tree/selector-attr.d.ts.map +0 -1
- package/lib/tree/selector-attr.js +0 -99
- package/lib/tree/selector-attr.js.map +0 -1
- package/lib/tree/selector-basic.d.ts +0 -24
- package/lib/tree/selector-basic.d.ts.map +0 -1
- package/lib/tree/selector-basic.js +0 -38
- package/lib/tree/selector-basic.js.map +0 -1
- package/lib/tree/selector-capture.d.ts +0 -23
- package/lib/tree/selector-capture.d.ts.map +0 -1
- package/lib/tree/selector-capture.js +0 -34
- package/lib/tree/selector-capture.js.map +0 -1
- package/lib/tree/selector-complex.d.ts +0 -40
- package/lib/tree/selector-complex.d.ts.map +0 -1
- package/lib/tree/selector-complex.js +0 -143
- package/lib/tree/selector-complex.js.map +0 -1
- package/lib/tree/selector-compound.d.ts +0 -16
- package/lib/tree/selector-compound.d.ts.map +0 -1
- package/lib/tree/selector-compound.js +0 -114
- package/lib/tree/selector-compound.js.map +0 -1
- package/lib/tree/selector-interpolated.d.ts +0 -23
- package/lib/tree/selector-interpolated.d.ts.map +0 -1
- package/lib/tree/selector-interpolated.js +0 -27
- package/lib/tree/selector-interpolated.js.map +0 -1
- package/lib/tree/selector-list.d.ts +0 -17
- package/lib/tree/selector-list.d.ts.map +0 -1
- package/lib/tree/selector-list.js +0 -174
- package/lib/tree/selector-list.js.map +0 -1
- package/lib/tree/selector-pseudo.d.ts +0 -42
- package/lib/tree/selector-pseudo.d.ts.map +0 -1
- package/lib/tree/selector-pseudo.js +0 -204
- package/lib/tree/selector-pseudo.js.map +0 -1
- package/lib/tree/selector-simple.d.ts +0 -5
- package/lib/tree/selector-simple.d.ts.map +0 -1
- package/lib/tree/selector-simple.js +0 -6
- package/lib/tree/selector-simple.js.map +0 -1
- package/lib/tree/selector.d.ts +0 -43
- package/lib/tree/selector.d.ts.map +0 -1
- package/lib/tree/selector.js +0 -56
- package/lib/tree/selector.js.map +0 -1
- package/lib/tree/sequence.d.ts +0 -43
- package/lib/tree/sequence.d.ts.map +0 -1
- package/lib/tree/sequence.js +0 -151
- package/lib/tree/sequence.js.map +0 -1
- package/lib/tree/tree.d.ts +0 -87
- package/lib/tree/tree.d.ts.map +0 -1
- package/lib/tree/tree.js +0 -2
- package/lib/tree/tree.js.map +0 -1
- package/lib/tree/url.d.ts +0 -18
- package/lib/tree/url.d.ts.map +0 -1
- package/lib/tree/url.js +0 -35
- package/lib/tree/url.js.map +0 -1
- package/lib/tree/util/__tests__/debug-log.d.ts +0 -1
- package/lib/tree/util/__tests__/debug-log.d.ts.map +0 -1
- package/lib/tree/util/__tests__/debug-log.js +0 -36
- package/lib/tree/util/__tests__/debug-log.js.map +0 -1
- package/lib/tree/util/calculate.d.ts +0 -3
- package/lib/tree/util/calculate.d.ts.map +0 -1
- package/lib/tree/util/calculate.js +0 -10
- package/lib/tree/util/calculate.js.map +0 -1
- package/lib/tree/util/cast.d.ts +0 -10
- package/lib/tree/util/cast.d.ts.map +0 -1
- package/lib/tree/util/cast.js +0 -87
- package/lib/tree/util/cast.js.map +0 -1
- package/lib/tree/util/cloning.d.ts +0 -4
- package/lib/tree/util/cloning.d.ts.map +0 -1
- package/lib/tree/util/cloning.js +0 -8
- package/lib/tree/util/cloning.js.map +0 -1
- package/lib/tree/util/collections.d.ts +0 -57
- package/lib/tree/util/collections.d.ts.map +0 -1
- package/lib/tree/util/collections.js +0 -136
- package/lib/tree/util/collections.js.map +0 -1
- package/lib/tree/util/compare.d.ts +0 -11
- package/lib/tree/util/compare.d.ts.map +0 -1
- package/lib/tree/util/compare.js +0 -89
- package/lib/tree/util/compare.js.map +0 -1
- package/lib/tree/util/extend-helpers.d.ts +0 -2
- package/lib/tree/util/extend-helpers.d.ts.map +0 -1
- package/lib/tree/util/extend-helpers.js +0 -2
- package/lib/tree/util/extend-helpers.js.map +0 -1
- package/lib/tree/util/extend-roots.d.ts +0 -37
- package/lib/tree/util/extend-roots.d.ts.map +0 -1
- package/lib/tree/util/extend-roots.js +0 -700
- package/lib/tree/util/extend-roots.js.map +0 -1
- package/lib/tree/util/extend-roots.old.d.ts +0 -132
- package/lib/tree/util/extend-roots.old.d.ts.map +0 -1
- package/lib/tree/util/extend-roots.old.js +0 -2272
- package/lib/tree/util/extend-roots.old.js.map +0 -1
- package/lib/tree/util/extend-trace-debug.d.ts +0 -13
- package/lib/tree/util/extend-trace-debug.d.ts.map +0 -1
- package/lib/tree/util/extend-trace-debug.js +0 -34
- package/lib/tree/util/extend-trace-debug.js.map +0 -1
- package/lib/tree/util/extend-walk.d.ts +0 -53
- package/lib/tree/util/extend-walk.d.ts.map +0 -1
- package/lib/tree/util/extend-walk.js +0 -881
- package/lib/tree/util/extend-walk.js.map +0 -1
- package/lib/tree/util/extend.d.ts +0 -218
- package/lib/tree/util/extend.d.ts.map +0 -1
- package/lib/tree/util/extend.js +0 -3182
- package/lib/tree/util/extend.js.map +0 -1
- package/lib/tree/util/find-extendable-locations.d.ts +0 -2
- package/lib/tree/util/find-extendable-locations.d.ts.map +0 -1
- package/lib/tree/util/find-extendable-locations.js +0 -2
- package/lib/tree/util/find-extendable-locations.js.map +0 -1
- package/lib/tree/util/format.d.ts +0 -20
- package/lib/tree/util/format.d.ts.map +0 -1
- package/lib/tree/util/format.js +0 -67
- package/lib/tree/util/format.js.map +0 -1
- package/lib/tree/util/is-node.d.ts +0 -13
- package/lib/tree/util/is-node.d.ts.map +0 -1
- package/lib/tree/util/is-node.js +0 -43
- package/lib/tree/util/is-node.js.map +0 -1
- package/lib/tree/util/print.d.ts +0 -80
- package/lib/tree/util/print.d.ts.map +0 -1
- package/lib/tree/util/print.js +0 -205
- package/lib/tree/util/print.js.map +0 -1
- package/lib/tree/util/process-leading-is.d.ts +0 -25
- package/lib/tree/util/process-leading-is.d.ts.map +0 -1
- package/lib/tree/util/process-leading-is.js +0 -364
- package/lib/tree/util/process-leading-is.js.map +0 -1
- package/lib/tree/util/recursion-helper.d.ts +0 -15
- package/lib/tree/util/recursion-helper.d.ts.map +0 -1
- package/lib/tree/util/recursion-helper.js +0 -43
- package/lib/tree/util/recursion-helper.js.map +0 -1
- package/lib/tree/util/regex.d.ts +0 -4
- package/lib/tree/util/regex.d.ts.map +0 -1
- package/lib/tree/util/regex.js +0 -4
- package/lib/tree/util/regex.js.map +0 -1
- package/lib/tree/util/registry-utils.d.ts +0 -192
- package/lib/tree/util/registry-utils.d.ts.map +0 -1
- package/lib/tree/util/registry-utils.js +0 -1214
- package/lib/tree/util/registry-utils.js.map +0 -1
- package/lib/tree/util/ruleset-trace.d.ts +0 -4
- package/lib/tree/util/ruleset-trace.d.ts.map +0 -1
- package/lib/tree/util/ruleset-trace.js +0 -14
- package/lib/tree/util/ruleset-trace.js.map +0 -1
- package/lib/tree/util/selector-compare.d.ts +0 -2
- package/lib/tree/util/selector-compare.d.ts.map +0 -1
- package/lib/tree/util/selector-compare.js +0 -2
- package/lib/tree/util/selector-compare.js.map +0 -1
- package/lib/tree/util/selector-match-core.d.ts +0 -184
- package/lib/tree/util/selector-match-core.d.ts.map +0 -1
- package/lib/tree/util/selector-match-core.js +0 -1603
- package/lib/tree/util/selector-match-core.js.map +0 -1
- package/lib/tree/util/selector-utils.d.ts +0 -30
- package/lib/tree/util/selector-utils.d.ts.map +0 -1
- package/lib/tree/util/selector-utils.js +0 -100
- package/lib/tree/util/selector-utils.js.map +0 -1
- package/lib/tree/util/serialize-helper.d.ts +0 -13
- package/lib/tree/util/serialize-helper.d.ts.map +0 -1
- package/lib/tree/util/serialize-helper.js +0 -387
- package/lib/tree/util/serialize-helper.js.map +0 -1
- package/lib/tree/util/serialize-types.d.ts +0 -9
- package/lib/tree/util/serialize-types.d.ts.map +0 -1
- package/lib/tree/util/serialize-types.js +0 -216
- package/lib/tree/util/serialize-types.js.map +0 -1
- package/lib/tree/util/should-operate.d.ts +0 -23
- package/lib/tree/util/should-operate.d.ts.map +0 -1
- package/lib/tree/util/should-operate.js +0 -46
- package/lib/tree/util/should-operate.js.map +0 -1
- package/lib/tree/util/sourcemap.d.ts +0 -7
- package/lib/tree/util/sourcemap.d.ts.map +0 -1
- package/lib/tree/util/sourcemap.js +0 -25
- package/lib/tree/util/sourcemap.js.map +0 -1
- package/lib/types/config.d.ts +0 -205
- package/lib/types/config.d.ts.map +0 -1
- package/lib/types/config.js +0 -2
- package/lib/types/config.js.map +0 -1
- package/lib/types/index.d.ts +0 -15
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
- package/lib/types/modes.d.ts.map +0 -1
- package/lib/types/modes.js +0 -2
- package/lib/types/modes.js.map +0 -1
- package/lib/types.d.ts +0 -61
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/use-webpack-resolver.d.ts +0 -9
- package/lib/use-webpack-resolver.d.ts.map +0 -1
- package/lib/use-webpack-resolver.js +0 -41
- package/lib/use-webpack-resolver.js.map +0 -1
- package/lib/visitor/index.d.ts +0 -136
- package/lib/visitor/index.d.ts.map +0 -1
- package/lib/visitor/index.js +0 -135
- package/lib/visitor/index.js.map +0 -1
- package/lib/visitor/less-visitor.d.ts +0 -7
- package/lib/visitor/less-visitor.d.ts.map +0 -1
- package/lib/visitor/less-visitor.js.map +0 -1
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
import { Node, F_MAY_ASYNC, F_NON_STATIC, F_VISIBLE, defineType } from './node.js';
|
|
2
|
+
import { type PrintOptions, getPrintOptions } from './util/print.js';
|
|
3
|
+
import { type Reference } from './reference.js';
|
|
4
|
+
import { Rules, type RulesOptions, type RulesVisibility } from './rules.js';
|
|
5
|
+
import { Quoted } from './quoted.js';
|
|
6
|
+
import { Url } from './url.js';
|
|
7
|
+
import { type Context } from '../context.js';
|
|
8
|
+
import { type MaybePromise } from '@jesscss/awaitable-pipe';
|
|
9
|
+
import { isNode } from './util/is-node.js';
|
|
10
|
+
import { N } from './node-type.js';
|
|
11
|
+
import { getParent, getChildren, setIndex } from './util/field-helpers.js';
|
|
12
|
+
import type { Collection } from './collection.js';
|
|
13
|
+
import { Any } from './any.js';
|
|
14
|
+
import { AtRule } from './at-rule.js';
|
|
15
|
+
import { Sequence } from './sequence.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This class is for Jess / Sass+ / Less-style imports,
|
|
19
|
+
* not the CSS `@import` rule. The two will be distinguished
|
|
20
|
+
* during parsing.
|
|
21
|
+
*
|
|
22
|
+
* @see https://sass-lang.com/documentation/at-rules/import/#plain-css-imports
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export type ImportOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* Affects evaluation - will be passed to registered import handlers when parsing.
|
|
28
|
+
* Normally this is done by file extension, but can be overridden to select a
|
|
29
|
+
* particular plugin handler.
|
|
30
|
+
*
|
|
31
|
+
* e.g. `@-import (type: less) 'foo.css';`
|
|
32
|
+
*/
|
|
33
|
+
type?: string;
|
|
34
|
+
/** Rules are not rendered in output. */
|
|
35
|
+
reference?: boolean;
|
|
36
|
+
optional?: boolean;
|
|
37
|
+
inline?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Optional import postlude captured by parsers for forms like:
|
|
40
|
+
* `@import (inline) "x.css" layer(foo) supports(display: grid) screen;`
|
|
41
|
+
*
|
|
42
|
+
* For inline imports, this is applied as serializer wrappers around the inlined source.
|
|
43
|
+
*/
|
|
44
|
+
postlude?: Node;
|
|
45
|
+
/**
|
|
46
|
+
* Less's default behavior for `@import` is to only output any resolved resource once.
|
|
47
|
+
* In Jess, subsequent imports should output as reference unless the `multiple` option
|
|
48
|
+
* is set to true.
|
|
49
|
+
*
|
|
50
|
+
* @todo - Investigate what Sass does.
|
|
51
|
+
*/
|
|
52
|
+
multiple?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Allow extends to reach into this import.
|
|
55
|
+
* Default is false for @-compose (protected by default), true for @-import.
|
|
56
|
+
*/
|
|
57
|
+
mutable?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Sass `@forward` semantics:
|
|
60
|
+
* - members are NOT visible to the current stylesheet scope
|
|
61
|
+
* - members ARE made available downstream when this stylesheet is imported
|
|
62
|
+
*/
|
|
63
|
+
forward?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Sass `@forward ... as <prefix>-*;` prefixing.
|
|
66
|
+
* Stores the prefix portion (e.g. `bar-` from `bar-*`).
|
|
67
|
+
*/
|
|
68
|
+
forwardAsPrefix?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Sass `@forward ... show ...;` list.
|
|
71
|
+
* We capture raw member names (e.g. `$a`, `mixin-b`, `fn-c`) without semantics yet.
|
|
72
|
+
*/
|
|
73
|
+
forwardShow?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Sass `@forward ... hide ...;` list.
|
|
76
|
+
* We capture raw member names (e.g. `$a`, `mixin-b`, `fn-c`) without semantics yet.
|
|
77
|
+
*/
|
|
78
|
+
forwardHide?: string[];
|
|
79
|
+
/** Variables can't be reassigned (default is true for `@-compose` and false for `@-import`). */
|
|
80
|
+
readonly?: boolean;
|
|
81
|
+
/** Internal marker for "once" de-duplication rendering semantics. */
|
|
82
|
+
_dedupe?: boolean;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type StyleImportOptions = {
|
|
87
|
+
/**
|
|
88
|
+
* Old-style `@import` type or new `@-compose` type.
|
|
89
|
+
*/
|
|
90
|
+
type: 'import' | 'compose';
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Options passed to the Jess import plugin. Options are interpreted like
|
|
94
|
+
* querystring parameters i.e.
|
|
95
|
+
* e.g. `@-import (foo, bar, baz: 1) 'foo.css';`
|
|
96
|
+
* - foo: true
|
|
97
|
+
* - bar: true
|
|
98
|
+
* - baz: '1'
|
|
99
|
+
*/
|
|
100
|
+
importOptions?: ImportOptions;
|
|
101
|
+
|
|
102
|
+
/** e.g. `import * as foo` sets namespace to `foo` */
|
|
103
|
+
namespace?: string;
|
|
104
|
+
|
|
105
|
+
/** Set on the import node instead of on rules */
|
|
106
|
+
local?: boolean;
|
|
107
|
+
rulesVisibility?: RulesOptions['rulesVisibility'];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type StyleImportValue = {
|
|
111
|
+
path: Quoted | Url;
|
|
112
|
+
|
|
113
|
+
/** The node to inject values from (Reference or Collection). */
|
|
114
|
+
withNode?: Reference | Collection;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* How the injected values are applied.
|
|
118
|
+
* 'set' can be used once per module, 'with' can be used multiple.
|
|
119
|
+
* In Sass, 'set' is called 'with' and 'with' will be parsed as 'set'.
|
|
120
|
+
* e.g.
|
|
121
|
+
* `@-use 'library' set { $foo: 1 };` -- $foo will be set to 1 every time
|
|
122
|
+
* `@-use 'library' with { $foo: 1 };` -- $foo will be set to 1 just for this scope.
|
|
123
|
+
*/
|
|
124
|
+
withType?: 'with' | 'set';
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type StyleImportChildData = {
|
|
128
|
+
path: Quoted | Url;
|
|
129
|
+
withNode: Reference | Collection | undefined;
|
|
130
|
+
withType: 'with' | 'set' | undefined;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export interface StyleImport extends Node<StyleImportValue, StyleImportOptions, StyleImportChildData> {
|
|
134
|
+
type: 'StyleImport';
|
|
135
|
+
shortType: 'style';
|
|
136
|
+
eval(context: Context): MaybePromise<Rules>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isWithRulesNode(value: Node): value is Rules | Collection {
|
|
140
|
+
return isNode(value, N.Rules | N.Collection);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isPlainCssImportPath(finalPath: string, importOptions: ImportOptions | undefined): boolean {
|
|
144
|
+
if (importOptions?.inline === true) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const explicitType = typeof importOptions?.type === 'string'
|
|
148
|
+
? importOptions.type.toLowerCase()
|
|
149
|
+
: undefined;
|
|
150
|
+
if (explicitType === 'css') {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (explicitType === 'less') {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (explicitType) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const normalizedPath = finalPath.split(/[?#]/)[0] ?? finalPath;
|
|
160
|
+
if (/\.less$/i.test(normalizedPath)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return /\.css$/i.test(normalizedPath) || /^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(finalPath);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function materializeCssImportPathNode(
|
|
167
|
+
resolvedPathNode: Quoted | Url,
|
|
168
|
+
finalPath: string,
|
|
169
|
+
context: Context
|
|
170
|
+
): Quoted | Url {
|
|
171
|
+
if (resolvedPathNode instanceof Url) {
|
|
172
|
+
const rawValue = resolvedPathNode.get('value', context);
|
|
173
|
+
const nextValue = isNode(rawValue, N.Quoted)
|
|
174
|
+
? new Quoted(finalPath, {
|
|
175
|
+
quote: rawValue.quote,
|
|
176
|
+
escaped: rawValue.escaped
|
|
177
|
+
}, rawValue.location, rawValue.treeContext)
|
|
178
|
+
: new Any(finalPath, { role: 'urlvalue' }, rawValue.location, rawValue.treeContext);
|
|
179
|
+
return new Url(nextValue, undefined, resolvedPathNode.location, resolvedPathNode.treeContext);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return new Quoted(finalPath, {
|
|
183
|
+
quote: resolvedPathNode.quote,
|
|
184
|
+
escaped: resolvedPathNode.escaped
|
|
185
|
+
}, resolvedPathNode.location, resolvedPathNode.treeContext);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* This is a generic class for:
|
|
189
|
+
* - Sass+ `@use` (for stylesheets)
|
|
190
|
+
* - Jess `@-compose` and Less `@compose`
|
|
191
|
+
* - Less, Sass+, and Jess `@import` / `@-import` that are indicated
|
|
192
|
+
* to be processed by the engine
|
|
193
|
+
*
|
|
194
|
+
* @see https://sass-lang.com/documentation/at-rules/import/
|
|
195
|
+
*/
|
|
196
|
+
export class StyleImport extends Node<StyleImportValue, StyleImportOptions, StyleImportChildData> {
|
|
197
|
+
static override childKeys = ['path', 'withNode'] as const;
|
|
198
|
+
|
|
199
|
+
readonly path!: Quoted | Url;
|
|
200
|
+
readonly withNode: Reference | Collection | undefined;
|
|
201
|
+
private withType: 'with' | 'set' | undefined;
|
|
202
|
+
|
|
203
|
+
override clone(deep?: boolean): this {
|
|
204
|
+
const options = this._meta?.options;
|
|
205
|
+
const newNode: this = Reflect.construct(this.constructor, [
|
|
206
|
+
{
|
|
207
|
+
path: deep ? this.path.clone(deep) : this.path,
|
|
208
|
+
withNode: deep && this.withNode instanceof Node ? this.withNode.clone(deep) : this.withNode,
|
|
209
|
+
withType: this.withType
|
|
210
|
+
},
|
|
211
|
+
options ? { ...options } : undefined,
|
|
212
|
+
this.location,
|
|
213
|
+
this.treeContext
|
|
214
|
+
]);
|
|
215
|
+
newNode.inherit(this);
|
|
216
|
+
return newNode;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
constructor(value: StyleImportValue, options?: StyleImportOptions, location?: any, treeContext?: any) {
|
|
220
|
+
super(value, options, location, treeContext);
|
|
221
|
+
this.path = value.path;
|
|
222
|
+
this.withNode = value.withNode;
|
|
223
|
+
this.withType = value.withType;
|
|
224
|
+
if (this.path instanceof Node) {
|
|
225
|
+
this.adopt(this.path);
|
|
226
|
+
}
|
|
227
|
+
if (this.withNode instanceof Node) {
|
|
228
|
+
this.adopt(this.withNode);
|
|
229
|
+
}
|
|
230
|
+
this.addFlags(F_MAY_ASYNC, F_NON_STATIC);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
override toTrimmedString(options?: PrintOptions): string {
|
|
234
|
+
options = getPrintOptions(options);
|
|
235
|
+
const w = options.writer!;
|
|
236
|
+
const mark = w.mark();
|
|
237
|
+
const path = this.get('path', options.context);
|
|
238
|
+
const { type, namespace, importOptions } = this.options;
|
|
239
|
+
|
|
240
|
+
if (type === 'compose') {
|
|
241
|
+
const keyword = importOptions?.forward ? '@-export' : '@-compose';
|
|
242
|
+
w.add(`${keyword} `);
|
|
243
|
+
} else {
|
|
244
|
+
w.add('@-import ');
|
|
245
|
+
}
|
|
246
|
+
path.toString(options);
|
|
247
|
+
if (namespace) {
|
|
248
|
+
w.add(` as ${namespace}`);
|
|
249
|
+
}
|
|
250
|
+
w.add(';');
|
|
251
|
+
return w.getSince(mark);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** @removal-target — node-copy-reduction: clone(true) on prelude nodes.
|
|
255
|
+
* Prelude should be read from canonical + position patches. */
|
|
256
|
+
private materializePostludePrelude(current: Node, context: Context): {
|
|
257
|
+
atRuleName: '@media' | '@supports' | '@layer';
|
|
258
|
+
prelude: Node;
|
|
259
|
+
} {
|
|
260
|
+
if (isNode(current, N.Call)) {
|
|
261
|
+
const callName = String(current.get('name')).toLowerCase();
|
|
262
|
+
if (callName === 'media' || callName === 'supports' || callName === 'layer') {
|
|
263
|
+
const args = current.get('args')?.get('value') ?? [];
|
|
264
|
+
const prelude = args.length <= 1 ? args[0] : current.get('args');
|
|
265
|
+
if (prelude) {
|
|
266
|
+
return {
|
|
267
|
+
atRuleName: `@${callName}` as '@media' | '@supports' | '@layer',
|
|
268
|
+
prelude: prelude.clone(false, undefined, context)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
atRuleName: '@media',
|
|
276
|
+
prelude: current.clone(false, undefined, context)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private createPlacementRules(rules: Rules, context: Context): Rules {
|
|
281
|
+
const placementRenderKey = context.nextRenderKey();
|
|
282
|
+
return rules.createPlacementWrapper(context, placementRenderKey);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
getFinalRules(evaluatedRules: Rules, context: Context) {
|
|
286
|
+
let { importOptions, type } = this.options;
|
|
287
|
+
const reference = importOptions!.reference;
|
|
288
|
+
const isForward = importOptions!.forward === true;
|
|
289
|
+
// For compose type, default is protected (not mutable). For import type, default is mutable.
|
|
290
|
+
// mutable: false on @import explicitly makes it protected.
|
|
291
|
+
const isProtected = type === 'compose'
|
|
292
|
+
? !importOptions!.mutable // compose: protected unless mutable: true
|
|
293
|
+
: importOptions!.mutable === false; // import: mutable unless explicitly mutable: false
|
|
294
|
+
|
|
295
|
+
let Ruleset: RulesVisibility = 'public';
|
|
296
|
+
let Declaration: RulesVisibility = 'public';
|
|
297
|
+
let Mixin: RulesVisibility = 'public';
|
|
298
|
+
let VarDeclaration: RulesVisibility = 'public';
|
|
299
|
+
|
|
300
|
+
const isImplicitDedupeReference = (
|
|
301
|
+
type === 'import'
|
|
302
|
+
&& importOptions?._dedupe === true
|
|
303
|
+
&& reference !== true
|
|
304
|
+
&& !importOptions?.multiple
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
if (isProtected) {
|
|
308
|
+
Ruleset = 'private';
|
|
309
|
+
} else if (reference || isImplicitDedupeReference) {
|
|
310
|
+
/**
|
|
311
|
+
* Not sure if this is true.
|
|
312
|
+
* They won't be output, but that's not the same as being optional,
|
|
313
|
+
* UNLESS we're extending the word 'optional' to mean "not output".
|
|
314
|
+
*
|
|
315
|
+
* I think what we mean here by "optional" it "not ouptut unless extended".
|
|
316
|
+
* Our test for reference therefore should mimic Less behavior.
|
|
317
|
+
*/
|
|
318
|
+
Ruleset = 'optional';
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Create a rules wrapper so we can set visibility.
|
|
323
|
+
* The inner rules may be static, but the import may
|
|
324
|
+
* have different import settings.
|
|
325
|
+
*
|
|
326
|
+
* For compose type:
|
|
327
|
+
* - Variables and mixins are visible to the direct parent (the file that imports them)
|
|
328
|
+
* - If 'export' flag is set, variables and mixins are also forwarded to downstream stylesheets
|
|
329
|
+
* - The 'local' flag means: visible to direct parent, but not re-exported to parent's parent
|
|
330
|
+
*/
|
|
331
|
+
const isReferenceMode = (
|
|
332
|
+
(type === 'import' && (importOptions?._dedupe === true || reference))
|
|
333
|
+
|| (type === 'compose' && reference)
|
|
334
|
+
);
|
|
335
|
+
const materializeConfiguredComposeChildren = type === 'compose' && this.get('withNode', context) != null;
|
|
336
|
+
// Every import placement gets its own render-owned Rules wrapper so the same
|
|
337
|
+
// source module can be imported multiple times without clone-driven cleanup.
|
|
338
|
+
const out = evaluatedRules.sourceNode === this
|
|
339
|
+
? evaluatedRules
|
|
340
|
+
: evaluatedRules.createPlacementWrapper(context, context.nextRenderKey());
|
|
341
|
+
if (materializeConfiguredComposeChildren) {
|
|
342
|
+
const placementContext: Context = { ...context, renderKey: out.renderKey, rulesContext: out };
|
|
343
|
+
const children = getChildren(out, placementContext);
|
|
344
|
+
for (let i = 0; i < children.length; i++) {
|
|
345
|
+
setIndex(children[i]!, i, placementContext);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// Import type: variables are visible and re-exported (not local)
|
|
349
|
+
// Compose type: variables are visible to parent but not transitive by default (`local: true`)
|
|
350
|
+
// Forward: not visible locally but *is* transitive (`local: false`)
|
|
351
|
+
const isLocal = type === 'compose' && !isForward;
|
|
352
|
+
|
|
353
|
+
out.options = {
|
|
354
|
+
rulesVisibility: { Ruleset, Declaration, Mixin, VarDeclaration },
|
|
355
|
+
local: isLocal,
|
|
356
|
+
forward: isForward,
|
|
357
|
+
referenceMode: isReferenceMode,
|
|
358
|
+
referenceRenderOnExtend: reference === true,
|
|
359
|
+
readonly: importOptions!.readonly ?? (type === 'compose' ? true : false)
|
|
360
|
+
};
|
|
361
|
+
// Forwarded modules should never render output at this scope.
|
|
362
|
+
if (isForward) {
|
|
363
|
+
out.removeFlag(F_VISIBLE);
|
|
364
|
+
}
|
|
365
|
+
// Set sourceNode so variable lookups know they can cross import boundaries
|
|
366
|
+
out.sourceNode = this;
|
|
367
|
+
this.adopt(out, context);
|
|
368
|
+
return out;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Defer import-path interpolation to evalNode so unresolved vars can be retried
|
|
373
|
+
* after later imports/assignments in the same Rules scope have evaluated.
|
|
374
|
+
*/
|
|
375
|
+
override preEval(_context: Context): MaybePromise<this> {
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @note
|
|
381
|
+
* When imports are evaluated, they should be deeply cloned. The reason is that
|
|
382
|
+
* they can be used in multiple places, and can be evaluated differently
|
|
383
|
+
* each time, so they are more like a function call.
|
|
384
|
+
*
|
|
385
|
+
* @todo
|
|
386
|
+
* How do extends work then?
|
|
387
|
+
*/
|
|
388
|
+
override evalNode(context: Context): MaybePromise<Rules> {
|
|
389
|
+
let node = this;
|
|
390
|
+
const path = node.get('path', context);
|
|
391
|
+
const withNode = node.get('withNode', context);
|
|
392
|
+
const withType = node.get('withType', context);
|
|
393
|
+
let withValues = withNode != null ? { node: withNode, type: withType! } : undefined;
|
|
394
|
+
const { options } = node;
|
|
395
|
+
options.importOptions ??= {};
|
|
396
|
+
const { type, importOptions } = options;
|
|
397
|
+
let maybePath;
|
|
398
|
+
try {
|
|
399
|
+
maybePath = path.eval(context);
|
|
400
|
+
} catch (e: any) {
|
|
401
|
+
// Tag path-resolution errors so the eval-queue retry policy can
|
|
402
|
+
// distinguish "path interpolation not ready" (cheap, worth retrying)
|
|
403
|
+
// from "content evaluation failed" (expensive clone, not worth retrying).
|
|
404
|
+
e._isPathResolutionError = true;
|
|
405
|
+
throw e;
|
|
406
|
+
}
|
|
407
|
+
let originalDepth = context.depth;
|
|
408
|
+
context.depth = this.depth;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @todo - Add options
|
|
412
|
+
*
|
|
413
|
+
* Note that the Less plugin should trigger a unique default behavior
|
|
414
|
+
* for `@import` which is that it is de-duplicated by default. Meaning
|
|
415
|
+
* that it won't render rulesets twice per compilation. I think that
|
|
416
|
+
* means that it's just kind of ignored without an explicit `multiple`
|
|
417
|
+
* option. Since all vars are global per compilation, it should just
|
|
418
|
+
* work.
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
const finalize = async (finalPath: string, resolvedPathNode: Quoted | Url) => {
|
|
422
|
+
const previousTreeContext = context.treeContext;
|
|
423
|
+
// Inherit "reference branch" semantics lexically for nested imports unless
|
|
424
|
+
// `multiple` explicitly opts into fresh output.
|
|
425
|
+
const inheritedReferenceMode = context.inReferenceImportScope;
|
|
426
|
+
const previousExplicitReference = importOptions!.reference;
|
|
427
|
+
let pushedImportScope = false;
|
|
428
|
+
if (inheritedReferenceMode && !importOptions!.multiple) {
|
|
429
|
+
importOptions!.reference = true;
|
|
430
|
+
}
|
|
431
|
+
if (node.treeContext?.file) {
|
|
432
|
+
context.treeContext = node.treeContext;
|
|
433
|
+
}
|
|
434
|
+
if (importOptions!.multiple || importOptions!.reference) {
|
|
435
|
+
// Scope push/pop is intentionally paired in this method's try/finally.
|
|
436
|
+
// This keeps branch semantics local to this import evaluation path.
|
|
437
|
+
context.pushImportScope({
|
|
438
|
+
multiple: importOptions!.multiple === true,
|
|
439
|
+
reference: importOptions!.reference === true
|
|
440
|
+
});
|
|
441
|
+
pushedImportScope = true;
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
const isInlineImport = importOptions!.inline === true;
|
|
445
|
+
let rules: Rules;
|
|
446
|
+
let resolvedPath: string;
|
|
447
|
+
if (type === 'import' && isPlainCssImportPath(finalPath, importOptions)) {
|
|
448
|
+
const pathPreludeNode = materializeCssImportPathNode(resolvedPathNode, finalPath, context);
|
|
449
|
+
const postlude = importOptions!.postlude;
|
|
450
|
+
const prelude = postlude
|
|
451
|
+
? new Sequence(
|
|
452
|
+
[
|
|
453
|
+
pathPreludeNode,
|
|
454
|
+
...(isNode(postlude, N.Sequence | N.List) ? postlude.get('value', context) : [postlude])
|
|
455
|
+
],
|
|
456
|
+
undefined,
|
|
457
|
+
undefined,
|
|
458
|
+
context.treeContext
|
|
459
|
+
)
|
|
460
|
+
: pathPreludeNode;
|
|
461
|
+
const cssImport = new AtRule({
|
|
462
|
+
name: new Any('@import', { role: 'atkeyword' }),
|
|
463
|
+
prelude
|
|
464
|
+
});
|
|
465
|
+
await cssImport.preEval(context);
|
|
466
|
+
return Rules.create([]);
|
|
467
|
+
}
|
|
468
|
+
if (isInlineImport) {
|
|
469
|
+
const resolved = await context.resolveImportPath(finalPath);
|
|
470
|
+
resolvedPath = resolved.resolvedPath;
|
|
471
|
+
const sourceGetter = context.plugins.find(plugin => plugin.getSource);
|
|
472
|
+
if (!sourceGetter) {
|
|
473
|
+
throw new Error('No source getter found');
|
|
474
|
+
}
|
|
475
|
+
const source = await sourceGetter.getSource!(resolvedPath);
|
|
476
|
+
const sourceNode = new Any(source, { role: 'any' });
|
|
477
|
+
rules = this.wrapInlineSourceWithPostlude(sourceNode, importOptions!.postlude, context);
|
|
478
|
+
} else {
|
|
479
|
+
try {
|
|
480
|
+
({ node: rules, resolvedPath } = await context.getTree(finalPath, importOptions));
|
|
481
|
+
} catch (error: any) {
|
|
482
|
+
if (importOptions!.optional) {
|
|
483
|
+
return Rules.create([]);
|
|
484
|
+
}
|
|
485
|
+
if (importOptions!.reference && (error?.phase === 'parse' || String(error?.code ?? '').startsWith('parse/'))) {
|
|
486
|
+
return Rules.create([]);
|
|
487
|
+
}
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// Set sourceNode immediately after getting the Rules, before any evaluation
|
|
492
|
+
// This ensures that when preEval clones the Rules, the cloned Rules will have sourceNode set
|
|
493
|
+
// and registerNode can detect this is an imported Rules
|
|
494
|
+
rules.sourceNode = node;
|
|
495
|
+
let evaldRules = context.evaldTrees.get(resolvedPath);
|
|
496
|
+
|
|
497
|
+
// Compose caching semantics:
|
|
498
|
+
// - The first time a module is composed, we evaluate and cache the evaluated Rules.
|
|
499
|
+
// - Subsequent compose imports reuse the cached evaluated Rules (so re-imports don't re-run evaluation).
|
|
500
|
+
// - Subsequent compose imports default to "reference" mode unless `multiple: true` is set,
|
|
501
|
+
// so rulesets / at-rules are not output again.
|
|
502
|
+
const cachedSetValues = context.composeSetValues.get(resolvedPath);
|
|
503
|
+
const needsFreshSetBaselinePlacement = (
|
|
504
|
+
type === 'compose'
|
|
505
|
+
&& evaldRules != null
|
|
506
|
+
&& cachedSetValues != null
|
|
507
|
+
&& withValues == null
|
|
508
|
+
&& importOptions!.multiple === true
|
|
509
|
+
);
|
|
510
|
+
if (type === 'compose' && evaldRules) {
|
|
511
|
+
if (withValues?.type === 'set') {
|
|
512
|
+
// `set` establishes the cached module baseline and cannot be applied twice.
|
|
513
|
+
throw new Error('Cannot configure a stylesheet more than once.');
|
|
514
|
+
}
|
|
515
|
+
if (withValues?.type !== 'with' && !needsFreshSetBaselinePlacement) {
|
|
516
|
+
// Reuse cached evaluated rules tree for plain compose re-imports and `set` baselines.
|
|
517
|
+
rules = evaldRules;
|
|
518
|
+
}
|
|
519
|
+
// Default: de-dupe output for compose re-imports unless explicitly multiple.
|
|
520
|
+
if (!importOptions!.multiple) {
|
|
521
|
+
importOptions!.reference = true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (needsFreshSetBaselinePlacement) {
|
|
525
|
+
withValues = { node: cachedSetValues!, type: 'with' };
|
|
526
|
+
}
|
|
527
|
+
const inMultipleImportBranch = context.inMultipleImportScope;
|
|
528
|
+
if (type === 'import' && importOptions!.once !== false && !importOptions!.multiple && !inMultipleImportBranch && evaldRules) {
|
|
529
|
+
rules = evaldRules;
|
|
530
|
+
importOptions!._dedupe = true;
|
|
531
|
+
}
|
|
532
|
+
if (withValues) {
|
|
533
|
+
// Once configured, cannot be configured again (handled above for compose+cache).
|
|
534
|
+
if (withValues.type === 'set' && evaldRules) {
|
|
535
|
+
throw new Error('Cannot configure a stylesheet more than once.');
|
|
536
|
+
}
|
|
537
|
+
// Evaluate withValues.node if it's a Reference to get the actual Rules
|
|
538
|
+
let withRulesNode = withValues.node;
|
|
539
|
+
if (isNode(withRulesNode, N.Reference)) {
|
|
540
|
+
const evaluated = await withRulesNode.eval(context);
|
|
541
|
+
if (!isWithRulesNode(evaluated)) {
|
|
542
|
+
throw new Error('with/set node must evaluate to a Collection');
|
|
543
|
+
}
|
|
544
|
+
withRulesNode = evaluated;
|
|
545
|
+
}
|
|
546
|
+
if (!isWithRulesNode(withRulesNode)) {
|
|
547
|
+
throw new Error('with/set node must evaluate to a Collection');
|
|
548
|
+
}
|
|
549
|
+
let withRules: Rules = isNode(withRulesNode, N.Rules)
|
|
550
|
+
? withRulesNode
|
|
551
|
+
: Rules.create([...withRulesNode.value]);
|
|
552
|
+
if (type === 'compose' && withValues.type === 'with' && cachedSetValues) {
|
|
553
|
+
const mergedConfig = new Map<string, Node>();
|
|
554
|
+
for (const configuredNode of cachedSetValues.value) {
|
|
555
|
+
if (!isNode(configuredNode, N.VarDeclaration)) {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const key = String(configuredNode.get('name')?.valueOf() ?? '');
|
|
559
|
+
if (key) {
|
|
560
|
+
mergedConfig.set(key, configuredNode);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
for (const configuredNode of withRules.value) {
|
|
564
|
+
if (!isNode(configuredNode, N.VarDeclaration)) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
const key = String(configuredNode.get('name')?.valueOf() ?? '');
|
|
568
|
+
if (key) {
|
|
569
|
+
mergedConfig.set(key, configuredNode);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
withRules = Rules.create([...mergedConfig.values()]);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Build a name→index map over canonical top-level VarDeclarations for O(1) lookup.
|
|
576
|
+
// This replaces the previous rules.clone(true) + registry approach — we no longer
|
|
577
|
+
// deep-clone the entire imported tree just to find which declarations to override.
|
|
578
|
+
// A session created in the evaluation block below ensures that evaluated/preEvaluated
|
|
579
|
+
// tracking does not permanently mark canonical nodes as evaluated.
|
|
580
|
+
const topLevelVarIndex = new Map<string, number>();
|
|
581
|
+
for (let i = 0; i < rules.value.length; i++) {
|
|
582
|
+
const n = rules.value[i]!;
|
|
583
|
+
if (isNode(n, N.VarDeclaration)) {
|
|
584
|
+
const varName = String(n.get('name')?.valueOf() ?? '');
|
|
585
|
+
if (varName && !topLevelVarIndex.has(varName)) {
|
|
586
|
+
topLevelVarIndex.set(varName, i);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Separate injected variables into replacements (matched in canonical) and new variables.
|
|
592
|
+
const replacementAt = new Map<number, Node>();
|
|
593
|
+
const newVariables: Node[] = [];
|
|
594
|
+
|
|
595
|
+
for (const injectedNode of withRules.value) {
|
|
596
|
+
if (isNode(injectedNode, N.VarDeclaration)) {
|
|
597
|
+
const varName = String(injectedNode.get('name')?.valueOf() ?? '');
|
|
598
|
+
if (varName) {
|
|
599
|
+
const existingIdx = topLevelVarIndex.get(varName);
|
|
600
|
+
if (existingIdx !== undefined) {
|
|
601
|
+
replacementAt.set(existingIdx, injectedNode);
|
|
602
|
+
} else {
|
|
603
|
+
newVariables.push(injectedNode);
|
|
604
|
+
}
|
|
605
|
+
} else {
|
|
606
|
+
newVariables.push(injectedNode);
|
|
607
|
+
}
|
|
608
|
+
} else {
|
|
609
|
+
newVariables.push(injectedNode);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Build finalRules like mixin params: injected variables are pushed
|
|
614
|
+
// canonically (they're new nodes), library children keep their canonical
|
|
615
|
+
// parents untouched. We directly set the value array to avoid adopt()
|
|
616
|
+
// mutating canonical library node parents.
|
|
617
|
+
const finalChildren: Node[] = [];
|
|
618
|
+
for (const newNode of newVariables) {
|
|
619
|
+
finalChildren.push(newNode);
|
|
620
|
+
}
|
|
621
|
+
for (let i = 0; i < rules.value.length; i++) {
|
|
622
|
+
finalChildren.push(replacementAt.get(i) ?? rules.value[i]!);
|
|
623
|
+
}
|
|
624
|
+
rules = rules.createPlacementWrapperWithChildren(finalChildren, context.nextRenderKey());
|
|
625
|
+
if (type === 'compose' && withValues.type === 'set') {
|
|
626
|
+
context.composeSetValues.set(resolvedPath, withRules);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
// For compose type, register and push extend root BEFORE evaluation
|
|
630
|
+
// so extends inside the import use the correct root
|
|
631
|
+
const parentExtendRoot = context.extendRoots.getCurrentExtendRoot();
|
|
632
|
+
let pushedExtendRoot = false;
|
|
633
|
+
if (type === 'compose') {
|
|
634
|
+
// Register the Rules as an extend root (use rules before cloning/evaluation)
|
|
635
|
+
// We'll update the registration after evaluation if the Rules changes
|
|
636
|
+
// For compose type, default is protected (not mutable)
|
|
637
|
+
const isComposeProtected = !importOptions!.mutable;
|
|
638
|
+
context.extendRoots.registerRoot(rules, parentExtendRoot, {
|
|
639
|
+
isProtected: isComposeProtected,
|
|
640
|
+
isCompose: true,
|
|
641
|
+
namespace: node.options.namespace
|
|
642
|
+
});
|
|
643
|
+
context.extendRoots.pushExtendRoot(rules);
|
|
644
|
+
pushedExtendRoot = true;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** Freshly evaluate the rules in these circumstances
|
|
648
|
+
* - `with` (or `set`) values are present
|
|
649
|
+
* - the rules have not been evaluated yet
|
|
650
|
+
* - the import type is `import`
|
|
651
|
+
*/
|
|
652
|
+
const activeParent = getParent(this, context);
|
|
653
|
+
const shouldIsolateSelectorFrames = !isNode(activeParent ? getParent(activeParent, context) : undefined, N.Ruleset | N.AtRule);
|
|
654
|
+
const prevRulesetFrames = shouldIsolateSelectorFrames ? context.rulesetFrames : undefined;
|
|
655
|
+
const prevFrames = shouldIsolateSelectorFrames ? context.frames : undefined;
|
|
656
|
+
if (withValues || !evaldRules || type === 'import') {
|
|
657
|
+
let pushedImplicitReferenceEvalScope = false;
|
|
658
|
+
const isImplicitReferenceModeForEval = (
|
|
659
|
+
type === 'import'
|
|
660
|
+
&& importOptions!.reference !== true
|
|
661
|
+
&& importOptions!._dedupe === true
|
|
662
|
+
&& !importOptions!.multiple
|
|
663
|
+
);
|
|
664
|
+
if (isImplicitReferenceModeForEval) {
|
|
665
|
+
// Dedupe re-imports behave like an implicit reference traversal:
|
|
666
|
+
// evaluate for symbol availability, but avoid outward extend side effects.
|
|
667
|
+
context.pushImportScope({ reference: true });
|
|
668
|
+
pushedImplicitReferenceEvalScope = true;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// For protected imports (mutable: false), push the rules to extend root stack
|
|
672
|
+
// so rulesets register in the import's registry, not the parent's
|
|
673
|
+
const isImportProtected = type === 'import' && importOptions!.mutable === false;
|
|
674
|
+
const shouldUseLocalExtendRoot = isImportProtected || isImplicitReferenceModeForEval;
|
|
675
|
+
if (isImplicitReferenceModeForEval) {
|
|
676
|
+
// Link local in-eval root so external extends can still target deduped imports.
|
|
677
|
+
context.extendRoots.registerRoot(rules, parentExtendRoot, {
|
|
678
|
+
isProtected: isImportProtected,
|
|
679
|
+
namespace: node.options.namespace
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (shouldUseLocalExtendRoot) {
|
|
683
|
+
context.extendRoots.pushExtendRoot(rules);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
try {
|
|
687
|
+
if (shouldIsolateSelectorFrames) {
|
|
688
|
+
context.rulesetFrames = [];
|
|
689
|
+
context.frames = [];
|
|
690
|
+
}
|
|
691
|
+
if (withValues || !evaldRules) {
|
|
692
|
+
rules = this.createPlacementRules(rules, context);
|
|
693
|
+
}
|
|
694
|
+
// Call preEval first to get the cloned Rules (if cloning occurs)
|
|
695
|
+
// sourceNode is already set above, so the cloned Rules will have it
|
|
696
|
+
rules = await rules.preEval(context);
|
|
697
|
+
if (type === 'import') {
|
|
698
|
+
/** Needed at evaluation time for older import type */
|
|
699
|
+
node.adopt(rules);
|
|
700
|
+
}
|
|
701
|
+
rules = await rules.eval(context);
|
|
702
|
+
} finally {
|
|
703
|
+
if (pushedImplicitReferenceEvalScope) {
|
|
704
|
+
context.popImportScope();
|
|
705
|
+
}
|
|
706
|
+
if (shouldUseLocalExtendRoot) {
|
|
707
|
+
context.extendRoots.popExtendRoot();
|
|
708
|
+
}
|
|
709
|
+
if (shouldIsolateSelectorFrames) {
|
|
710
|
+
context.rulesetFrames = prevRulesetFrames!;
|
|
711
|
+
context.frames = prevFrames!;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// Cache compose modules (and configured modules) after first evaluation.
|
|
716
|
+
if (
|
|
717
|
+
(type === 'compose' && withValues?.type !== 'with')
|
|
718
|
+
|| withValues?.type === 'set'
|
|
719
|
+
|| (type === 'import' && importOptions!.once !== false)
|
|
720
|
+
) {
|
|
721
|
+
context.evaldTrees.set(resolvedPath, rules);
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
// Shallow-clone the cached rules BEFORE evaluation so registries are populated
|
|
725
|
+
// on the clone, not on the cached evaldRules.
|
|
726
|
+
rules = rules.createShallowBodyWrapper(context, context.nextRenderKey());
|
|
727
|
+
// Note: For compose type, we don't set rules.parent = node
|
|
728
|
+
// (only import type needs this for older import behavior)
|
|
729
|
+
try {
|
|
730
|
+
if (shouldIsolateSelectorFrames) {
|
|
731
|
+
context.rulesetFrames = [];
|
|
732
|
+
context.frames = [];
|
|
733
|
+
}
|
|
734
|
+
rules = await rules.eval(context);
|
|
735
|
+
} finally {
|
|
736
|
+
if (shouldIsolateSelectorFrames) {
|
|
737
|
+
context.rulesetFrames = prevRulesetFrames!;
|
|
738
|
+
context.frames = prevFrames!;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// Pop extend root if we pushed one
|
|
744
|
+
if (pushedExtendRoot) {
|
|
745
|
+
context.extendRoots.popExtendRoot();
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
let finalRules = node.getFinalRules(rules, context);
|
|
749
|
+
if (importOptions!.postlude && !isInlineImport) {
|
|
750
|
+
finalRules = this.wrapEvaluatedRulesWithPostlude(finalRules, importOptions!.postlude, context);
|
|
751
|
+
}
|
|
752
|
+
// configuredWithCanonicalParents restore removed — canonical parents are not mutated.
|
|
753
|
+
|
|
754
|
+
// For import type, register the final Rules as a child root of the parent
|
|
755
|
+
// so extends from the parent can find rulesets in the imported Rules.
|
|
756
|
+
if (type === 'import') {
|
|
757
|
+
const currentParentExtendRoot = context.extendRoots.getCurrentExtendRoot();
|
|
758
|
+
// Import type is mutable by default (unless explicitly mutable: false)
|
|
759
|
+
const isImportProtected = importOptions!.mutable === false;
|
|
760
|
+
const isImplicitReferenceModeForRegistration = (
|
|
761
|
+
importOptions!._dedupe === true
|
|
762
|
+
&& importOptions!.reference !== true
|
|
763
|
+
&& !importOptions!.multiple
|
|
764
|
+
);
|
|
765
|
+
const shouldReRegisterLocalRootRulesets = (
|
|
766
|
+
isImportProtected
|
|
767
|
+
|| isImplicitReferenceModeForRegistration
|
|
768
|
+
|| importOptions!.reference === true
|
|
769
|
+
);
|
|
770
|
+
context.extendRoots.registerRoot(finalRules, currentParentExtendRoot, {
|
|
771
|
+
isProtected: isImportProtected,
|
|
772
|
+
namespace: node.options.namespace
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// For imports that evaluated under a local extend root (protected import or implicit _dedupe
|
|
776
|
+
// reference traversal), rulesets were registered in the pre-finalized Rules root. Since
|
|
777
|
+
// getFinalRules can clone, re-register all descendant rulesets under finalRules.
|
|
778
|
+
// during preEval (when we pushed rules to the stack). Since getFinalRules clones,
|
|
779
|
+
// we need to re-register rulesets in finalRules' registry.
|
|
780
|
+
if (shouldReRegisterLocalRootRulesets) {
|
|
781
|
+
for (const maybeNode of finalRules.nodes()) {
|
|
782
|
+
if (isNode(maybeNode, N.Ruleset | N.Mixin)) {
|
|
783
|
+
finalRules.registerNode(maybeNode, undefined, context);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
// Don't push to stack - import type uses parent's root for extends inside the import
|
|
788
|
+
// But we register it so extends from parent can find rulesets in the imported Rules
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
return finalRules;
|
|
792
|
+
} finally {
|
|
793
|
+
// dedupedCachedRules/dedupedCanonicalParents restore removed —
|
|
794
|
+
// eval writes stay on derived nodes, canonical tree is not mutated.
|
|
795
|
+
context.treeContext = previousTreeContext;
|
|
796
|
+
if (pushedImportScope) {
|
|
797
|
+
context.popImportScope();
|
|
798
|
+
}
|
|
799
|
+
importOptions!.reference = previousExplicitReference;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
const getFinalPath = (resolvedPath: Quoted | Url): string => {
|
|
803
|
+
if (resolvedPath instanceof Url) {
|
|
804
|
+
return resolvedPath.pathValue(context);
|
|
805
|
+
}
|
|
806
|
+
const quotedValue = resolvedPath.get('value', context);
|
|
807
|
+
if (isNode(quotedValue)) {
|
|
808
|
+
return String(quotedValue.valueOf());
|
|
809
|
+
}
|
|
810
|
+
return String(quotedValue);
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
return Promise.resolve(maybePath).then(async (p: Quoted | Url) => {
|
|
814
|
+
const finalPath = getFinalPath(p);
|
|
815
|
+
context.depth = originalDepth;
|
|
816
|
+
return finalize(finalPath, p);
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Applies CSS import postlude wrappers around inline source content.
|
|
822
|
+
* Falls back to `@media <postlude>` for plain query nodes.
|
|
823
|
+
*/
|
|
824
|
+
private wrapInlineSourceWithPostlude(sourceNode: Node, postlude: Node | undefined, context: Context): Rules {
|
|
825
|
+
if (!postlude) {
|
|
826
|
+
return Rules.create([sourceNode]);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
let wrapped: Node = sourceNode;
|
|
830
|
+
const postludeNodes: Node[] = isNode(postlude, N.Sequence | N.List) ? [...postlude.get('value', context)] : [postlude];
|
|
831
|
+
|
|
832
|
+
for (let i = postludeNodes.length - 1; i >= 0; i--) {
|
|
833
|
+
const current = postludeNodes[i]!;
|
|
834
|
+
const body = Rules.create([wrapped]);
|
|
835
|
+
const { atRuleName, prelude } = this.materializePostludePrelude(current, context);
|
|
836
|
+
wrapped = new AtRule({
|
|
837
|
+
name: new Any(atRuleName, { role: 'atkeyword' }),
|
|
838
|
+
prelude,
|
|
839
|
+
rules: body
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return Rules.create([wrapped]);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Applies CSS import postlude wrappers around evaluated stylesheet rules.
|
|
848
|
+
* Used for Less-style imports with media/layer/supports postludes.
|
|
849
|
+
*/
|
|
850
|
+
private wrapEvaluatedRulesWithPostlude(rules: Rules, postlude: Node | undefined, context: Context): Rules {
|
|
851
|
+
if (!postlude) {
|
|
852
|
+
return rules;
|
|
853
|
+
}
|
|
854
|
+
const postludeNodes: Node[] = isNode(postlude, N.Sequence | N.List) ? [...postlude.get('value', context)] : [postlude];
|
|
855
|
+
let wrappedRules: Rules = rules;
|
|
856
|
+
for (let i = postludeNodes.length - 1; i >= 0; i--) {
|
|
857
|
+
const current = postludeNodes[i]!;
|
|
858
|
+
const { atRuleName, prelude } = this.materializePostludePrelude(current, context);
|
|
859
|
+
const wrappedAtRule = new AtRule({
|
|
860
|
+
name: new Any(atRuleName, { role: 'atkeyword' }),
|
|
861
|
+
prelude,
|
|
862
|
+
rules: wrappedRules
|
|
863
|
+
});
|
|
864
|
+
wrappedRules = Rules.create([wrappedAtRule]);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
return wrappedRules;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
defineType<StyleImportValue>(StyleImport, 'StyleImport', 'style');
|
|
872
|
+
|
|
873
|
+
export const style = (...args: ConstructorParameters<typeof StyleImport>) => {
|
|
874
|
+
return new StyleImport(...args);
|
|
875
|
+
};
|