less 4.5.1 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -5
- package/bin/lessc +37 -23
- package/dist/less.js +14501 -11745
- package/dist/less.min.js +4 -4
- package/dist/less.min.js.map +1 -1
- package/index.cjs +41 -0
- package/lib/less/constants.js +5 -7
- package/lib/less/contexts.js +71 -55
- package/lib/less/data/colors.js +150 -153
- package/lib/less/data/index.js +4 -7
- package/lib/less/data/unit-conversions.js +2 -5
- package/lib/less/default-options.js +36 -26
- package/lib/less/deprecation.js +67 -0
- package/lib/less/environment/abstract-file-manager.js +62 -50
- package/lib/less/environment/abstract-plugin-loader.js +69 -46
- package/lib/less/environment/environment-api.ts +21 -0
- package/lib/less/environment/environment.js +34 -30
- package/lib/less/environment/file-manager-api.ts +77 -0
- package/lib/less/functions/boolean.js +13 -13
- package/lib/less/functions/color-blending.js +39 -31
- package/lib/less/functions/color.js +153 -137
- package/lib/less/functions/data-uri.js +73 -64
- package/lib/less/functions/default.js +9 -11
- package/lib/less/functions/function-caller.js +35 -34
- package/lib/less/functions/function-registry.js +16 -17
- package/lib/less/functions/index.js +33 -33
- package/lib/less/functions/list.js +88 -75
- package/lib/less/functions/math-helper.js +8 -11
- package/lib/less/functions/math.js +21 -21
- package/lib/less/functions/number.js +42 -53
- package/lib/less/functions/string.js +18 -22
- package/lib/less/functions/style.js +21 -20
- package/lib/less/functions/svg.js +83 -82
- package/lib/less/functions/types.js +28 -32
- package/lib/less/import-manager.js +73 -64
- package/lib/less/index.js +65 -65
- package/lib/less/less-error.js +63 -45
- package/lib/less/logger.js +11 -14
- package/lib/less/parse-tree.js +52 -53
- package/lib/less/parse.js +44 -44
- package/lib/less/parser/parser-input.js +151 -113
- package/lib/less/parser/parser.js +864 -658
- package/lib/less/plugin-manager.js +57 -46
- package/lib/less/render.js +17 -23
- package/lib/less/source-map-builder.js +52 -43
- package/lib/less/source-map-output.js +56 -43
- package/lib/less/transform-tree.js +40 -30
- package/lib/less/tree/anonymous.js +52 -28
- package/lib/less/tree/assignment.js +44 -27
- package/lib/less/tree/atrule-syntax.js +4 -6
- package/lib/less/tree/atrule.js +247 -140
- package/lib/less/tree/attribute.js +55 -24
- package/lib/less/tree/call.js +70 -42
- package/lib/less/tree/color.js +194 -145
- package/lib/less/tree/combinator.js +31 -21
- package/lib/less/tree/comment.js +44 -23
- package/lib/less/tree/condition.js +61 -36
- package/lib/less/tree/container.js +90 -34
- package/lib/less/tree/debug-info.js +28 -15
- package/lib/less/tree/declaration.js +97 -52
- package/lib/less/tree/detached-ruleset.js +42 -24
- package/lib/less/tree/dimension.js +127 -71
- package/lib/less/tree/element.js +82 -52
- package/lib/less/tree/expression.js +75 -50
- package/lib/less/tree/extend.js +71 -42
- package/lib/less/tree/import.js +184 -110
- package/lib/less/tree/index.js +52 -81
- package/lib/less/tree/javascript.js +43 -32
- package/lib/less/tree/js-eval-node.js +46 -32
- package/lib/less/tree/keyword.js +25 -17
- package/lib/less/tree/media.js +77 -35
- package/lib/less/tree/merge-rules.js +47 -0
- package/lib/less/tree/mixin-call.js +181 -98
- package/lib/less/tree/mixin-definition.js +211 -117
- package/lib/less/tree/namespace-value.js +63 -44
- package/lib/less/tree/negative.js +34 -21
- package/lib/less/tree/nested-at-rule.js +149 -66
- package/lib/less/tree/node.js +225 -90
- package/lib/less/tree/operation.js +59 -34
- package/lib/less/tree/paren.js +34 -17
- package/lib/less/tree/property.js +66 -35
- package/lib/less/tree/query-in-parens.js +52 -60
- package/lib/less/tree/quoted.js +93 -44
- package/lib/less/tree/ruleset.js +632 -318
- package/lib/less/tree/selector.js +151 -77
- package/lib/less/tree/unicode-descriptor.js +14 -12
- package/lib/less/tree/unit.js +111 -63
- package/lib/less/tree/url.js +62 -38
- package/lib/less/tree/value.js +50 -34
- package/lib/less/tree/variable-call.js +47 -30
- package/lib/less/tree/variable.js +53 -31
- package/lib/less/utils.js +44 -47
- package/lib/less/visitors/extend-visitor.js +233 -172
- package/lib/less/visitors/import-sequencer.js +24 -24
- package/lib/less/visitors/import-visitor.js +62 -52
- package/lib/less/visitors/index.js +14 -17
- package/lib/less/visitors/join-selector-visitor.js +40 -37
- package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
- package/lib/less/visitors/to-css-visitor.js +135 -128
- package/lib/less/visitors/visitor.js +60 -45
- package/lib/less-browser/add-default-options.js +23 -13
- package/lib/less-browser/bootstrap.js +23 -17
- package/lib/less-browser/browser.js +24 -21
- package/lib/less-browser/cache.js +17 -19
- package/lib/less-browser/error-reporting.js +52 -44
- package/lib/less-browser/file-manager.js +52 -42
- package/lib/less-browser/image-size.js +12 -12
- package/lib/less-browser/index.js +131 -105
- package/lib/less-browser/log-listener.js +30 -31
- package/lib/less-browser/plugin-loader.js +10 -10
- package/lib/less-browser/utils.js +19 -21
- package/lib/less-node/environment.js +32 -8
- package/lib/less-node/file-manager.js +62 -45
- package/lib/less-node/fs.js +11 -8
- package/lib/less-node/image-size.js +40 -31
- package/lib/less-node/index.js +28 -19
- package/lib/less-node/lessc-helper.js +20 -21
- package/lib/less-node/plugin-loader.js +35 -27
- package/lib/less-node/url-file-manager.js +33 -31
- package/package.json +29 -18
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -63
- package/Gruntfile.js +0 -403
- package/bower.json +0 -22
- package/lib/less/constants.js.map +0 -1
- package/lib/less/contexts.js.map +0 -1
- package/lib/less/data/colors.js.map +0 -1
- package/lib/less/data/index.js.map +0 -1
- package/lib/less/data/unit-conversions.js.map +0 -1
- package/lib/less/default-options.js.map +0 -1
- package/lib/less/environment/abstract-file-manager.js.map +0 -1
- package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
- package/lib/less/environment/environment-api.js +0 -3
- package/lib/less/environment/environment-api.js.map +0 -1
- package/lib/less/environment/environment.js.map +0 -1
- package/lib/less/environment/file-manager-api.js +0 -3
- package/lib/less/environment/file-manager-api.js.map +0 -1
- package/lib/less/functions/boolean.js.map +0 -1
- package/lib/less/functions/color-blending.js.map +0 -1
- package/lib/less/functions/color.js.map +0 -1
- package/lib/less/functions/data-uri.js.map +0 -1
- package/lib/less/functions/default.js.map +0 -1
- package/lib/less/functions/function-caller.js.map +0 -1
- package/lib/less/functions/function-registry.js.map +0 -1
- package/lib/less/functions/index.js.map +0 -1
- package/lib/less/functions/list.js.map +0 -1
- package/lib/less/functions/math-helper.js.map +0 -1
- package/lib/less/functions/math.js.map +0 -1
- package/lib/less/functions/number.js.map +0 -1
- package/lib/less/functions/string.js.map +0 -1
- package/lib/less/functions/style.js.map +0 -1
- package/lib/less/functions/svg.js.map +0 -1
- package/lib/less/functions/types.js.map +0 -1
- package/lib/less/import-manager.js.map +0 -1
- package/lib/less/index.js.map +0 -1
- package/lib/less/less-error.js.map +0 -1
- package/lib/less/logger.js.map +0 -1
- package/lib/less/parse-tree.js.map +0 -1
- package/lib/less/parse.js.map +0 -1
- package/lib/less/parser/parser-input.js.map +0 -1
- package/lib/less/parser/parser.js.map +0 -1
- package/lib/less/plugin-manager.js.map +0 -1
- package/lib/less/render.js.map +0 -1
- package/lib/less/source-map-builder.js.map +0 -1
- package/lib/less/source-map-output.js.map +0 -1
- package/lib/less/transform-tree.js.map +0 -1
- package/lib/less/tree/anonymous.js.map +0 -1
- package/lib/less/tree/assignment.js.map +0 -1
- package/lib/less/tree/atrule-syntax.js.map +0 -1
- package/lib/less/tree/atrule.js.map +0 -1
- package/lib/less/tree/attribute.js.map +0 -1
- package/lib/less/tree/call.js.map +0 -1
- package/lib/less/tree/color.js.map +0 -1
- package/lib/less/tree/combinator.js.map +0 -1
- package/lib/less/tree/comment.js.map +0 -1
- package/lib/less/tree/condition.js.map +0 -1
- package/lib/less/tree/container.js.map +0 -1
- package/lib/less/tree/debug-info.js.map +0 -1
- package/lib/less/tree/declaration.js.map +0 -1
- package/lib/less/tree/detached-ruleset.js.map +0 -1
- package/lib/less/tree/dimension.js.map +0 -1
- package/lib/less/tree/element.js.map +0 -1
- package/lib/less/tree/expression.js.map +0 -1
- package/lib/less/tree/extend.js.map +0 -1
- package/lib/less/tree/import.js.map +0 -1
- package/lib/less/tree/index.js.map +0 -1
- package/lib/less/tree/javascript.js.map +0 -1
- package/lib/less/tree/js-eval-node.js.map +0 -1
- package/lib/less/tree/keyword.js.map +0 -1
- package/lib/less/tree/media.js.map +0 -1
- package/lib/less/tree/mixin-call.js.map +0 -1
- package/lib/less/tree/mixin-definition.js.map +0 -1
- package/lib/less/tree/namespace-value.js.map +0 -1
- package/lib/less/tree/negative.js.map +0 -1
- package/lib/less/tree/nested-at-rule.js.map +0 -1
- package/lib/less/tree/node.js.map +0 -1
- package/lib/less/tree/operation.js.map +0 -1
- package/lib/less/tree/paren.js.map +0 -1
- package/lib/less/tree/property.js.map +0 -1
- package/lib/less/tree/query-in-parens.js.map +0 -1
- package/lib/less/tree/quoted.js.map +0 -1
- package/lib/less/tree/ruleset.js.map +0 -1
- package/lib/less/tree/selector.js.map +0 -1
- package/lib/less/tree/unicode-descriptor.js.map +0 -1
- package/lib/less/tree/unit.js.map +0 -1
- package/lib/less/tree/url.js.map +0 -1
- package/lib/less/tree/value.js.map +0 -1
- package/lib/less/tree/variable-call.js.map +0 -1
- package/lib/less/tree/variable.js.map +0 -1
- package/lib/less/utils.js.map +0 -1
- package/lib/less/visitors/extend-visitor.js.map +0 -1
- package/lib/less/visitors/import-sequencer.js.map +0 -1
- package/lib/less/visitors/import-visitor.js.map +0 -1
- package/lib/less/visitors/index.js.map +0 -1
- package/lib/less/visitors/join-selector-visitor.js.map +0 -1
- package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
- package/lib/less/visitors/to-css-visitor.js.map +0 -1
- package/lib/less/visitors/visitor.js.map +0 -1
- package/lib/less-browser/add-default-options.js.map +0 -1
- package/lib/less-browser/bootstrap.js.map +0 -1
- package/lib/less-browser/browser.js.map +0 -1
- package/lib/less-browser/cache.js.map +0 -1
- package/lib/less-browser/error-reporting.js.map +0 -1
- package/lib/less-browser/file-manager.js.map +0 -1
- package/lib/less-browser/image-size.js.map +0 -1
- package/lib/less-browser/index.js.map +0 -1
- package/lib/less-browser/log-listener.js.map +0 -1
- package/lib/less-browser/plugin-loader.js.map +0 -1
- package/lib/less-browser/utils.js.map +0 -1
- package/lib/less-node/environment.js.map +0 -1
- package/lib/less-node/file-manager.js.map +0 -1
- package/lib/less-node/fs.js.map +0 -1
- package/lib/less-node/image-size.js.map +0 -1
- package/lib/less-node/index.js.map +0 -1
- package/lib/less-node/lessc-helper.js.map +0 -1
- package/lib/less-node/plugin-loader.js.map +0 -1
- package/lib/less-node/url-file-manager.js.map +0 -1
- package/scripts/coverage-lines.js +0 -207
- package/scripts/coverage-report.js +0 -158
- package/scripts/postinstall.js +0 -61
- package/test/.eslintrc.json +0 -9
- package/test/README.md +0 -3
- package/test/browser/common.js +0 -251
- package/test/browser/css/global-vars/simple.css +0 -3
- package/test/browser/css/modify-vars/simple.css +0 -8
- package/test/browser/css/plugin/plugin.css +0 -3
- package/test/browser/css/postProcessor/postProcessor.css +0 -4
- package/test/browser/css/relative-urls/urls.css +0 -36
- package/test/browser/css/rewrite-urls/urls.css +0 -36
- package/test/browser/css/rootpath/urls.css +0 -35
- package/test/browser/css/rootpath-relative/urls.css +0 -35
- package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
- package/test/browser/css/urls.css +0 -54
- package/test/browser/generator/benchmark.config.js +0 -50
- package/test/browser/generator/generate.js +0 -78
- package/test/browser/generator/runner.config.js +0 -184
- package/test/browser/generator/runner.js +0 -2
- package/test/browser/generator/template.js +0 -104
- package/test/browser/generator/utils.js +0 -14
- package/test/browser/less/console-errors/test-error.less +0 -3
- package/test/browser/less/console-errors/test-error.txt +0 -2
- package/test/browser/less/errors/image-height-error.less +0 -3
- package/test/browser/less/errors/image-height-error.txt +0 -4
- package/test/browser/less/errors/image-size-error.less +0 -3
- package/test/browser/less/errors/image-size-error.txt +0 -4
- package/test/browser/less/errors/image-width-error.less +0 -3
- package/test/browser/less/errors/image-width-error.txt +0 -4
- package/test/browser/less/global-vars/simple.less +0 -3
- package/test/browser/less/imports/urls.less +0 -4
- package/test/browser/less/imports/urls2.less +0 -4
- package/test/browser/less/modify-vars/imports/simple2.less +0 -4
- package/test/browser/less/modify-vars/simple.less +0 -8
- package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
- package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
- package/test/browser/less/plugin/plugin.js +0 -4
- package/test/browser/less/plugin/plugin.less +0 -4
- package/test/browser/less/postProcessor/postProcessor.less +0 -4
- package/test/browser/less/relative-urls/urls.less +0 -34
- package/test/browser/less/rewrite-urls/urls.less +0 -34
- package/test/browser/less/rootpath/urls.less +0 -33
- package/test/browser/less/rootpath-relative/urls.less +0 -33
- package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
- package/test/browser/less/urls.less +0 -62
- package/test/browser/runner-VisitorPlugin-options.js +0 -3
- package/test/browser/runner-VisitorPlugin.js +0 -3
- package/test/browser/runner-browser-options.js +0 -51
- package/test/browser/runner-browser-spec.js +0 -12
- package/test/browser/runner-console-errors.js +0 -5
- package/test/browser/runner-errors-options.js +0 -6
- package/test/browser/runner-errors-spec.js +0 -3
- package/test/browser/runner-filemanagerPlugin-options.js +0 -5
- package/test/browser/runner-filemanagerPlugin.js +0 -3
- package/test/browser/runner-global-vars-options.js +0 -7
- package/test/browser/runner-global-vars-spec.js +0 -3
- package/test/browser/runner-main-options.js +0 -17
- package/test/browser/runner-main-spec.js +0 -7
- package/test/browser/runner-modify-vars-options.js +0 -5
- package/test/browser/runner-modify-vars-spec.js +0 -33
- package/test/browser/runner-no-js-errors-options.js +0 -4
- package/test/browser/runner-no-js-errors-spec.js +0 -3
- package/test/browser/runner-postProcessorPlugin-options.js +0 -3
- package/test/browser/runner-postProcessorPlugin.js +0 -3
- package/test/browser/runner-preProcessorPlugin-options.js +0 -3
- package/test/browser/runner-preProcessorPlugin.js +0 -3
- package/test/browser/runner-production-options.js +0 -3
- package/test/browser/runner-production-spec.js +0 -5
- package/test/browser/runner-relative-urls-options.js +0 -3
- package/test/browser/runner-relative-urls-spec.js +0 -3
- package/test/browser/runner-rewrite-urls-options.js +0 -3
- package/test/browser/runner-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-options.js +0 -3
- package/test/browser/runner-rootpath-relative-options.js +0 -4
- package/test/browser/runner-rootpath-relative-spec.js +0 -3
- package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
- package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-spec.js +0 -3
- package/test/browser/runner-strict-units-options.js +0 -5
- package/test/browser/runner-strict-units-spec.js +0 -3
- package/test/index.js +0 -307
- package/test/less-test.js +0 -984
- package/test/mocha-playwright/runner.js +0 -210
- package/test/modify-vars.js +0 -28
- package/test/plugins/filemanager/index.js +0 -19
- package/test/plugins/postprocess/index.js +0 -14
- package/test/plugins/preprocess/index.js +0 -19
- package/test/plugins/visitor/index.js +0 -24
- package/test/sourcemaps/basic.json +0 -1
- package/test/sourcemaps/comprehensive.json +0 -1
- package/test/sourcemaps/custom-props.json +0 -1
- package/test/sourcemaps/index.html +0 -17
- package/test/sourcemaps/sourcemaps-basepath.json +0 -1
- package/test/sourcemaps/sourcemaps-include-source.json +0 -1
- package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
- package/test/sourcemaps/sourcemaps-url.json +0 -1
- package/test/sourcemaps-disable-annotation/basic.json +0 -1
- package/test/sourcemaps-variable-selector/basic.json +0 -1
- package/test/test-es6.ts +0 -17
- package/test.less +0 -1
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
package/lib/less/tree/comment.js
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, FileInfo } from './node.js' */
|
|
3
|
+
/** @import { DebugInfoContext } from './debug-info.js' */
|
|
4
|
+
import Node from './node.js';
|
|
5
|
+
import getDebugInfo from './debug-info.js';
|
|
6
|
+
|
|
7
|
+
class Comment extends Node {
|
|
8
|
+
get type() { return 'Comment'; }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} value
|
|
12
|
+
* @param {boolean} isLineComment
|
|
13
|
+
* @param {number} index
|
|
14
|
+
* @param {FileInfo} currentFileInfo
|
|
15
|
+
*/
|
|
16
|
+
constructor(value, isLineComment, index, currentFileInfo) {
|
|
17
|
+
super();
|
|
18
|
+
this.value = value;
|
|
19
|
+
this.isLineComment = isLineComment;
|
|
20
|
+
this._index = index;
|
|
21
|
+
this._fileInfo = currentFileInfo;
|
|
22
|
+
this.allowRoot = true;
|
|
23
|
+
/** @type {{ lineNumber: number, fileName: string } | undefined} */
|
|
24
|
+
this.debugInfo = undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {EvalContext} context
|
|
29
|
+
* @param {CSSOutput} output
|
|
30
|
+
*/
|
|
31
|
+
genCSS(context, output) {
|
|
16
32
|
if (this.debugInfo) {
|
|
17
|
-
output.add((
|
|
33
|
+
output.add(getDebugInfo(context, /** @type {DebugInfoContext} */ (this)), this.fileInfo(), this.getIndex());
|
|
18
34
|
}
|
|
19
|
-
output.add(this.value);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
output.add(/** @type {string} */ (this.value));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {EvalContext} context
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
isSilent(context) {
|
|
43
|
+
const isCompressed = context.compress && /** @type {string} */ (this.value)[2] !== '!';
|
|
23
44
|
return this.isLineComment || isCompressed;
|
|
24
45
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default Comment;
|
|
@@ -1,40 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, TreeVisitor } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
|
|
5
|
+
class Condition extends Node {
|
|
6
|
+
get type() { return 'Condition'; }
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} op
|
|
10
|
+
* @param {Node} l
|
|
11
|
+
* @param {Node} r
|
|
12
|
+
* @param {number} i
|
|
13
|
+
* @param {boolean} negate
|
|
14
|
+
*/
|
|
15
|
+
constructor(op, l, r, i, negate) {
|
|
16
|
+
super();
|
|
17
|
+
this.op = op.trim();
|
|
18
|
+
this.lvalue = l;
|
|
19
|
+
this.rvalue = r;
|
|
20
|
+
this._index = i;
|
|
21
|
+
this.negate = negate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {TreeVisitor} visitor */
|
|
25
|
+
accept(visitor) {
|
|
15
26
|
this.lvalue = visitor.visit(this.lvalue);
|
|
16
27
|
this.rvalue = visitor.visit(this.rvalue);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {EvalContext} context
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
* @suppress {checkTypes}
|
|
34
|
+
*/
|
|
35
|
+
// @ts-ignore - Condition.eval returns boolean, not Node (used as guard condition)
|
|
36
|
+
eval(context) {
|
|
37
|
+
const a = this.lvalue.eval(context);
|
|
38
|
+
const b = this.rvalue.eval(context);
|
|
39
|
+
/** @type {boolean} */
|
|
40
|
+
let result;
|
|
41
|
+
|
|
42
|
+
switch (this.op) {
|
|
43
|
+
case 'and': result = Boolean(a && b); break;
|
|
44
|
+
case 'or': result = Boolean(a || b); break;
|
|
45
|
+
default:
|
|
46
|
+
switch (Node.compare(a, b)) {
|
|
47
|
+
case -1:
|
|
48
|
+
result = this.op === '<' || this.op === '=<' || this.op === '<=';
|
|
49
|
+
break;
|
|
50
|
+
case 0:
|
|
51
|
+
result = this.op === '=' || this.op === '>=' || this.op === '=<' || this.op === '<=';
|
|
52
|
+
break;
|
|
53
|
+
case 1:
|
|
54
|
+
result = this.op === '>' || this.op === '>=';
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
result = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
36
61
|
return this.negate ? !result : result;
|
|
37
62
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default Condition;
|
|
@@ -1,48 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
+
/** @import { FunctionRegistry, NestableAtRuleThis } from './nested-at-rule.js' */
|
|
4
|
+
import Node from './node.js';
|
|
5
|
+
import Ruleset from './ruleset.js';
|
|
6
|
+
import Value from './value.js';
|
|
7
|
+
import Selector from './selector.js';
|
|
8
|
+
import AtRule from './atrule.js';
|
|
9
|
+
import NestableAtRulePrototype from './nested-at-rule.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Ruleset & {
|
|
13
|
+
* allowImports?: boolean,
|
|
14
|
+
* debugInfo?: { lineNumber: number, fileName: string },
|
|
15
|
+
* functionRegistry?: FunctionRegistry
|
|
16
|
+
* }} RulesetWithExtras
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
class Container extends AtRule {
|
|
20
|
+
get type() { return 'Container'; }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {Node[] | null} value
|
|
24
|
+
* @param {Node[]} features
|
|
25
|
+
* @param {number} index
|
|
26
|
+
* @param {FileInfo} currentFileInfo
|
|
27
|
+
* @param {VisibilityInfo} visibilityInfo
|
|
28
|
+
*/
|
|
29
|
+
constructor(value, features, index, currentFileInfo, visibilityInfo) {
|
|
30
|
+
super();
|
|
31
|
+
this._index = index;
|
|
32
|
+
this._fileInfo = currentFileInfo;
|
|
33
|
+
|
|
34
|
+
const selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();
|
|
35
|
+
|
|
36
|
+
/** @type {Value} */
|
|
37
|
+
this.features = new Value(features);
|
|
38
|
+
/** @type {RulesetWithExtras[]} */
|
|
39
|
+
this.rules = [new Ruleset(selectors, value)];
|
|
40
|
+
this.rules[0].allowImports = true;
|
|
41
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
42
|
+
this.allowRoot = true;
|
|
43
|
+
this.setParent(selectors, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
44
|
+
this.setParent(this.features, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
45
|
+
this.setParent(this.rules, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
46
|
+
|
|
47
|
+
/** @type {boolean | undefined} */
|
|
48
|
+
this._evaluated = undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {EvalContext} context
|
|
53
|
+
* @param {CSSOutput} output
|
|
54
|
+
*/
|
|
55
|
+
genCSS(context, output) {
|
|
23
56
|
output.add('@container ', this._fileInfo, this._index);
|
|
24
57
|
this.features.genCSS(context, output);
|
|
25
58
|
this.outputRuleset(context, output, this.rules);
|
|
26
|
-
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {EvalContext} context
|
|
63
|
+
* @returns {Node}
|
|
64
|
+
*/
|
|
65
|
+
eval(context) {
|
|
66
|
+
if (this._evaluated) {
|
|
67
|
+
return /** @type {Node} */ (/** @type {unknown} */ (this));
|
|
68
|
+
}
|
|
27
69
|
if (!context.mediaBlocks) {
|
|
28
70
|
context.mediaBlocks = [];
|
|
29
71
|
context.mediaPath = [];
|
|
30
72
|
}
|
|
31
|
-
|
|
73
|
+
|
|
74
|
+
const media = new Container(null, [], this._index, this._fileInfo, this.visibilityInfo());
|
|
75
|
+
media._evaluated = true;
|
|
32
76
|
if (this.debugInfo) {
|
|
33
77
|
this.rules[0].debugInfo = this.debugInfo;
|
|
34
78
|
media.debugInfo = this.debugInfo;
|
|
35
79
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
80
|
+
|
|
81
|
+
media.features = /** @type {Value} */ (this.features.eval(context));
|
|
82
|
+
|
|
83
|
+
context.mediaPath.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
84
|
+
context.mediaBlocks.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
85
|
+
|
|
86
|
+
const fr = /** @type {RulesetWithExtras} */ (context.frames[0]).functionRegistry;
|
|
87
|
+
if (fr) {
|
|
88
|
+
this.rules[0].functionRegistry = fr.inherit();
|
|
89
|
+
}
|
|
40
90
|
context.frames.unshift(this.rules[0]);
|
|
41
|
-
media.rules = [this.rules[0].eval(context)];
|
|
91
|
+
media.rules = [/** @type {RulesetWithExtras} */ (this.rules[0].eval(context))];
|
|
42
92
|
context.frames.shift();
|
|
93
|
+
|
|
43
94
|
context.mediaPath.pop();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
95
|
+
|
|
96
|
+
return context.mediaPath.length === 0 ? /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalTop(context) :
|
|
97
|
+
/** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalNested(context);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Apply NestableAtRulePrototype methods (accept, isRulesetLike override AtRule's versions)
|
|
102
|
+
Object.assign(Container.prototype, NestableAtRulePrototype);
|
|
103
|
+
|
|
104
|
+
export default Container;
|
|
@@ -1,41 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {object} DebugInfoData
|
|
5
|
+
* @property {number} lineNumber
|
|
6
|
+
* @property {string} fileName
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {object} DebugInfoContext
|
|
11
|
+
* @property {DebugInfoData} debugInfo
|
|
12
|
+
*/
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead.
|
|
5
16
|
* This will be removed in a future version.
|
|
6
17
|
*
|
|
7
|
-
* @param {
|
|
18
|
+
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
8
19
|
* @returns {string} Debug info as CSS comment
|
|
9
20
|
*/
|
|
10
21
|
function asComment(ctx) {
|
|
11
|
-
return
|
|
22
|
+
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
|
|
12
23
|
}
|
|
24
|
+
|
|
13
25
|
/**
|
|
14
26
|
* @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead.
|
|
15
27
|
* This function generates Sass-compatible debug info using @media -sass-debug-info syntax.
|
|
16
28
|
* This format had short-lived usage and is no longer recommended.
|
|
17
29
|
* This will be removed in a future version.
|
|
18
30
|
*
|
|
19
|
-
* @param {
|
|
31
|
+
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
20
32
|
* @returns {string} Sass-compatible debug info as @media query
|
|
21
33
|
*/
|
|
22
34
|
function asMediaQuery(ctx) {
|
|
23
|
-
|
|
35
|
+
let filenameWithProtocol = ctx.debugInfo.fileName;
|
|
24
36
|
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
|
|
25
|
-
filenameWithProtocol =
|
|
37
|
+
filenameWithProtocol = `file://${filenameWithProtocol}`;
|
|
26
38
|
}
|
|
27
|
-
return
|
|
39
|
+
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:/\\])/g, function (a) {
|
|
28
40
|
if (a == '\\') {
|
|
29
41
|
a = '/';
|
|
30
42
|
}
|
|
31
|
-
return
|
|
32
|
-
})
|
|
43
|
+
return `\\${a}`;
|
|
44
|
+
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
|
|
33
45
|
}
|
|
46
|
+
|
|
34
47
|
/**
|
|
35
48
|
* Generates debug information (line numbers) for CSS output.
|
|
36
49
|
*
|
|
37
|
-
* @param {
|
|
38
|
-
* @param {
|
|
50
|
+
* @param {{ dumpLineNumbers?: string, compress?: boolean }} context - Context object with dumpLineNumbers option
|
|
51
|
+
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
39
52
|
* @param {string} [lineSeparator] - Separator between comment and media query (for 'all' mode)
|
|
40
53
|
* @returns {string} Debug info string
|
|
41
54
|
*
|
|
@@ -45,7 +58,7 @@ function asMediaQuery(ctx) {
|
|
|
45
58
|
* which had short-lived usage and is no longer recommended.
|
|
46
59
|
*/
|
|
47
60
|
function debugInfo(context, ctx, lineSeparator) {
|
|
48
|
-
|
|
61
|
+
let result = '';
|
|
49
62
|
if (context.dumpLineNumbers && !context.compress) {
|
|
50
63
|
switch (context.dumpLineNumbers) {
|
|
51
64
|
case 'comments':
|
|
@@ -61,5 +74,5 @@ function debugInfo(context, ctx, lineSeparator) {
|
|
|
61
74
|
}
|
|
62
75
|
return result;
|
|
63
76
|
}
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
|
|
78
|
+
export default debugInfo;
|
|
@@ -1,58 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, FileInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
import Value from './value.js';
|
|
5
|
+
import Keyword from './keyword.js';
|
|
6
|
+
import Anonymous from './anonymous.js';
|
|
7
|
+
import * as Constants from '../constants.js';
|
|
8
|
+
const MATH = Constants.Math;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {EvalContext} context
|
|
12
|
+
* @param {Node[]} name
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
10
15
|
function evalName(context, name) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
let value = '';
|
|
17
|
+
let i;
|
|
18
|
+
const n = name.length;
|
|
19
|
+
/** @type {CSSOutput} */
|
|
20
|
+
const output = {add: function (s) {value += s;}, isEmpty: function() { return value === ''; }};
|
|
15
21
|
for (i = 0; i < n; i++) {
|
|
16
22
|
name[i].eval(context).genCSS(context, output);
|
|
17
23
|
}
|
|
18
24
|
return value;
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
|
|
27
|
+
class Declaration extends Node {
|
|
28
|
+
get type() { return 'Declaration'; }
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string | Node[]} name
|
|
32
|
+
* @param {Node | string | null} value
|
|
33
|
+
* @param {string} [important]
|
|
34
|
+
* @param {string} [merge]
|
|
35
|
+
* @param {number} [index]
|
|
36
|
+
* @param {FileInfo} [currentFileInfo]
|
|
37
|
+
* @param {boolean} [inline]
|
|
38
|
+
* @param {boolean} [variable]
|
|
39
|
+
*/
|
|
40
|
+
constructor(name, value, important, merge, index, currentFileInfo, inline, variable) {
|
|
41
|
+
super();
|
|
42
|
+
this.name = name;
|
|
43
|
+
this.value = (value instanceof Node) ? value : new Value([value ? new Anonymous(value) : null]);
|
|
44
|
+
this.important = important ? ` ${important.trim()}` : '';
|
|
45
|
+
/** @type {string | undefined} */
|
|
46
|
+
this.merge = merge;
|
|
47
|
+
this._index = index;
|
|
48
|
+
this._fileInfo = currentFileInfo;
|
|
49
|
+
/** @type {boolean} */
|
|
50
|
+
this.inline = inline || false;
|
|
51
|
+
/** @type {boolean} */
|
|
52
|
+
this.variable = (variable !== undefined) ? variable
|
|
53
|
+
: (typeof name === 'string' && name.charAt(0) === '@');
|
|
54
|
+
/** @type {boolean} */
|
|
55
|
+
this.allowRoot = true;
|
|
56
|
+
this.setParent(this.value, this);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {EvalContext} context
|
|
61
|
+
* @param {CSSOutput} output
|
|
62
|
+
*/
|
|
63
|
+
genCSS(context, output) {
|
|
64
|
+
output.add(/** @type {string} */ (this.name) + (context.compress ? ':' : ': '), this.fileInfo(), this.getIndex());
|
|
37
65
|
try {
|
|
38
|
-
this.value.genCSS(context, output);
|
|
66
|
+
/** @type {Node} */ (this.value).genCSS(context, output);
|
|
39
67
|
}
|
|
40
68
|
catch (e) {
|
|
41
|
-
|
|
42
|
-
|
|
69
|
+
const err = /** @type {{ index?: number, filename?: string }} */ (e);
|
|
70
|
+
err.index = this._index;
|
|
71
|
+
err.filename = this._fileInfo && this._fileInfo.filename;
|
|
43
72
|
throw e;
|
|
44
73
|
}
|
|
45
74
|
output.add(this.important + ((this.inline || (context.lastRule && context.compress)) ? '' : ';'), this._fileInfo, this._index);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {EvalContext} context */
|
|
78
|
+
eval(context) {
|
|
79
|
+
let mathBypass = false, prevMath, name = this.name, evaldValue, variable = this.variable;
|
|
49
80
|
if (typeof name !== 'string') {
|
|
50
81
|
// expand 'primitive' name directly to get
|
|
51
82
|
// things faster (~10% for benchmark.less):
|
|
52
|
-
name = (name.length === 1) && (name[0] instanceof
|
|
53
|
-
name[0].value : evalName(context, name);
|
|
83
|
+
name = (/** @type {Node[]} */ (name).length === 1) && (/** @type {Node[]} */ (name)[0] instanceof Keyword) ?
|
|
84
|
+
/** @type {string} */ (/** @type {Node[]} */ (name)[0].value) : evalName(context, /** @type {Node[]} */ (name));
|
|
54
85
|
variable = false; // never treat expanded interpolation as new variable name
|
|
55
86
|
}
|
|
87
|
+
|
|
56
88
|
// @todo remove when parens-division is default
|
|
57
89
|
if (name === 'font' && context.math === MATH.ALWAYS) {
|
|
58
90
|
mathBypass = true;
|
|
@@ -61,22 +93,30 @@ Declaration.prototype = Object.assign(new node_1.default(), {
|
|
|
61
93
|
}
|
|
62
94
|
try {
|
|
63
95
|
context.importantScope.push({});
|
|
64
|
-
evaldValue = this.value.eval(context);
|
|
96
|
+
evaldValue = /** @type {Node} */ (this.value).eval(context);
|
|
97
|
+
|
|
65
98
|
if (!this.variable && evaldValue.type === 'DetachedRuleset') {
|
|
66
99
|
throw { message: 'Rulesets cannot be evaluated on a property.',
|
|
67
100
|
index: this.getIndex(), filename: this.fileInfo().filename };
|
|
68
101
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!important && importantResult.important) {
|
|
102
|
+
let important = this.important;
|
|
103
|
+
const importantResult = context.importantScope.pop();
|
|
104
|
+
if (!important && importantResult && importantResult.important) {
|
|
72
105
|
important = importantResult.important;
|
|
73
106
|
}
|
|
74
|
-
|
|
107
|
+
|
|
108
|
+
return new Declaration(/** @type {string} */ (name),
|
|
109
|
+
evaldValue,
|
|
110
|
+
important,
|
|
111
|
+
this.merge,
|
|
112
|
+
this.getIndex(), this.fileInfo(), this.inline,
|
|
113
|
+
variable);
|
|
75
114
|
}
|
|
76
115
|
catch (e) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
const err = /** @type {{ index?: number, filename?: string }} */ (e);
|
|
117
|
+
if (typeof err.index !== 'number') {
|
|
118
|
+
err.index = this.getIndex();
|
|
119
|
+
err.filename = this.fileInfo().filename;
|
|
80
120
|
}
|
|
81
121
|
throw e;
|
|
82
122
|
}
|
|
@@ -85,10 +125,15 @@ Declaration.prototype = Object.assign(new node_1.default(), {
|
|
|
85
125
|
context.math = prevMath;
|
|
86
126
|
}
|
|
87
127
|
}
|
|
88
|
-
},
|
|
89
|
-
makeImportant: function () {
|
|
90
|
-
return new Declaration(this.name, this.value, '!important', this.merge, this.getIndex(), this.fileInfo(), this.inline);
|
|
91
128
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
129
|
+
|
|
130
|
+
makeImportant() {
|
|
131
|
+
return new Declaration(this.name,
|
|
132
|
+
/** @type {Node} */ (this.value),
|
|
133
|
+
'!important',
|
|
134
|
+
this.merge,
|
|
135
|
+
this.getIndex(), this.fileInfo(), this.inline);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default Declaration;
|