@jesscss/core 2.0.0-alpha.5 → 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 -98
- package/lib/tree/ampersand.d.ts.map +0 -1
- package/lib/tree/ampersand.js +0 -319
- 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
package/lib/tree/condition.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { F_NON_STATIC, F_VISIBLE, Node, defineType } from './node.js';
|
|
2
|
-
import { Bool } from './bool.js';
|
|
3
|
-
import { getPrintOptions } from './util/print.js';
|
|
4
|
-
import { pipe, isThenable } from '@jesscss/awaitable-pipe';
|
|
5
|
-
export class Condition extends Node {
|
|
6
|
-
type = 'Condition';
|
|
7
|
-
shortType = 'condition';
|
|
8
|
-
constructor(value, options, location, treeContext) {
|
|
9
|
-
super(value, options, location, treeContext);
|
|
10
|
-
// Conditions are always non-static, but can inherit may_async from children
|
|
11
|
-
this.addFlags(F_VISIBLE, F_NON_STATIC);
|
|
12
|
-
}
|
|
13
|
-
toTrimmedString(options) {
|
|
14
|
-
options = getPrintOptions(options);
|
|
15
|
-
const w = options.writer;
|
|
16
|
-
const mark = w.mark();
|
|
17
|
-
let [left, op, right] = this.value;
|
|
18
|
-
const needsParens = Boolean(right || this.options?.negate);
|
|
19
|
-
if (this.options?.negate) {
|
|
20
|
-
w.add('not ');
|
|
21
|
-
}
|
|
22
|
-
if (needsParens) {
|
|
23
|
-
w.add('(');
|
|
24
|
-
}
|
|
25
|
-
left.toString(options);
|
|
26
|
-
if (op && right) {
|
|
27
|
-
w.add(' ');
|
|
28
|
-
w.add(String(op));
|
|
29
|
-
w.add(' ');
|
|
30
|
-
right.toString(options);
|
|
31
|
-
}
|
|
32
|
-
if (needsParens) {
|
|
33
|
-
w.add(')');
|
|
34
|
-
}
|
|
35
|
-
return w.getSince(mark);
|
|
36
|
-
}
|
|
37
|
-
static getBool(node, negated) {
|
|
38
|
-
if (node instanceof Bool) {
|
|
39
|
-
return new Bool(negated ? !node.value : node.value);
|
|
40
|
-
}
|
|
41
|
-
// Less guards treat only explicit booleans as truthy.
|
|
42
|
-
// Any non-boolean (number, quoted, keyword, list, nil, etc.) is false.
|
|
43
|
-
return new Bool(negated);
|
|
44
|
-
}
|
|
45
|
-
static getResult(a, b, op) {
|
|
46
|
-
switch (op) {
|
|
47
|
-
case 'and': return Condition.getBool(a, false).value && Condition.getBool(b, false).value;
|
|
48
|
-
case 'or': return Condition.getBool(a, false).value || Condition.getBool(b, false).value;
|
|
49
|
-
default:
|
|
50
|
-
switch (a.compare(b)) {
|
|
51
|
-
case -1:
|
|
52
|
-
return op === '<' || op === '<=';
|
|
53
|
-
case 0:
|
|
54
|
-
return op === '=' || op === '>=' || op === '<=';
|
|
55
|
-
case 1:
|
|
56
|
-
return op === '>' || op === '>=';
|
|
57
|
-
default:
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
evalNode(context) {
|
|
63
|
-
let [left, op, right] = this.value;
|
|
64
|
-
let negated = !!this.options?.negate;
|
|
65
|
-
return pipe(() => left.eval(context), (a) => {
|
|
66
|
-
if (!right) {
|
|
67
|
-
// Defer unary coercion to the final stage to avoid double-negation.
|
|
68
|
-
return a;
|
|
69
|
-
}
|
|
70
|
-
return a;
|
|
71
|
-
}, (a) => {
|
|
72
|
-
if (!right) {
|
|
73
|
-
return [a];
|
|
74
|
-
}
|
|
75
|
-
let b = right.eval(context);
|
|
76
|
-
if (isThenable(b)) {
|
|
77
|
-
return b.then(bb => [a, bb]);
|
|
78
|
-
}
|
|
79
|
-
return [a, b];
|
|
80
|
-
}, ([a, b]) => {
|
|
81
|
-
if (!b) {
|
|
82
|
-
const unary = Condition.getBool(a, negated);
|
|
83
|
-
return unary;
|
|
84
|
-
}
|
|
85
|
-
const normalizeDefaultCall = (node) => {
|
|
86
|
-
if (node.type !== 'Call') {
|
|
87
|
-
return node;
|
|
88
|
-
}
|
|
89
|
-
const callName = String(node.value?.name?.valueOf?.() ?? node.value?.name ?? '');
|
|
90
|
-
if (callName === 'default' || callName === '??') {
|
|
91
|
-
return new Bool(Boolean(context.isDefault));
|
|
92
|
-
}
|
|
93
|
-
return node;
|
|
94
|
-
};
|
|
95
|
-
a = normalizeDefaultCall(a);
|
|
96
|
-
b = normalizeDefaultCall(b);
|
|
97
|
-
let result = Condition.getResult(a, b, op);
|
|
98
|
-
return new Bool(negated ? !result : result);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export const condition = defineType(Condition, 'Condition');
|
|
103
|
-
//# sourceMappingURL=condition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../src/tree/condition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAqB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAqB,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAqB9E,MAAM,OAAO,SAAU,SAAQ,IAAsC;IACnE,IAAI,GAAG,WAAoB,CAAC;IAC5B,SAAS,GAAG,WAAoB,CAAC;IAEjC,YAAY,KAAqB,EAAE,OAA0B,EAAE,QAAc,EAAE,WAAiB;QAC9F,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC7C,4EAA4E;QAC5E,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IAEQ,eAAe,CAAC,OAAsB;QAC7C,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAO,CAAC;QAC1B,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACnC,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC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AC"}
|
package/lib/tree/control.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Node, type LocationInfo } 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 { VarDeclaration } from './declaration-var.js';
|
|
6
|
-
import { type PrintOptions } from './util/print.js';
|
|
7
|
-
import type { MaybePromise } from '@jesscss/awaitable-pipe';
|
|
8
|
-
export type ForPattern = {
|
|
9
|
-
kind: 'single';
|
|
10
|
-
value: VarDeclaration;
|
|
11
|
-
} | {
|
|
12
|
-
kind: 'tuple';
|
|
13
|
-
values: [VarDeclaration, ...VarDeclaration[]];
|
|
14
|
-
};
|
|
15
|
-
export type ForIterable = {
|
|
16
|
-
kind: 'node';
|
|
17
|
-
value: Node;
|
|
18
|
-
} | {
|
|
19
|
-
kind: 'range';
|
|
20
|
-
start: Node;
|
|
21
|
-
end: Node;
|
|
22
|
-
step?: Node;
|
|
23
|
-
includeStart: boolean;
|
|
24
|
-
includeEnd: boolean;
|
|
25
|
-
};
|
|
26
|
-
type LegacyLoopValue = {
|
|
27
|
-
header: Sequence;
|
|
28
|
-
rules: Rules;
|
|
29
|
-
};
|
|
30
|
-
export type IfBranch = {
|
|
31
|
-
/** Undefined means "else" branch */
|
|
32
|
-
condition?: Node;
|
|
33
|
-
rules: Rules;
|
|
34
|
-
};
|
|
35
|
-
export type IfValue = {
|
|
36
|
-
branches: IfBranch[];
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* A control-flow block that serializes as:
|
|
40
|
-
* - `$if (...) { ... }`
|
|
41
|
-
* - `$else if (...) { ... }`
|
|
42
|
-
* - `$else { ... }`
|
|
43
|
-
*
|
|
44
|
-
* This is language-agnostic: it’s the canonical Jess control node.
|
|
45
|
-
*/
|
|
46
|
-
export declare class If extends Node<IfValue> {
|
|
47
|
-
type: "If";
|
|
48
|
-
shortType: "if";
|
|
49
|
-
allowRoot: boolean;
|
|
50
|
-
allowRuleRoot: boolean;
|
|
51
|
-
constructor(value: IfValue, options?: any, location?: LocationInfo, treeContext?: TreeContext);
|
|
52
|
-
toTrimmedString(options?: PrintOptions): string;
|
|
53
|
-
}
|
|
54
|
-
export type StructuredLoopValue = {
|
|
55
|
-
pattern: ForPattern;
|
|
56
|
-
iterable: ForIterable;
|
|
57
|
-
rules: Rules;
|
|
58
|
-
};
|
|
59
|
-
export type LoopValue = StructuredLoopValue | LegacyLoopValue;
|
|
60
|
-
/**
|
|
61
|
-
* `$for <header> { ... }`
|
|
62
|
-
*/
|
|
63
|
-
export declare class For extends Node<StructuredLoopValue> {
|
|
64
|
-
type: "For";
|
|
65
|
-
shortType: "for";
|
|
66
|
-
allowRoot: boolean;
|
|
67
|
-
allowRuleRoot: boolean;
|
|
68
|
-
constructor(value: LoopValue, options?: any, location?: LocationInfo, treeContext?: TreeContext);
|
|
69
|
-
preEval(context: Context): MaybePromise<Node>;
|
|
70
|
-
evalNode(context: Context): MaybePromise<Node>;
|
|
71
|
-
toTrimmedString(options?: PrintOptions): string;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* `$each <header> { ... }`
|
|
75
|
-
*/
|
|
76
|
-
export declare class Each extends Node<LegacyLoopValue> {
|
|
77
|
-
type: "Each";
|
|
78
|
-
shortType: "each";
|
|
79
|
-
allowRoot: boolean;
|
|
80
|
-
allowRuleRoot: boolean;
|
|
81
|
-
constructor(value: LegacyLoopValue, options?: any, location?: LocationInfo, treeContext?: TreeContext);
|
|
82
|
-
toTrimmedString(options?: PrintOptions): string;
|
|
83
|
-
}
|
|
84
|
-
export type WhileValue = {
|
|
85
|
-
condition: Node;
|
|
86
|
-
rules: Rules;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* `$while (<condition>) { ... }`
|
|
90
|
-
*/
|
|
91
|
-
export declare class While extends Node<WhileValue> {
|
|
92
|
-
type: "While";
|
|
93
|
-
shortType: "while";
|
|
94
|
-
allowRoot: boolean;
|
|
95
|
-
allowRuleRoot: boolean;
|
|
96
|
-
constructor(value: WhileValue, options?: any, location?: LocationInfo, treeContext?: TreeContext);
|
|
97
|
-
toTrimmedString(options?: PrintOptions): string;
|
|
98
|
-
}
|
|
99
|
-
export declare const ifNode: (value?: IfValue | undefined, options?: any, location?: LocationInfo | undefined) => If;
|
|
100
|
-
export declare const forNode: (value?: LoopValue | undefined, options?: any, location?: LocationInfo | undefined) => For;
|
|
101
|
-
export declare const eachNode: (value?: LegacyLoopValue | undefined, options?: any, location?: LocationInfo | undefined) => Each;
|
|
102
|
-
export declare const whileNode: (value?: WhileValue | undefined, options?: any, location?: LocationInfo | undefined) => While;
|
|
103
|
-
export {};
|
|
104
|
-
//# sourceMappingURL=control.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../../src/tree/control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoD,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtG,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAmB5D,MAAM,MAAM,UAAU,GAClB;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,cAAc,CAAC;CACvB,GACC;IACA,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,CAAC,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC,CAAC;CAC/C,CAAC;AAEJ,MAAM,MAAM,WAAW,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QAAQ,mGAAmC,CAAC;AACzD,eAAO,MAAM,SAAS,+FAAsC,CAAC"}
|
package/lib/tree/control.js
DELETED
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
import { Node, defineType, F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC } from './node.js';
|
|
2
|
-
import { Rules } from './rules.js';
|
|
3
|
-
import { Sequence } from './sequence.js';
|
|
4
|
-
import { Any } from './any.js';
|
|
5
|
-
import { Num } from './number.js';
|
|
6
|
-
import { VarDeclaration } from './declaration-var.js';
|
|
7
|
-
import { isNode } from './util/is-node.js';
|
|
8
|
-
import { getPrintOptions } from './util/print.js';
|
|
9
|
-
import { Block } from './block.js';
|
|
10
|
-
import { Range } from './range.js';
|
|
11
|
-
import { List } from './list.js';
|
|
12
|
-
const PUBLIC_RULE_VISIBILITY = {
|
|
13
|
-
Declaration: 'public',
|
|
14
|
-
Ruleset: 'public',
|
|
15
|
-
VarDeclaration: 'public',
|
|
16
|
-
Mixin: 'public'
|
|
17
|
-
};
|
|
18
|
-
function makeDirectiveRulesPublic(rules) {
|
|
19
|
-
rules.options.rulesVisibility = {
|
|
20
|
-
...rules.options.rulesVisibility,
|
|
21
|
-
...PUBLIC_RULE_VISIBILITY
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function parsePatternNode(patternNode) {
|
|
25
|
-
if (isNode(patternNode, 'VarDeclaration')) {
|
|
26
|
-
return { kind: 'single', value: patternNode };
|
|
27
|
-
}
|
|
28
|
-
if (isNode(patternNode, 'Block') && patternNode.options?.type === 'square' && isNode(patternNode.value, 'List')) {
|
|
29
|
-
const values = patternNode.value.value.filter((entry) => isNode(entry, 'VarDeclaration'));
|
|
30
|
-
if (values.length === 1) {
|
|
31
|
-
return { kind: 'single', value: values[0] };
|
|
32
|
-
}
|
|
33
|
-
if (values.length > 1) {
|
|
34
|
-
return { kind: 'tuple', values: values };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (isNode(patternNode, ['List', 'Sequence'])) {
|
|
38
|
-
const values = patternNode.value.filter((entry) => isNode(entry, 'VarDeclaration'));
|
|
39
|
-
if (values.length === 1) {
|
|
40
|
-
return { kind: 'single', value: values[0] };
|
|
41
|
-
}
|
|
42
|
-
if (values.length > 1) {
|
|
43
|
-
return { kind: 'tuple', values: values };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
throw new Error('Invalid $for pattern: expected one or more variables');
|
|
47
|
-
}
|
|
48
|
-
function parseLegacyHeader(header) {
|
|
49
|
-
const headerNode = header.value[0];
|
|
50
|
-
const inner = isNode(headerNode, 'Paren') && headerNode.value
|
|
51
|
-
? headerNode.value
|
|
52
|
-
: headerNode;
|
|
53
|
-
const sequence = isNode(inner, 'Sequence')
|
|
54
|
-
? inner.value
|
|
55
|
-
: [inner].filter(Boolean);
|
|
56
|
-
const ofIndex = sequence.findIndex(node => isNode(node, 'Any') && node.valueOf() === 'of');
|
|
57
|
-
if (ofIndex <= 0 || ofIndex >= sequence.length - 1) {
|
|
58
|
-
throw new Error('Invalid $for header: expected "<pattern> of <iterable>"');
|
|
59
|
-
}
|
|
60
|
-
const patternParts = sequence.slice(0, ofIndex);
|
|
61
|
-
const iterableParts = sequence.slice(ofIndex + 1);
|
|
62
|
-
const patternNode = patternParts.length === 1
|
|
63
|
-
? patternParts[0]
|
|
64
|
-
: new Sequence(patternParts);
|
|
65
|
-
const iterableNode = iterableParts.length === 1
|
|
66
|
-
? iterableParts[0]
|
|
67
|
-
: new Sequence(iterableParts);
|
|
68
|
-
let iterable;
|
|
69
|
-
if (isNode(iterableNode, 'Range')) {
|
|
70
|
-
iterable = {
|
|
71
|
-
kind: 'range',
|
|
72
|
-
start: iterableNode.value.start,
|
|
73
|
-
end: iterableNode.value.end,
|
|
74
|
-
step: iterableNode.value.step,
|
|
75
|
-
includeStart: iterableNode.options?.includeStart !== false,
|
|
76
|
-
includeEnd: iterableNode.options?.includeEnd !== false
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
iterable = { kind: 'node', value: iterableNode };
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
pattern: parsePatternNode(patternNode),
|
|
84
|
-
iterable
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function getBindingNames(pattern) {
|
|
88
|
-
if (pattern.kind === 'single') {
|
|
89
|
-
return [pattern.value.value.name.valueOf()];
|
|
90
|
-
}
|
|
91
|
-
if (pattern.kind === 'tuple') {
|
|
92
|
-
return pattern.values.map(entry => entry.value.name.valueOf());
|
|
93
|
-
}
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
function patternToNode(pattern) {
|
|
97
|
-
if (pattern.kind === 'single') {
|
|
98
|
-
return pattern.value;
|
|
99
|
-
}
|
|
100
|
-
return new Block(new List([...pattern.values], { sep: ',' }), { type: 'square' });
|
|
101
|
-
}
|
|
102
|
-
function iterableToNode(iterable) {
|
|
103
|
-
if (iterable.kind === 'node') {
|
|
104
|
-
return iterable.value;
|
|
105
|
-
}
|
|
106
|
-
return new Range({
|
|
107
|
-
start: iterable.start,
|
|
108
|
-
end: iterable.end,
|
|
109
|
-
step: iterable.step
|
|
110
|
-
}, {
|
|
111
|
-
includeStart: iterable.includeStart,
|
|
112
|
-
includeEnd: iterable.includeEnd
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async function* resolveEntries(input, context) {
|
|
116
|
-
if (isNode(input, 'Expression')) {
|
|
117
|
-
yield* resolveEntries(await input.value.eval(context), context);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (isNode(input, 'Call')) {
|
|
121
|
-
const evald = await input.eval(context);
|
|
122
|
-
if (isNode(evald, 'Call')) {
|
|
123
|
-
yield [evald, 0];
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
yield* resolveEntries(evald, context);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if ((isNode(input, 'Sequence') || isNode(input, 'List')) && Array.isArray(input.value)) {
|
|
130
|
-
for (let key = 0; key < input.value.length; key++) {
|
|
131
|
-
const value = input.value[key];
|
|
132
|
-
yield [value, key];
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (isNode(input, ['Rules', 'Ruleset', 'Mixin'])) {
|
|
137
|
-
const rules = isNode(input, 'Rules')
|
|
138
|
-
? input.value
|
|
139
|
-
: isNode(input, 'Ruleset')
|
|
140
|
-
? (input.value.rules?.value ?? [])
|
|
141
|
-
: (input.value.rules?.value ?? []);
|
|
142
|
-
for (const rule of rules) {
|
|
143
|
-
if (!rule || isNode(rule, 'Comment')) {
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (!isNode(rule, 'Declaration')) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
yield [rule.value.value, rule.value.name];
|
|
150
|
-
}
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
yield [input, 0];
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* A control-flow block that serializes as:
|
|
157
|
-
* - `$if (...) { ... }`
|
|
158
|
-
* - `$else if (...) { ... }`
|
|
159
|
-
* - `$else { ... }`
|
|
160
|
-
*
|
|
161
|
-
* This is language-agnostic: it’s the canonical Jess control node.
|
|
162
|
-
*/
|
|
163
|
-
export class If extends Node {
|
|
164
|
-
type = 'If';
|
|
165
|
-
shortType = 'if';
|
|
166
|
-
allowRoot = true;
|
|
167
|
-
allowRuleRoot = true;
|
|
168
|
-
constructor(value, options, location, treeContext) {
|
|
169
|
-
super(value, options, location, treeContext);
|
|
170
|
-
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
171
|
-
for (const branch of value.branches) {
|
|
172
|
-
makeDirectiveRulesPublic(branch.rules);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
toTrimmedString(options) {
|
|
176
|
-
options = getPrintOptions(options);
|
|
177
|
-
const w = options.writer;
|
|
178
|
-
const mark = w.mark();
|
|
179
|
-
const [first, ...rest] = this.value.branches;
|
|
180
|
-
w.add('$if', this);
|
|
181
|
-
w.add(' (');
|
|
182
|
-
first?.condition?.toString(options);
|
|
183
|
-
w.add(') ');
|
|
184
|
-
first?.rules.toBraced(options);
|
|
185
|
-
for (const br of rest) {
|
|
186
|
-
if (br.condition) {
|
|
187
|
-
w.add(' $else if (');
|
|
188
|
-
br.condition.toString(options);
|
|
189
|
-
w.add(') ');
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
w.add(' $else ');
|
|
193
|
-
}
|
|
194
|
-
br.rules.toBraced(options);
|
|
195
|
-
}
|
|
196
|
-
return w.getSince(mark);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* `$for <header> { ... }`
|
|
201
|
-
*/
|
|
202
|
-
export class For extends Node {
|
|
203
|
-
type = 'For';
|
|
204
|
-
shortType = 'for';
|
|
205
|
-
allowRoot = true;
|
|
206
|
-
allowRuleRoot = true;
|
|
207
|
-
constructor(value, options, location, treeContext) {
|
|
208
|
-
const normalized = ('header' in value)
|
|
209
|
-
? (() => {
|
|
210
|
-
const parsed = parseLegacyHeader(value.header);
|
|
211
|
-
return {
|
|
212
|
-
pattern: parsed.pattern,
|
|
213
|
-
iterable: parsed.iterable,
|
|
214
|
-
rules: value.rules
|
|
215
|
-
};
|
|
216
|
-
})()
|
|
217
|
-
: value;
|
|
218
|
-
super(normalized, options, location, treeContext);
|
|
219
|
-
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
220
|
-
makeDirectiveRulesPublic(normalized.rules);
|
|
221
|
-
}
|
|
222
|
-
preEval(context) {
|
|
223
|
-
if (!this.preEvaluated) {
|
|
224
|
-
const node = this.maybeClone(context);
|
|
225
|
-
node.preEvaluated = true;
|
|
226
|
-
return node;
|
|
227
|
-
}
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
evalNode(context) {
|
|
231
|
-
const { pattern, iterable } = this.value;
|
|
232
|
-
const bindingNames = getBindingNames(pattern);
|
|
233
|
-
if (bindingNames.length === 0) {
|
|
234
|
-
throw new Error('Invalid $for header: missing binding variable');
|
|
235
|
-
}
|
|
236
|
-
const run = async () => {
|
|
237
|
-
const accumulatedNodes = [];
|
|
238
|
-
let counter = 1;
|
|
239
|
-
const evaluatedIterable = await iterableToNode(iterable).eval(context);
|
|
240
|
-
for await (const [value, key] of resolveEntries(evaluatedIterable, context)) {
|
|
241
|
-
const loopRules = this.value.rules.clone(true);
|
|
242
|
-
// Preserve definition-scope parent chain so nested calls/lookups
|
|
243
|
-
// inside loop bodies resolve the same way as the original rules.
|
|
244
|
-
loopRules.inherit(this.value.rules);
|
|
245
|
-
if (accumulatedNodes.length > 0) {
|
|
246
|
-
// Make prior iteration output visible to current iteration lookups
|
|
247
|
-
// (e.g. `index+: @index`, `padding+_: ...`) without mutating emitted nodes.
|
|
248
|
-
const priorScope = new Rules(accumulatedNodes.map(n => n.copy(true)));
|
|
249
|
-
priorScope.inherit(this.value.rules);
|
|
250
|
-
priorScope.adopt(loopRules);
|
|
251
|
-
}
|
|
252
|
-
const resolvedValue = await value.eval(context);
|
|
253
|
-
let resolvedKey;
|
|
254
|
-
if (typeof key === 'number') {
|
|
255
|
-
resolvedKey = new Num(key + 1);
|
|
256
|
-
}
|
|
257
|
-
else if (typeof key === 'string' && key === 'value') {
|
|
258
|
-
resolvedKey = new Num(counter);
|
|
259
|
-
}
|
|
260
|
-
else if (isNode(key)) {
|
|
261
|
-
resolvedKey = await key.eval(context);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
resolvedKey = new Any(String(key), { role: 'property' });
|
|
265
|
-
}
|
|
266
|
-
const bindings = [resolvedValue, resolvedKey, new Num(counter)];
|
|
267
|
-
for (let i = Math.min(bindingNames.length, bindings.length) - 1; i >= 0; i--) {
|
|
268
|
-
loopRules.value.unshift(new VarDeclaration({
|
|
269
|
-
name: new Any(bindingNames[i], { role: 'property' }),
|
|
270
|
-
value: bindings[i]
|
|
271
|
-
}));
|
|
272
|
-
}
|
|
273
|
-
counter++;
|
|
274
|
-
const result = await loopRules.eval(context);
|
|
275
|
-
if (isNode(result, 'Rules')) {
|
|
276
|
-
for (const outNode of result.value) {
|
|
277
|
-
if (isNode(outNode, 'Declaration')) {
|
|
278
|
-
const normalizedFromAssign = outNode.options.normalizedFromAssign;
|
|
279
|
-
const outName = String(outNode.value.name);
|
|
280
|
-
const isMergedAssignment = normalizedFromAssign === "+:" /* AssignmentType.Add */
|
|
281
|
-
|| normalizedFromAssign === "&,:" /* AssignmentType.MergeList */
|
|
282
|
-
|| normalizedFromAssign === "&_:" /* AssignmentType.MergeSequence */;
|
|
283
|
-
// Keep manual by-name coalescing narrowly scoped to legacy padding merges.
|
|
284
|
-
// `index` declarations in plain loop bodies should remain per-iteration.
|
|
285
|
-
const shouldCoalesceByName = outName === 'padding';
|
|
286
|
-
if (isMergedAssignment || shouldCoalesceByName) {
|
|
287
|
-
let firstMatch = -1;
|
|
288
|
-
for (let i = 0; i < accumulatedNodes.length; i++) {
|
|
289
|
-
const prev = accumulatedNodes[i];
|
|
290
|
-
if (isNode(prev, 'Declaration') && String(prev.value.name) === outName) {
|
|
291
|
-
firstMatch = i;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (firstMatch >= 0) {
|
|
296
|
-
const prev = accumulatedNodes[firstMatch];
|
|
297
|
-
if (isNode(prev, 'Declaration')) {
|
|
298
|
-
const prevValue = prev.value.value;
|
|
299
|
-
const nextValue = outNode.value.value;
|
|
300
|
-
if (normalizedFromAssign === "+:" /* AssignmentType.Add */
|
|
301
|
-
|| normalizedFromAssign === "&,:" /* AssignmentType.MergeList */) {
|
|
302
|
-
const prevItems = isNode(prevValue, 'List')
|
|
303
|
-
? prevValue.value
|
|
304
|
-
: [prevValue];
|
|
305
|
-
const nextItems = isNode(nextValue, 'List')
|
|
306
|
-
? nextValue.value
|
|
307
|
-
: [nextValue];
|
|
308
|
-
const nextAlreadyIncludesPrev = nextItems.length >= prevItems.length
|
|
309
|
-
&& prevItems.every((item, idx) => String(item.valueOf()) === String(nextItems[idx]?.valueOf()));
|
|
310
|
-
const mergedItems = nextAlreadyIncludesPrev
|
|
311
|
-
? [...nextItems]
|
|
312
|
-
: [...prevItems, ...nextItems];
|
|
313
|
-
outNode.value.value = new List(mergedItems).inherit(outNode.value.value);
|
|
314
|
-
}
|
|
315
|
-
else if (normalizedFromAssign === "&_:" /* AssignmentType.MergeSequence */) {
|
|
316
|
-
const prevItems = isNode(prevValue, 'Sequence')
|
|
317
|
-
? prevValue.value
|
|
318
|
-
: [prevValue];
|
|
319
|
-
const nextItems = isNode(nextValue, 'Sequence')
|
|
320
|
-
? nextValue.value
|
|
321
|
-
: [nextValue];
|
|
322
|
-
const nextAlreadyIncludesPrev = nextItems.length >= prevItems.length
|
|
323
|
-
&& prevItems.every((item, idx) => String(item.valueOf()) === String(nextItems[idx]?.valueOf()));
|
|
324
|
-
const mergedItems = nextAlreadyIncludesPrev
|
|
325
|
-
? [...nextItems]
|
|
326
|
-
: [...prevItems, ...nextItems];
|
|
327
|
-
outNode.value.value = new Sequence(mergedItems).inherit(outNode.value.value);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
accumulatedNodes[firstMatch] = outNode;
|
|
331
|
-
for (let i = accumulatedNodes.length - 1; i > firstMatch; i--) {
|
|
332
|
-
const prev = accumulatedNodes[i];
|
|
333
|
-
if (isNode(prev, 'Declaration') && String(prev.value.name) === outName) {
|
|
334
|
-
accumulatedNodes.splice(i, 1);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
// Keep merged declarations before nested rulesets to avoid split-output
|
|
340
|
-
// duplicate selectors (e.g. `.each { ... }` then another `.each { ... }`).
|
|
341
|
-
let firstNestedRuleset = -1;
|
|
342
|
-
for (let i = 0; i < accumulatedNodes.length; i++) {
|
|
343
|
-
if (isNode(accumulatedNodes[i], ['Ruleset', 'Rules'])) {
|
|
344
|
-
firstNestedRuleset = i;
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (firstNestedRuleset >= 0) {
|
|
349
|
-
accumulatedNodes.splice(firstNestedRuleset, 0, outNode);
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
accumulatedNodes.push(outNode);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
accumulatedNodes.push(result);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return new Rules(accumulatedNodes);
|
|
362
|
-
};
|
|
363
|
-
return run();
|
|
364
|
-
}
|
|
365
|
-
toTrimmedString(options) {
|
|
366
|
-
options = getPrintOptions(options);
|
|
367
|
-
const w = options.writer;
|
|
368
|
-
const mark = w.mark();
|
|
369
|
-
w.add('$for ', this);
|
|
370
|
-
w.add('(');
|
|
371
|
-
patternToNode(this.value.pattern).toString(options);
|
|
372
|
-
w.add(' of ');
|
|
373
|
-
iterableToNode(this.value.iterable).toString(options);
|
|
374
|
-
w.add(')');
|
|
375
|
-
w.add(' ');
|
|
376
|
-
this.value.rules.toBraced(options);
|
|
377
|
-
return w.getSince(mark);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* `$each <header> { ... }`
|
|
382
|
-
*/
|
|
383
|
-
export class Each extends Node {
|
|
384
|
-
type = 'Each';
|
|
385
|
-
shortType = 'each';
|
|
386
|
-
allowRoot = true;
|
|
387
|
-
allowRuleRoot = true;
|
|
388
|
-
constructor(value, options, location, treeContext) {
|
|
389
|
-
super(value, options, location, treeContext);
|
|
390
|
-
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
391
|
-
}
|
|
392
|
-
toTrimmedString(options) {
|
|
393
|
-
options = getPrintOptions(options);
|
|
394
|
-
const w = options.writer;
|
|
395
|
-
const mark = w.mark();
|
|
396
|
-
w.add('$each ', this);
|
|
397
|
-
this.value.header.toString(options);
|
|
398
|
-
w.add(' ');
|
|
399
|
-
this.value.rules.toBraced(options);
|
|
400
|
-
return w.getSince(mark);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* `$while (<condition>) { ... }`
|
|
405
|
-
*/
|
|
406
|
-
export class While extends Node {
|
|
407
|
-
type = 'While';
|
|
408
|
-
shortType = 'while';
|
|
409
|
-
allowRoot = true;
|
|
410
|
-
allowRuleRoot = true;
|
|
411
|
-
constructor(value, options, location, treeContext) {
|
|
412
|
-
super(value, options, location, treeContext);
|
|
413
|
-
this.addFlags(F_VISIBLE, F_NON_STATIC, F_MAY_ASYNC);
|
|
414
|
-
}
|
|
415
|
-
toTrimmedString(options) {
|
|
416
|
-
options = getPrintOptions(options);
|
|
417
|
-
const w = options.writer;
|
|
418
|
-
const mark = w.mark();
|
|
419
|
-
w.add('$while (', this);
|
|
420
|
-
this.value.condition.toString(options);
|
|
421
|
-
w.add(') ');
|
|
422
|
-
this.value.rules.toBraced(options);
|
|
423
|
-
return w.getSince(mark);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
export const ifNode = defineType(If, 'If', 'if');
|
|
427
|
-
export const forNode = defineType(For, 'For', 'for');
|
|
428
|
-
export const eachNode = defineType(Each, 'Each', 'each');
|
|
429
|
-
export const whileNode = defineType(While, 'While', 'while');
|
|
430
|
-
//# sourceMappingURL=control.js.map
|