diff --git a/packages/less/src/less-browser/utils.js b/packages/less/src/less-browser/utils.js index 42a1b442e..039f1d595 100644 --- a/packages/less/src/less-browser/utils.js +++ b/packages/less/src/less-browser/utils.js @@ -9,7 +9,7 @@ export function extractId(href) { } export function addDataAttr(options, tag) { - if(!tag) return; // in case of tag is null or undefined + if (!tag) {return;} // in case of tag is null or undefined for (const opt in tag.dataset) { if (tag.dataset.hasOwnProperty(opt)) { if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') { diff --git a/packages/less/src/less/environment/environment.js b/packages/less/src/less/environment/environment.js index 39de0d315..f7d65c6a1 100644 --- a/packages/less/src/less/environment/environment.js +++ b/packages/less/src/less/environment/environment.js @@ -30,7 +30,7 @@ class Environment { if (!filename) { logger.warn('getFileManager called with no filename.. Please report this issue. continuing.'); } - if (currentDirectory == null) { + if (currentDirectory === undefined) { logger.warn('getFileManager called with null directory.. Please report this issue. continuing.'); } diff --git a/packages/less/src/less/functions/default.js b/packages/less/src/less/functions/default.js index fc7fd63aa..61c14b9ac 100644 --- a/packages/less/src/less/functions/default.js +++ b/packages/less/src/less/functions/default.js @@ -1,4 +1,5 @@ import Keyword from '../tree/keyword'; +import * as utils from '../utils'; const defaultFunc = { eval: function () { @@ -7,7 +8,7 @@ const defaultFunc = { if (e) { throw e; } - if (v != null) { + if (!utils.isNullOrUndefined(v)) { return v ? Keyword.True : Keyword.False; } }, diff --git a/packages/less/src/less/functions/math-helper.js b/packages/less/src/less/functions/math-helper.js index ed6deaa75..b557875c5 100644 --- a/packages/less/src/less/functions/math-helper.js +++ b/packages/less/src/less/functions/math-helper.js @@ -4,7 +4,7 @@ const MathHelper = (fn, unit, n) => { if (!(n instanceof Dimension)) { throw { type: 'Argument', message: 'argument must be a number' }; } - if (unit == null) { + if (unit === null) { unit = n.unit; } else { n = n.unify(); diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js index c7a65cb07..2b2799c62 100644 --- a/packages/less/src/less/parser/parser.js +++ b/packages/less/src/less/parser/parser.js @@ -581,7 +581,7 @@ const Parser = function Parser(context, imports, fileInfo) { expectChar(')'); - return new(tree.URL)((value.value != null || + return new(tree.URL)((value.value !== undefined || value instanceof tree.Variable || value instanceof tree.Property) ? value : new(tree.Anonymous)(value, index), index, fileInfo); diff --git a/packages/less/src/less/tree/node.js b/packages/less/src/less/tree/node.js index b40e30da9..4aadc261c 100644 --- a/packages/less/src/less/tree/node.js +++ b/packages/less/src/less/tree/node.js @@ -1,3 +1,5 @@ +import * as utils from '../utils'; + /** * The reason why Node is a class and other nodes simply do not extend * from Node (since we're transpiling) is due to this issue: @@ -125,21 +127,21 @@ class Node { // Returns true if this node represents root of ast imported by reference blocksVisibility() { - if (this.visibilityBlocks == null) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } return this.visibilityBlocks !== 0; } addVisibilityBlock() { - if (this.visibilityBlocks == null) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks + 1; } removeVisibilityBlock() { - if (this.visibilityBlocks == null) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks - 1; diff --git a/packages/less/src/less/tree/quoted.js b/packages/less/src/less/tree/quoted.js index d73c40ca6..7c96c0ecd 100644 --- a/packages/less/src/less/tree/quoted.js +++ b/packages/less/src/less/tree/quoted.js @@ -1,10 +1,11 @@ import Node from './node'; import Variable from './variable'; import Property from './property'; +import * as utils from '../utils'; const Quoted = function(str, content, escaped, index, currentFileInfo) { - this.escaped = (escaped == null) ? true : escaped; + this.escaped = (escaped === undefined) ? true : escaped; this.value = content || ''; this.quote = str.charAt(0); this._index = index; diff --git a/packages/less/src/less/tree/ruleset.js b/packages/less/src/less/tree/ruleset.js index 22f68b75c..dfd044932 100644 --- a/packages/less/src/less/tree/ruleset.js +++ b/packages/less/src/less/tree/ruleset.js @@ -734,7 +734,7 @@ Ruleset.prototype = Object.assign(new Node(), { // non parent reference elements just get added if (el.value !== '&') { const nestedSelector = findNestedSelector(el); - if (nestedSelector != null) { + if (nestedSelector !== null) { // merge the current list of non parent selector elements // on to the current list of selectors to add mergeElementsOnToSelectors(currentElements, newSelectors); diff --git a/packages/less/src/less/tree/selector.js b/packages/less/src/less/tree/selector.js index a198a7740..d098cc2bc 100644 --- a/packages/less/src/less/tree/selector.js +++ b/packages/less/src/less/tree/selector.js @@ -1,6 +1,7 @@ import Node from './node'; import Element from './element'; import LessError from '../less-error'; +import * as utils from '../utils'; const Selector = function(elements, extendList, condition, index, currentFileInfo, visibilityInfo) { this.extendList = extendList; @@ -33,7 +34,7 @@ Selector.prototype = Object.assign(new Node(), { elements = this.getElements(elements); const newSelector = new Selector(elements, extendList || this.extendList, null, this.getIndex(), this.fileInfo(), this.visibilityInfo()); - newSelector.evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition; + newSelector.evaldCondition = (!utils.isNullOrUndefined(evaldCondition)) ? evaldCondition : this.evaldCondition; newSelector.mediaEmpty = this.mediaEmpty; return newSelector; }, diff --git a/packages/less/src/less/utils.js b/packages/less/src/less/utils.js index c0921b90d..b723ab2ac 100644 --- a/packages/less/src/less/utils.js +++ b/packages/less/src/less/utils.js @@ -119,4 +119,8 @@ export function flattenArray(arr, result = []) { } } return result; +} + +export function isNullOrUndefined(val) { + return val === null || val === undefined } \ No newline at end of file