@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,194 @@
|
|
|
1
|
+
import type { Class } from 'type-fest';
|
|
2
|
+
import { type Context } from '../context.js';
|
|
3
|
+
import { F_NON_STATIC, F_VISIBLE, Node, defineType, type OptionalLocation, type TreeContext } from './node.js';
|
|
4
|
+
import { Bool } from './bool.js';
|
|
5
|
+
import { type PrintOptions, getPrintOptions } from './util/print.js';
|
|
6
|
+
import { type MaybePromise, pipe, isThenable } from '@jesscss/awaitable-pipe';
|
|
7
|
+
|
|
8
|
+
/** @note Less will parse =< but it will be stored as <= */
|
|
9
|
+
export type ConditionOperator = 'and' | 'or' | '=' | '>' | '<' | '>=' | '<=';
|
|
10
|
+
|
|
11
|
+
export type ConditionValue = [
|
|
12
|
+
left: Node
|
|
13
|
+
] | [
|
|
14
|
+
left: Node,
|
|
15
|
+
op: ConditionOperator,
|
|
16
|
+
right: Node
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export type ConditionOptions = {
|
|
20
|
+
negate?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ConditionChildData = {
|
|
24
|
+
left: Node;
|
|
25
|
+
operator: ConditionOperator | undefined;
|
|
26
|
+
right: Node | undefined;
|
|
27
|
+
negate: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface Condition extends Node<ConditionValue, ConditionOptions, ConditionChildData> {
|
|
31
|
+
type: 'Condition';
|
|
32
|
+
shortType: 'condition';
|
|
33
|
+
eval(context: Context): MaybePromise<Bool>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Condition extends Node<ConditionValue, ConditionOptions, ConditionChildData> {
|
|
37
|
+
static override childKeys = ['left', 'right'] as const;
|
|
38
|
+
|
|
39
|
+
readonly left!: Node;
|
|
40
|
+
private readonly operator: ConditionOperator | undefined;
|
|
41
|
+
readonly right: Node | undefined;
|
|
42
|
+
private readonly negate: boolean;
|
|
43
|
+
|
|
44
|
+
override clone(deep?: boolean, cloneFn?: (n: Node) => Node, ctx?: Context): this {
|
|
45
|
+
const left = this.get('left', ctx);
|
|
46
|
+
const operator = this.get('operator', ctx);
|
|
47
|
+
const right = this.get('right', ctx);
|
|
48
|
+
const negate = this.get('negate', ctx);
|
|
49
|
+
const options = this._meta?.options;
|
|
50
|
+
const cloneChild = cloneFn ?? ((n: Node) => n.clone(deep, cloneFn, ctx));
|
|
51
|
+
const value: ConditionValue = operator !== undefined && right !== undefined
|
|
52
|
+
? [deep ? cloneChild(left) : left, operator, deep ? cloneChild(right) : right]
|
|
53
|
+
: [deep ? cloneChild(left) : left];
|
|
54
|
+
let clonedOptions = options ? { ...options } : undefined;
|
|
55
|
+
if (negate) {
|
|
56
|
+
(clonedOptions ??= {}).negate = true;
|
|
57
|
+
} else if (clonedOptions) {
|
|
58
|
+
delete clonedOptions.negate;
|
|
59
|
+
}
|
|
60
|
+
const newNode = new (this.constructor as Class<this>)(
|
|
61
|
+
value,
|
|
62
|
+
clonedOptions,
|
|
63
|
+
this.location,
|
|
64
|
+
this.treeContext
|
|
65
|
+
);
|
|
66
|
+
newNode.inherit(this);
|
|
67
|
+
return newNode;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
constructor(value: ConditionValue, options?: ConditionOptions, location?: OptionalLocation, treeContext?: TreeContext) {
|
|
71
|
+
super(value, options, location, treeContext);
|
|
72
|
+
this.left = value[0];
|
|
73
|
+
this.operator = value[1];
|
|
74
|
+
this.right = value[2];
|
|
75
|
+
this.negate = !!options?.negate;
|
|
76
|
+
if (this.left instanceof Node) {
|
|
77
|
+
this.adopt(this.left);
|
|
78
|
+
}
|
|
79
|
+
if (this.right instanceof Node) {
|
|
80
|
+
this.adopt(this.right);
|
|
81
|
+
}
|
|
82
|
+
// Conditions are always non-static, but can inherit may_async from children
|
|
83
|
+
this.addFlags(F_VISIBLE, F_NON_STATIC);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
override toTrimmedString(options?: PrintOptions) {
|
|
87
|
+
options = getPrintOptions(options);
|
|
88
|
+
const w = options.writer!;
|
|
89
|
+
const mark = w.mark();
|
|
90
|
+
const context = options.context;
|
|
91
|
+
let left = this.get('left', context);
|
|
92
|
+
let op = this.get('operator', context);
|
|
93
|
+
let right = this.get('right', context);
|
|
94
|
+
const negated = this.get('negate', context);
|
|
95
|
+
const needsParens = Boolean(right || negated);
|
|
96
|
+
if (negated) {
|
|
97
|
+
w.add('not ');
|
|
98
|
+
}
|
|
99
|
+
if (needsParens) {
|
|
100
|
+
w.add('(');
|
|
101
|
+
}
|
|
102
|
+
left.toString(options);
|
|
103
|
+
if (op && right) {
|
|
104
|
+
w.add(' ');
|
|
105
|
+
w.add(String(op));
|
|
106
|
+
w.add(' ');
|
|
107
|
+
right.toString(options);
|
|
108
|
+
}
|
|
109
|
+
if (needsParens) {
|
|
110
|
+
w.add(')');
|
|
111
|
+
}
|
|
112
|
+
return w.getSince(mark);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static getBool(node: Node, negated: boolean): Bool {
|
|
116
|
+
if (node instanceof Bool) {
|
|
117
|
+
return new Bool(negated ? !node.value : node.value);
|
|
118
|
+
}
|
|
119
|
+
// Less guards treat only explicit booleans as truthy.
|
|
120
|
+
// Any non-boolean (number, quoted, keyword, list, nil, etc.) is false.
|
|
121
|
+
return new Bool(negated);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static getResult(a: Node, b: Node, op: ConditionOperator, context?: Context): boolean {
|
|
125
|
+
switch (op) {
|
|
126
|
+
case 'and': return Condition.getBool(a, false).value && Condition.getBool(b, false).value;
|
|
127
|
+
case 'or': return Condition.getBool(a, false).value || Condition.getBool(b, false).value;
|
|
128
|
+
default:
|
|
129
|
+
switch (a.compare(b, context)) {
|
|
130
|
+
case -1:
|
|
131
|
+
return op === '<' || op === '<=';
|
|
132
|
+
case 0:
|
|
133
|
+
return op === '=' || op === '>=' || op === '<=';
|
|
134
|
+
case 1:
|
|
135
|
+
return op === '>' || op === '>=';
|
|
136
|
+
default:
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
override evalNode(context: Context): MaybePromise<Bool> {
|
|
143
|
+
let left = this.get('left', context);
|
|
144
|
+
let op = this.get('operator', context);
|
|
145
|
+
let right = this.get('right', context);
|
|
146
|
+
let negated = this.get('negate', context);
|
|
147
|
+
|
|
148
|
+
return pipe(
|
|
149
|
+
() => left.eval(context),
|
|
150
|
+
(a) => {
|
|
151
|
+
if (!right) {
|
|
152
|
+
// Defer unary coercion to the final stage to avoid double-negation.
|
|
153
|
+
return a;
|
|
154
|
+
}
|
|
155
|
+
return a;
|
|
156
|
+
},
|
|
157
|
+
(a) => {
|
|
158
|
+
if (!right) {
|
|
159
|
+
return [a];
|
|
160
|
+
}
|
|
161
|
+
let b = right.eval(context);
|
|
162
|
+
if (isThenable(b)) {
|
|
163
|
+
return (b as Promise<Node>).then(bb => [a, bb] as const);
|
|
164
|
+
}
|
|
165
|
+
return [a, b];
|
|
166
|
+
},
|
|
167
|
+
([a, b]) => {
|
|
168
|
+
if (!b) {
|
|
169
|
+
const unary = Condition.getBool(a, negated);
|
|
170
|
+
return unary;
|
|
171
|
+
}
|
|
172
|
+
const normalizeDefaultCall = (node: Node): Node => {
|
|
173
|
+
if (node.type !== 'Call') {
|
|
174
|
+
return node;
|
|
175
|
+
}
|
|
176
|
+
const rawCallName = (node as import('./call.js').Call).name;
|
|
177
|
+
const callName = String(typeof rawCallName === 'string'
|
|
178
|
+
? rawCallName
|
|
179
|
+
: rawCallName?.valueOf?.() ?? '');
|
|
180
|
+
if (callName === 'default' || callName === '??') {
|
|
181
|
+
return new Bool(Boolean(context.isDefault));
|
|
182
|
+
}
|
|
183
|
+
return node;
|
|
184
|
+
};
|
|
185
|
+
a = normalizeDefaultCall(a);
|
|
186
|
+
b = normalizeDefaultCall(b);
|
|
187
|
+
let result = Condition.getResult(a, b, op!, context);
|
|
188
|
+
return new Bool(negated ? !result : result);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const condition = defineType(Condition, 'Condition');
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { Node, defineType, F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC, type OptionalLocation } from './node.js';
|
|
2
|
+
import type { Context, TreeContext } from '../context.js';
|
|
3
|
+
import { Rules } from './rules.js';
|
|
4
|
+
import { Sequence } from './sequence.js';
|
|
5
|
+
import { Any } from './any.js';
|
|
6
|
+
import { Num } from './number.js';
|
|
7
|
+
import { VarDeclaration } from './declaration-var.js';
|
|
8
|
+
import { isNode } from './util/is-node.js';
|
|
9
|
+
import { N } from './node-type.js';
|
|
10
|
+
import { type PrintOptions, getPrintOptions } from './util/print.js';
|
|
11
|
+
import type { MaybePromise } from '@jesscss/awaitable-pipe';
|
|
12
|
+
import { List } from './list.js';
|
|
13
|
+
import type { Mixin } from './mixin.js';
|
|
14
|
+
import { appendScopedOutputNodes, createCounterNode, evaluateScopedBodyWithBindings } from './util/scoped-body-eval.js';
|
|
15
|
+
|
|
16
|
+
const PUBLIC_RULE_VISIBILITY = {
|
|
17
|
+
Declaration: 'public',
|
|
18
|
+
Ruleset: 'public',
|
|
19
|
+
VarDeclaration: 'public',
|
|
20
|
+
Mixin: 'public'
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
function makeDirectiveRulesPublic(rules: Rules) {
|
|
24
|
+
rules.options.rulesVisibility = {
|
|
25
|
+
...rules.options.rulesVisibility,
|
|
26
|
+
...PUBLIC_RULE_VISIBILITY
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type LegacyLoopValue = {
|
|
31
|
+
header: Sequence;
|
|
32
|
+
rules: Rules;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type ForValue = {
|
|
36
|
+
vars: VarDeclaration | VarDeclaration[];
|
|
37
|
+
iterable: Node;
|
|
38
|
+
rules: Rules;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function getBindingNames(vars: VarDeclaration | VarDeclaration[]): string[] {
|
|
42
|
+
if (Array.isArray(vars)) {
|
|
43
|
+
return vars.map(v => v.get('name').valueOf());
|
|
44
|
+
}
|
|
45
|
+
return [vars.get('name').valueOf()];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function varsToNode(vars: VarDeclaration | VarDeclaration[]): Node {
|
|
49
|
+
if (!Array.isArray(vars)) {
|
|
50
|
+
return vars;
|
|
51
|
+
}
|
|
52
|
+
const wrapper = new List<VarDeclaration>([], { sep: ',' });
|
|
53
|
+
wrapper.value = [...vars];
|
|
54
|
+
return wrapper;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function resolveLoopEntryKey(
|
|
58
|
+
key: number | string | Node,
|
|
59
|
+
counter: number,
|
|
60
|
+
context: Context
|
|
61
|
+
): Promise<Node> {
|
|
62
|
+
if (typeof key === 'number') {
|
|
63
|
+
return new Num(key + 1);
|
|
64
|
+
}
|
|
65
|
+
if (typeof key === 'string' && key === 'value') {
|
|
66
|
+
return new Num(counter);
|
|
67
|
+
}
|
|
68
|
+
if (isNode(key)) {
|
|
69
|
+
return await key.eval(context);
|
|
70
|
+
}
|
|
71
|
+
return new Any(String(key), { role: 'property' });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function evaluateForIteration(
|
|
75
|
+
loopTemplate: Rules,
|
|
76
|
+
accumulatedNodes: readonly Node[],
|
|
77
|
+
bindingNames: readonly string[],
|
|
78
|
+
value: Node,
|
|
79
|
+
key: number | string | Node,
|
|
80
|
+
counter: number,
|
|
81
|
+
context: Context
|
|
82
|
+
): Promise<Node[]> {
|
|
83
|
+
const resolvedValue = await value.eval(context);
|
|
84
|
+
const resolvedKey = await resolveLoopEntryKey(key, counter, context);
|
|
85
|
+
return evaluateScopedBodyWithBindings(
|
|
86
|
+
loopTemplate,
|
|
87
|
+
accumulatedNodes,
|
|
88
|
+
[
|
|
89
|
+
{ name: bindingNames[0]!, value: resolvedValue },
|
|
90
|
+
{ name: bindingNames[1] ?? '', value: resolvedKey },
|
|
91
|
+
{ name: bindingNames[2] ?? '', value: createCounterNode(counter) }
|
|
92
|
+
].filter(binding => binding.name),
|
|
93
|
+
context
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function evaluateForOutput(
|
|
98
|
+
loopTemplate: Rules,
|
|
99
|
+
bindingNames: readonly string[],
|
|
100
|
+
evaluatedIterable: Node,
|
|
101
|
+
context: Context
|
|
102
|
+
): Promise<Rules> {
|
|
103
|
+
const accumulatedNodes: Node[] = [];
|
|
104
|
+
let counter = 1;
|
|
105
|
+
for await (const [value, key] of resolveEntries(evaluatedIterable, context)) {
|
|
106
|
+
const outputNodes = await evaluateForIteration(
|
|
107
|
+
loopTemplate,
|
|
108
|
+
accumulatedNodes,
|
|
109
|
+
bindingNames,
|
|
110
|
+
value,
|
|
111
|
+
key,
|
|
112
|
+
counter,
|
|
113
|
+
context
|
|
114
|
+
);
|
|
115
|
+
counter++;
|
|
116
|
+
appendScopedOutputNodes(accumulatedNodes, outputNodes, context);
|
|
117
|
+
}
|
|
118
|
+
return new Rules(accumulatedNodes);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function* resolveEntries(input: Node, context: Context): AsyncGenerator<[Node, number | string | Node]> {
|
|
122
|
+
if (isNode(input, N.Expression)) {
|
|
123
|
+
yield* resolveEntries(await input.get('value', context).eval(context), context);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (isNode(input, N.Call)) {
|
|
127
|
+
const evald = await input.eval(context);
|
|
128
|
+
if (isNode(evald, N.Call)) {
|
|
129
|
+
yield [evald, 0];
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
yield* resolveEntries(evald, context);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (isNode(input, N.Paren)) {
|
|
136
|
+
const parenValue = input.get('value', context);
|
|
137
|
+
if (parenValue instanceof Node) {
|
|
138
|
+
yield* resolveEntries(parenValue, context);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if ((isNode(input, N.Sequence) || isNode(input, N.List))) {
|
|
143
|
+
const items = input.get('value', context);
|
|
144
|
+
if (Array.isArray(items)) {
|
|
145
|
+
for (let key = 0; key < items.length; key++) {
|
|
146
|
+
const value = items[key]!;
|
|
147
|
+
yield [value, key];
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (isNode(input, N.Rules | N.Ruleset | N.Mixin)) {
|
|
153
|
+
const rules: readonly Node[] = isNode(input, N.Rules)
|
|
154
|
+
? input.value
|
|
155
|
+
: isNode(input, N.Ruleset)
|
|
156
|
+
? (input.getRules(context?.renderKey ?? input.renderKey)?.value ?? [])
|
|
157
|
+
: (((input as Mixin).get('rules')?.value) ?? []);
|
|
158
|
+
for (const rule of rules) {
|
|
159
|
+
if (!rule || isNode(rule, N.Comment)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (!isNode(rule, N.Declaration)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
yield [
|
|
166
|
+
(rule as Node & { value: Node }).value,
|
|
167
|
+
(rule as Node & { name: Node }).name
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
yield [input, 0];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** @todo - I don't understand how these are different or why the LLM did this? */
|
|
176
|
+
export type IfValue = {
|
|
177
|
+
conditions: Node[];
|
|
178
|
+
bodies: Rules[];
|
|
179
|
+
elseBranch?: Rules;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type IfChildData = {
|
|
183
|
+
conditions: Node[];
|
|
184
|
+
bodies: Rules[];
|
|
185
|
+
elseBranch: Rules | undefined;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A control-flow block that serializes as:
|
|
190
|
+
* - `$if (...) { ... }`
|
|
191
|
+
* - `$else if (...) { ... }`
|
|
192
|
+
* - `$else { ... }`
|
|
193
|
+
*
|
|
194
|
+
* This is language-agnostic: it's the canonical Jess control node.
|
|
195
|
+
*/
|
|
196
|
+
export interface If extends Node<IfValue, any, IfChildData> {
|
|
197
|
+
type: 'If';
|
|
198
|
+
shortType: 'if';
|
|
199
|
+
}
|
|
200
|
+
export class If extends Node<IfValue, any, IfChildData> {
|
|
201
|
+
static override childKeys = ['conditions', 'bodies', 'elseBranch'] as const;
|
|
202
|
+
|
|
203
|
+
readonly conditions!: Node[];
|
|
204
|
+
readonly bodies!: Rules[];
|
|
205
|
+
readonly elseBranch: Rules | undefined;
|
|
206
|
+
|
|
207
|
+
constructor(value: IfValue, options?: any, location?: OptionalLocation, treeContext?: TreeContext) {
|
|
208
|
+
super(value, options, location, treeContext);
|
|
209
|
+
this.conditions = value.conditions;
|
|
210
|
+
this.bodies = value.bodies;
|
|
211
|
+
this.elseBranch = value.elseBranch;
|
|
212
|
+
for (const cond of this.conditions) {
|
|
213
|
+
if (cond instanceof Node) {
|
|
214
|
+
this.adopt(cond);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
for (const body of this.bodies) {
|
|
218
|
+
if (body instanceof Node) {
|
|
219
|
+
this.adopt(body);
|
|
220
|
+
}
|
|
221
|
+
makeDirectiveRulesPublic(body);
|
|
222
|
+
}
|
|
223
|
+
if (this.elseBranch) {
|
|
224
|
+
if (this.elseBranch instanceof Node) {
|
|
225
|
+
this.adopt(this.elseBranch);
|
|
226
|
+
}
|
|
227
|
+
makeDirectiveRulesPublic(this.elseBranch);
|
|
228
|
+
}
|
|
229
|
+
this.allowRoot = true;
|
|
230
|
+
this.allowRuleRoot = true;
|
|
231
|
+
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
override toTrimmedString(options?: PrintOptions): string {
|
|
235
|
+
options = getPrintOptions(options);
|
|
236
|
+
const w = options.writer!;
|
|
237
|
+
const mark = w.mark();
|
|
238
|
+
const context = options.context;
|
|
239
|
+
|
|
240
|
+
const conditions = this.get('conditions', context);
|
|
241
|
+
const bodies = this.get('bodies', context);
|
|
242
|
+
const elseBranch = this.get('elseBranch', context);
|
|
243
|
+
w.add('$if', this);
|
|
244
|
+
w.add(' (');
|
|
245
|
+
conditions[0]?.toString(options);
|
|
246
|
+
w.add(') ');
|
|
247
|
+
bodies[0]?.toBraced(options);
|
|
248
|
+
|
|
249
|
+
for (let i = 1; i < conditions.length; i++) {
|
|
250
|
+
w.add(' $else if (');
|
|
251
|
+
conditions[i]!.toString(options);
|
|
252
|
+
w.add(') ');
|
|
253
|
+
bodies[i]?.toBraced(options);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (elseBranch) {
|
|
257
|
+
w.add(' $else ');
|
|
258
|
+
elseBranch.toBraced(options);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return w.getSince(mark);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export type ForChildData = {
|
|
266
|
+
vars: VarDeclaration | VarDeclaration[];
|
|
267
|
+
iterable: Node;
|
|
268
|
+
rules: Rules;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export interface For extends Node<ForValue, any, ForChildData> {
|
|
272
|
+
type: 'For';
|
|
273
|
+
shortType: 'for';
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* `$for <header> { ... }`
|
|
277
|
+
*/
|
|
278
|
+
export class For extends Node<ForValue, any, ForChildData> {
|
|
279
|
+
static override childKeys = ['vars', 'iterable', 'rules'] as const;
|
|
280
|
+
|
|
281
|
+
readonly vars!: VarDeclaration | VarDeclaration[];
|
|
282
|
+
readonly iterable!: Node;
|
|
283
|
+
readonly rules!: Rules;
|
|
284
|
+
|
|
285
|
+
constructor(value: ForValue, options?: any, location?: OptionalLocation, treeContext?: TreeContext) {
|
|
286
|
+
super(value, options, location, treeContext);
|
|
287
|
+
this.vars = value.vars;
|
|
288
|
+
this.iterable = value.iterable;
|
|
289
|
+
this.rules = value.rules;
|
|
290
|
+
if (Array.isArray(this.vars)) {
|
|
291
|
+
for (const v of this.vars) {
|
|
292
|
+
if (v instanceof Node) {
|
|
293
|
+
this.adopt(v);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
} else if (this.vars instanceof Node) {
|
|
297
|
+
this.adopt(this.vars);
|
|
298
|
+
}
|
|
299
|
+
if (this.iterable instanceof Node) {
|
|
300
|
+
this.adopt(this.iterable);
|
|
301
|
+
}
|
|
302
|
+
if (this.rules instanceof Node) {
|
|
303
|
+
this.adopt(this.rules);
|
|
304
|
+
}
|
|
305
|
+
this.allowRoot = true;
|
|
306
|
+
this.allowRuleRoot = true;
|
|
307
|
+
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
308
|
+
makeDirectiveRulesPublic(this.rules);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
override preEval(context: Context): MaybePromise<Node> {
|
|
312
|
+
if (!this.preEvaluated) {
|
|
313
|
+
this.preEvaluated = true;
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
return this;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
override evalNode(context: Context): MaybePromise<Node> {
|
|
320
|
+
const vars = this.get('vars', context);
|
|
321
|
+
const iterable = this.get('iterable', context);
|
|
322
|
+
const loopTemplate = this.get('rules', context).withRenderOwner(this, context.renderKey, context);
|
|
323
|
+
const bindingNames = getBindingNames(vars);
|
|
324
|
+
if (bindingNames.length === 0) {
|
|
325
|
+
throw new Error('Invalid $for header: missing binding variable');
|
|
326
|
+
}
|
|
327
|
+
const run = async (): Promise<Node> => {
|
|
328
|
+
const evaluatedIterable = await iterable.eval(context);
|
|
329
|
+
return evaluateForOutput(loopTemplate, bindingNames, evaluatedIterable, context);
|
|
330
|
+
};
|
|
331
|
+
return run();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
override toTrimmedString(options?: PrintOptions): string {
|
|
335
|
+
options = getPrintOptions(options);
|
|
336
|
+
const w = options.writer!;
|
|
337
|
+
const mark = w.mark();
|
|
338
|
+
const context = options.context;
|
|
339
|
+
w.add('$for ', this);
|
|
340
|
+
w.add('(');
|
|
341
|
+
varsToNode(this.get('vars', context)).toString(options);
|
|
342
|
+
w.add(' of ');
|
|
343
|
+
this.get('iterable', context).toString(options);
|
|
344
|
+
w.add(')');
|
|
345
|
+
w.add(' ');
|
|
346
|
+
this.get('rules', context).withRenderOwner(this, context?.renderKey, context).toBraced(options);
|
|
347
|
+
return w.getSince(mark);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* `$each <header> { ... }`
|
|
353
|
+
*/
|
|
354
|
+
export type EachChildData = {
|
|
355
|
+
header: Sequence;
|
|
356
|
+
rules: Rules;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
export interface Each extends Node<LegacyLoopValue, any, EachChildData> {
|
|
360
|
+
type: 'Each';
|
|
361
|
+
shortType: 'each';
|
|
362
|
+
}
|
|
363
|
+
export class Each extends Node<LegacyLoopValue, any, EachChildData> {
|
|
364
|
+
static override childKeys = ['header', 'rules'] as const;
|
|
365
|
+
|
|
366
|
+
readonly header!: Sequence;
|
|
367
|
+
readonly rules!: Rules;
|
|
368
|
+
|
|
369
|
+
constructor(value: LegacyLoopValue, options?: any, location?: OptionalLocation, treeContext?: TreeContext) {
|
|
370
|
+
super(value, options, location, treeContext);
|
|
371
|
+
this.header = value.header;
|
|
372
|
+
this.rules = value.rules;
|
|
373
|
+
if (this.header instanceof Node) {
|
|
374
|
+
this.adopt(this.header);
|
|
375
|
+
}
|
|
376
|
+
if (this.rules instanceof Node) {
|
|
377
|
+
this.adopt(this.rules);
|
|
378
|
+
}
|
|
379
|
+
this.allowRoot = true;
|
|
380
|
+
this.allowRuleRoot = true;
|
|
381
|
+
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
override toTrimmedString(options?: PrintOptions): string {
|
|
385
|
+
options = getPrintOptions(options);
|
|
386
|
+
const w = options.writer!;
|
|
387
|
+
const mark = w.mark();
|
|
388
|
+
const context = options.context;
|
|
389
|
+
w.add('$each ', this);
|
|
390
|
+
this.get('header', context).toString(options);
|
|
391
|
+
w.add(' ');
|
|
392
|
+
this.get('rules', context).withRenderOwner(this, context?.renderKey, context).toBraced(options);
|
|
393
|
+
return w.getSince(mark);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export type WhileValue = {
|
|
398
|
+
condition: Node;
|
|
399
|
+
rules: Rules;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
export type WhileChildData = {
|
|
403
|
+
condition: Node;
|
|
404
|
+
rules: Rules;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* `$while (<condition>) { ... }`
|
|
409
|
+
*/
|
|
410
|
+
export interface While extends Node<WhileValue, any, WhileChildData> {
|
|
411
|
+
type: 'While';
|
|
412
|
+
shortType: 'while';
|
|
413
|
+
}
|
|
414
|
+
export class While extends Node<WhileValue, any, WhileChildData> {
|
|
415
|
+
static override childKeys = ['condition', 'rules'] as const;
|
|
416
|
+
|
|
417
|
+
readonly condition!: Node;
|
|
418
|
+
readonly rules!: Rules;
|
|
419
|
+
|
|
420
|
+
constructor(value: WhileValue, options?: any, location?: OptionalLocation, treeContext?: TreeContext) {
|
|
421
|
+
super(value, options, location, treeContext);
|
|
422
|
+
this.condition = value.condition;
|
|
423
|
+
this.rules = value.rules;
|
|
424
|
+
if (this.condition instanceof Node) {
|
|
425
|
+
this.adopt(this.condition);
|
|
426
|
+
}
|
|
427
|
+
if (this.rules instanceof Node) {
|
|
428
|
+
this.adopt(this.rules);
|
|
429
|
+
}
|
|
430
|
+
this.allowRoot = true;
|
|
431
|
+
this.allowRuleRoot = true;
|
|
432
|
+
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
433
|
+
makeDirectiveRulesPublic(this.rules);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
override toTrimmedString(options?: PrintOptions): string {
|
|
437
|
+
options = getPrintOptions(options);
|
|
438
|
+
const w = options.writer!;
|
|
439
|
+
const mark = w.mark();
|
|
440
|
+
const context = options.context;
|
|
441
|
+
w.add('$while (', this);
|
|
442
|
+
this.get('condition', context).toString(options);
|
|
443
|
+
w.add(') ');
|
|
444
|
+
this.get('rules', context).withRenderOwner(this, context?.renderKey, context).toBraced(options);
|
|
445
|
+
return w.getSince(mark);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export const ifNode = defineType(If, 'If', 'if');
|
|
450
|
+
export const forNode = defineType(For, 'For', 'for');
|
|
451
|
+
export const eachNode = defineType(Each, 'Each', 'each');
|
|
452
|
+
export const whileNode = defineType(While, 'While', 'while');
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Declaration } from './declaration.js';
|
|
2
|
+
import { defineType } from './node.js';
|
|
3
|
+
import type { Context } from '../context.js';
|
|
4
|
+
import type { Nil } from './nil.js';
|
|
5
|
+
import { type MaybePromise, pipe } from '@jesscss/awaitable-pipe';
|
|
6
|
+
// import type { OutputCollector } from '../output'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A declaration that retains all tokens
|
|
10
|
+
* (white-space, comments, etc)
|
|
11
|
+
*
|
|
12
|
+
* Ideally, perhaps, the value would just be
|
|
13
|
+
* one Anonymous node for now?
|
|
14
|
+
*
|
|
15
|
+
* @todo - is this used?
|
|
16
|
+
*/
|
|
17
|
+
export class CustomDeclaration extends Declaration {
|
|
18
|
+
override evalNode(context: Context): MaybePromise<this | Nil> {
|
|
19
|
+
context.inCustom = true;
|
|
20
|
+
return pipe(
|
|
21
|
+
() => super.evalNode(context),
|
|
22
|
+
(node) => {
|
|
23
|
+
context.inCustom = false;
|
|
24
|
+
return node as this | Nil;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @todo move to visitors */
|
|
30
|
+
// toCSS(context: Context, out: OutputCollector) {
|
|
31
|
+
// const loc = this.location
|
|
32
|
+
// this.name.toCSS(context, out)
|
|
33
|
+
// /**
|
|
34
|
+
// * Don't insert a space after the colon;
|
|
35
|
+
// * Instead, insert the exact token stream.
|
|
36
|
+
// *
|
|
37
|
+
// * @todo - test this
|
|
38
|
+
// */
|
|
39
|
+
// out.add(':', loc)
|
|
40
|
+
// this.data.toCSS(context, out)
|
|
41
|
+
// out.add(';', loc)
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// toModule(context: Context, out: OutputCollector) {
|
|
45
|
+
// const pre = context.pre
|
|
46
|
+
// const loc = this.location
|
|
47
|
+
// out.add('$J.custom({\n', loc)
|
|
48
|
+
// out.add(` ${pre}name: `)
|
|
49
|
+
// this.name.toModule(context, out)
|
|
50
|
+
// out.add(`\n ${pre}value: `)
|
|
51
|
+
// this.data.toModule(context, out)
|
|
52
|
+
// out.add(`\n${pre}})`)
|
|
53
|
+
// }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const customdecl = defineType(CustomDeclaration, 'CustomDeclaration', 'custom');
|