Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-prototype-builtins issue in Ruleset variables() #4272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading