Skip to content

Commit

Permalink
fix: Fix https failures on macOS (less#3716)
Browse files Browse the repository at this point in the history
The issue was traced upstream to needle, and resolved in:
 - tomas/needle#392
 - tomas/needle#394
 - tomas/needle#396
 - tomas/needle#398

Closes less#3693
  • Loading branch information
joeyparrish authored and lumburr committed Apr 28, 2022
1 parent 3f05b5c commit 97f7082
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
20 changes: 15 additions & 5 deletions packages/less/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"image-size": "~0.5.0",
"make-dir": "^2.1.0",
"mime": "^1.4.1",
"needle": "^2.5.2",
"needle": "^3.1.0",
"source-map": "~0.6.0"
},
"devDependencies": {
Expand Down
31 changes: 24 additions & 7 deletions packages/less/src/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ Ruleset.prototype = Object.assign(new Node(), {
}
this.parse.parseNode(
toParseSelectors.join(','),
["selectors"],
selectors[0].getIndex(),
selectors[0].fileInfo(),
["selectors"],
selectors[0].getIndex(),
selectors[0].fileInfo(),
function(err, result) {
if (result) {
selectors = utils.flattenArray(result);
Expand Down Expand Up @@ -230,17 +230,34 @@ Ruleset.prototype = Object.assign(new Node(), {
let i;
let importRules;
if (!rules) { return; }

const importDecl = {};
for (i = 0; i < rules.length; i++) {
if (rules[i].type === 'Import') {
importRules = rules[i].eval(context);
if (importRules && (importRules.length || importRules.length === 0)) {
// fix: #3563
importRules.forEach((node, index) => {
if (node instanceof Declaration) {
if (!importDecl[node.name]) {
importDecl[node.name] = [i + index]
} else {
importDecl[node.name].push(i + index)
}
}
})
rules.splice.apply(rules, [i, 1].concat(importRules));
i += importRules.length - 1;
} else {
rules.splice(i, 1, importRules);
}
this.resetCache();
} else if (rules[i] instanceof Declaration && importDecl[rules[i].name]) {
const name = rules[i].name
importDecl[name].forEach(e => {
if (rules[e].name === name) {
rules[e].value = rules[i].value
}
})
}
}
},
Expand Down Expand Up @@ -356,9 +373,9 @@ Ruleset.prototype = Object.assign(new Node(), {
if (typeof decl.value.value === 'string') {
this.parse.parseNode(
decl.value.value,
['value', 'important'],
decl.value.getIndex(),
decl.fileInfo(),
['value', 'important'],
decl.value.getIndex(),
decl.fileInfo(),
function(err, result) {
if (err) {
decl.parsed = true;
Expand Down
12 changes: 12 additions & 0 deletions packages/test-data/css/_main/import.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@
width: 100%;
}
}
.some-class {
color: var(--primary-color);
backgroundColor: var(--bg-color);
}
:root {
--primary-color: #fff;
--bg-color: #000;
}
html[data-theme="dark"] {
--primary-color: #000;
--bg-color: #fff;
}
14 changes: 14 additions & 0 deletions packages/test-data/less/_main/import.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@

@charset "UTF-8"; // climb on top #2126

// #3563
@import "import/import-style.less";
@base-color: var(--primary-color);
@dark-color: var(--bg-color);

:root {
--primary-color: #fff;
--bg-color: #000;
}

html[data-theme="dark"] {
--primary-color: #000;
--bg-color: #fff;
}
7 changes: 7 additions & 0 deletions packages/test-data/less/_main/import/import-style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@base-color: green;
@dark-color: darken(@base-color, 50%);

.some-class {
color: @base-color;
backgroundColor: @dark-color;
}

0 comments on commit 97f7082

Please sign in to comment.