Skip to content

Commit

Permalink
Fix no-prototype-builtins issues in Ruleset and ToCSSVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 15, 2024
1 parent 53f84f0 commit 8e488b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/less/src/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ Ruleset.prototype = Object.assign(new Node(), {
if (r.type === 'Import' && r.root && r.root.variables) {
const vars = r.root.variables();
for (const name in vars) {
// eslint-disable-next-line no-prototype-builtins
if (vars.hasOwnProperty(name)) {
if (Object.prototype.hasOwnProperty.call(vars, name)) {
hash[name] = r.root.variable(name);
}
}
Expand Down
17 changes: 7 additions & 10 deletions packages/less/src/less/visitors/to-css-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,16 @@ ToCSSVisitor.prototype = {
// remove duplicates
const ruleCache = {};

let ruleList;
let rule;
let i;

for (i = rules.length - 1; i >= 0 ; i--) {
rule = rules[i];
for (let i = rules.length - 1; i >= 0 ; i--) {
let rule = rules[i];
if (rule instanceof tree.Declaration) {
if (!ruleCache[rule.name]) {
if (!Object.prototype.hasOwnProperty.call(ruleCache, rule.name)) {
ruleCache[rule.name] = rule;
} else {
ruleList = ruleCache[rule.name];
if (ruleList instanceof tree.Declaration) {
ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._context)];
let ruleList = ruleCache[rule.name];
if (!Array.isArray(ruleList)) {
const prevRuleCSS = ruleList.toCSS(this._context);
ruleList = ruleCache[rule.name] = [prevRuleCSS];
}
const ruleCSS = rule.toCSS(this._context);
if (ruleList.indexOf(ruleCSS) !== -1) {
Expand Down
1 change: 1 addition & 0 deletions packages/test-data/css/_main/rulesets.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#first > .one {
font-size: 2em;
hasOwnProperty: blue;
}
#first > .one > #second .two > #deux {
width: 50%;
Expand Down
1 change: 1 addition & 0 deletions packages/test-data/less/_main/rulesets.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
}
}
font-size: 2em;
hasOwnProperty: blue;
}

0 comments on commit 8e488b2

Please sign in to comment.