• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / less-openui5 / 13906243876

17 Mar 2025 05:43PM UTC coverage: 94.719%. Remained the same
13906243876

Pull #391

github

web-flow
Merge dd2a4f8ee into b8693f39a
Pull Request #391: Bump actions/setup-node from 4.2.0 to 4.3.0

501 of 560 branches covered (89.46%)

Branch coverage included in aggregate %.

916 of 936 relevant lines covered (97.86%)

206.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.22
/lib/plugin/variable-collector.js
1
"use strict";
2
const posixPath = require("path").posix;
1✔
3
const less = require("../thirdparty/less");
1✔
4
const backslashRegExp = /\\/g;
1✔
5

6
function toPosix(p) {
7
        return p.replace(backslashRegExp, "/");
639✔
8
}
9

10
const VariableCollector = module.exports = function(env) {
1✔
11
        /* eslint-disable new-cap */
12
        this.oVisitor = new less.tree.visitor(this);
198✔
13
        /* eslint-enable new-cap */
14
        this.env = env;
198✔
15
        this.mVariables = {};
198✔
16
        this.mGlobalVariables = {};
198✔
17
        this.mVarFile = {};
198✔
18
};
19

20
VariableCollector.prototype = {
1✔
21
        isPreVisitor: true,
22
        run: function(root) {
23
                this.mGlobalVariables = root.variables();
190✔
24
                return this.oVisitor.visit(root);
190✔
25
        },
26

27
        visitRule: function(node) {
28
                if (!node.variable) {
2,173✔
29
                        return;
1,891✔
30
                }
31
                if (!this.mGlobalVariables[node.name]) {
282✔
32
                        // Ignoring local variable
33
                        return;
16✔
34
                }
35
                try {
266✔
36
                        const value = node.value.toCSS(this.env);
266✔
37
                        this.mVariables[node.name.substr(1)] = {
265✔
38
                                value: value,
39
                                filename: node.currentFileInfo.filename,
40
                                rootFilename: node.currentFileInfo.rootFilename
41
                        };
42
                // eslint-disable-next-line no-unused-vars
43
                } catch (err) {
44
                        // Errors might occur within mixins.
45
                        // But as we only collect global variables, this doesn't matter...
46
                }
47
        },
48

49
        getVariables: function(aImports) {
50
                const mVariables = {};
188✔
51

52
                const aPosixImports = aImports.map(toPosix);
188✔
53

54
                const includeCache = {};
188✔
55

56
                function shouldIncludeVariable({rootFilename, filename}) {
57
                        // Simple case where variable is defined in root file
58
                        if (rootFilename === filename) {
167✔
59
                                return true;
55✔
60
                        }
61

62
                        const cacheKey = rootFilename + "|" + filename;
112✔
63
                        if (includeCache[cacheKey] !== undefined) {
112✔
64
                                return includeCache[cacheKey];
8✔
65
                        }
66

67
                        const dirname = posixPath.dirname(filename);
104✔
68
                        const baseFileName = posixPath.basename(rootFilename); // usually library.source.less
104✔
69

70
                        function check(currentDirname) {
71
                                const libraryBaseFile = posixPath.join(currentDirname, baseFileName);
166✔
72
                                if (libraryBaseFile === rootFilename || aPosixImports.includes(libraryBaseFile)) {
166✔
73
                                        return true;
93✔
74
                                } else {
75
                                        // Recursively check parent directories whether they contain an imported "base file"
76
                                        // This is only relevant when a theme contains sub-directories
77
                                        const parentDirname = posixPath.dirname(currentDirname);
73✔
78
                                        if (parentDirname === currentDirname) {
73✔
79
                                                return false; // We are at the root
11✔
80
                                        } else {
81
                                                return check(parentDirname);
62✔
82
                                        }
83
                                }
84
                        }
85

86
                        return includeCache[cacheKey] = check(dirname);
104✔
87
                }
88

89
                for (const name in this.mVariables) {
188✔
90
                        if (Object.prototype.hasOwnProperty.call(this.mVariables, name)) {
167!
91
                                const oVar = this.mVariables[name];
167✔
92
                                // Ensure posix paths
93
                                const rootFilename = toPosix(oVar.rootFilename);
167✔
94
                                const filename = toPosix(oVar.filename);
167✔
95

96
                                // Only add variable if the corresponding library "base file" has been imported
97
                                if (shouldIncludeVariable({rootFilename, filename})) {
167✔
98
                                        mVariables[name] = oVar.value;
155✔
99
                                }
100
                        }
101
                }
102

103
                return mVariables;
188✔
104
        },
105

106
        getAllVariables: function(aImports) {
107
                const mVariables = {};
190✔
108
                for (const name in this.mVariables) {
190✔
109
                        if (Object.prototype.hasOwnProperty.call(this.mVariables, name)) {
176!
110
                                const oVar = this.mVariables[name];
176✔
111
                                mVariables[name] = oVar.value;
176✔
112
                        }
113
                }
114
                return mVariables;
190✔
115
        }
116

117
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc