less 4.0.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,7 +57,8 @@ Dimension.prototype = Object.assign(new node_1.default(), {
57
57
  // so `1px + 2` will yield `3px`.
58
58
  operate: function (context, op, other) {
59
59
  /* jshint noempty:false */
60
- var value = this._operate(context, op, this.value, other.value), unit = this.unit.clone();
60
+ var value = this._operate(context, op, this.value, other.value);
61
+ var unit = this.unit.clone();
61
62
  if (op === '+' || op === '-') {
62
63
  if (unit.numerator.length === 0 && unit.denominator.length === 0) {
63
64
  unit = other.unit.clone();
@@ -1 +1 @@
1
- {"version":3,"file":"dimension.js","sourceRoot":"","sources":["../../../src/less/tree/dimension.js"],"names":[],"mappings":";;;AAAA,wDAA0B;AAC1B,sFAAuD;AACvD,wDAA0B;AAC1B,0DAA4B;AAE5B,EAAE;AACF,uBAAuB;AACvB,EAAE;AACF,IAAM,SAAS,GAAG,UAAS,KAAK,EAAE,IAAI;IAClC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KACjD;IACD,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,YAAY,cAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,cAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,SAAS,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,cAAI,EAAE,EAAE;IAC5C,IAAI,EAAE,WAAW;IAEjB,MAAM,YAAC,OA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AAI,WAAW,EAAE;oBACb,KAAK,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;iBAC3D;qBAAM;oBACH,KAAK,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;iBAC3D;gBAED,OAAO,UAAU,CAAC;aACrB;YAED,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC;QAEF,KAAK,SAAS,IAAI,WAAW,EAAE;YAC3B,IAAI,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;gBACvC,UAAU,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;gBACpC,KAAK,GAAG,0BAAe,CAAC,SAAS,CAAC,CAAC;gBAEnC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;aACvB;SACJ;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,OAAO,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,SAAS,CAAC","sourcesContent":["import Node from './node';\nimport unitConversions from '../data/unit-conversions';\nimport Unit from './unit';\nimport Color from './color';\n\n//\n// A number with a unit\n//\nconst Dimension = function(value, unit) {\n this.value = parseFloat(value);\n if (isNaN(this.value)) {\n throw new Error('Dimension is not a number.');\n }\n this.unit = (unit && unit instanceof Unit) ? unit :\n new Unit(unit ? [unit] : undefined);\n this.setParent(this.unit, this);\n};\n\nDimension.prototype = Object.assign(new Node(), {\n type: 'Dimension',\n\n accept(visitor) {\n this.unit = visitor.visit(this.unit);\n },\n\n eval(context) {\n return this;\n },\n\n toColor() {\n return new Color([this.value, this.value, this.value]);\n },\n\n genCSS(context, output) {\n if ((context && context.strictUnits) && !this.unit.isSingular()) {\n throw new Error(`Multiple units in dimension. Correct the units or use the unit function. Bad unit: ${this.unit.toString()}`);\n }\n\n const value = this.fround(context, this.value);\n let strValue = String(value);\n\n if (value !== 0 && value < 0.000001 && value > -0.000001) {\n // would be output 1e-6 etc.\n strValue = value.toFixed(20).replace(/0+$/, '');\n }\n\n if (context && context.compress) {\n // Zero values doesn't need a unit\n if (value === 0 && this.unit.isLength()) {\n output.add(strValue);\n return;\n }\n\n // Float values doesn't need a leading zero\n if (value > 0 && value < 1) {\n strValue = (strValue).substr(1);\n }\n }\n\n output.add(strValue);\n this.unit.genCSS(context, output);\n },\n\n // In an operation between two Dimensions,\n // we default to the first Dimension's unit,\n // so `1px + 2` will yield `3px`.\n operate(context, op, other) {\n /* jshint noempty:false */\n let value = this._operate(context, op, this.value, other.value), unit = this.unit.clone();\n\n if (op === '+' || op === '-') {\n if (unit.numerator.length === 0 && unit.denominator.length === 0) {\n unit = other.unit.clone();\n if (this.unit.backupUnit) {\n unit.backupUnit = this.unit.backupUnit;\n }\n } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {\n // do nothing\n } else {\n other = other.convertTo(this.unit.usedUnits());\n\n if (context.strictUnits && other.unit.toString() !== unit.toString()) {\n throw new Error(`Incompatible units. Change the units or use the unit function. `\n + `Bad units: '${unit.toString()}' and '${other.unit.toString()}'.`);\n }\n\n value = this._operate(context, op, this.value, other.value);\n }\n } else if (op === '*') {\n unit.numerator = unit.numerator.concat(other.unit.numerator).sort();\n unit.denominator = unit.denominator.concat(other.unit.denominator).sort();\n unit.cancel();\n } else if (op === '/') {\n unit.numerator = unit.numerator.concat(other.unit.denominator).sort();\n unit.denominator = unit.denominator.concat(other.unit.numerator).sort();\n unit.cancel();\n }\n return new Dimension(value, unit);\n },\n\n compare(other) {\n let a, b;\n\n if (!(other instanceof Dimension)) {\n return undefined;\n }\n\n if (this.unit.isEmpty() || other.unit.isEmpty()) {\n a = this;\n b = other;\n } else {\n a = this.unify();\n b = other.unify();\n if (a.unit.compare(b.unit) !== 0) {\n return undefined;\n }\n }\n\n return Node.numericCompare(a.value, b.value);\n },\n\n unify() {\n return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });\n },\n\n convertTo(conversions) {\n let value = this.value;\n const unit = this.unit.clone();\n let i;\n let groupName;\n let group;\n let targetUnit;\n let derivedConversions = {};\n let applyUnit;\n\n if (typeof conversions === 'string') {\n for (i in unitConversions) {\n if (unitConversions[i].hasOwnProperty(conversions)) {\n derivedConversions = {};\n derivedConversions[i] = conversions;\n }\n }\n conversions = derivedConversions;\n }\n applyUnit = function (atomicUnit, denominator) {\n /* jshint loopfunc:true */\n if (group.hasOwnProperty(atomicUnit)) {\n if (denominator) {\n value = value / (group[atomicUnit] / group[targetUnit]);\n } else {\n value = value * (group[atomicUnit] / group[targetUnit]);\n }\n\n return targetUnit;\n }\n\n return atomicUnit;\n };\n\n for (groupName in conversions) {\n if (conversions.hasOwnProperty(groupName)) {\n targetUnit = conversions[groupName];\n group = unitConversions[groupName];\n\n unit.map(applyUnit);\n }\n }\n\n unit.cancel();\n\n return new Dimension(value, unit);\n }\n});\n\nexport default Dimension;\n"]}
1
+ {"version":3,"file":"dimension.js","sourceRoot":"","sources":["../../../src/less/tree/dimension.js"],"names":[],"mappings":";;;AAAA,wDAA0B;AAC1B,sFAAuD;AACvD,wDAA0B;AAC1B,0DAA4B;AAE5B,EAAE;AACF,uBAAuB;AACvB,EAAE;AACF,IAAM,SAAS,GAAG,UAAS,KAAK,EAAE,IAAI;IAClC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KACjD;IACD,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,YAAY,cAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,cAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,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EAAE,CAAC;oBACxB,kBAAkB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;iBACvC;aACJ;YACD,WAAW,GAAG,kBAAkB,CAAC;SACpC;QACD,SAAS,GAAG,UAAU,UAAU,EAAE,WAAW;YACzC,0BAA0B;YAC1B,IAAI,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;gBAClC,IAAI,WAAW,EAAE;oBACb,KAAK,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;iBAC3D;qBAAM;oBACH,KAAK,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;iBAC3D;gBAED,OAAO,UAAU,CAAC;aACrB;YAED,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC;QAEF,KAAK,SAAS,IAAI,WAAW,EAAE;YAC3B,IAAI,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;gBACvC,UAAU,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;gBACpC,KAAK,GAAG,0BAAe,CAAC,SAAS,CAAC,CAAC;gBAEnC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;aACvB;SACJ;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,OAAO,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,SAAS,CAAC","sourcesContent":["import Node from './node';\nimport unitConversions from '../data/unit-conversions';\nimport Unit from './unit';\nimport Color from './color';\n\n//\n// A number with a unit\n//\nconst Dimension = function(value, unit) {\n this.value = parseFloat(value);\n if (isNaN(this.value)) {\n throw new Error('Dimension is not a number.');\n }\n this.unit = (unit && unit instanceof Unit) ? unit :\n new Unit(unit ? [unit] : undefined);\n this.setParent(this.unit, this);\n};\n\nDimension.prototype = Object.assign(new Node(), {\n type: 'Dimension',\n\n accept(visitor) {\n this.unit = visitor.visit(this.unit);\n },\n\n eval(context) {\n return this;\n },\n\n toColor() {\n return new Color([this.value, this.value, this.value]);\n },\n\n genCSS(context, output) {\n if ((context && context.strictUnits) && !this.unit.isSingular()) {\n throw new Error(`Multiple units in dimension. Correct the units or use the unit function. Bad unit: ${this.unit.toString()}`);\n }\n\n const value = this.fround(context, this.value);\n let strValue = String(value);\n\n if (value !== 0 && value < 0.000001 && value > -0.000001) {\n // would be output 1e-6 etc.\n strValue = value.toFixed(20).replace(/0+$/, '');\n }\n\n if (context && context.compress) {\n // Zero values doesn't need a unit\n if (value === 0 && this.unit.isLength()) {\n output.add(strValue);\n return;\n }\n\n // Float values doesn't need a leading zero\n if (value > 0 && value < 1) {\n strValue = (strValue).substr(1);\n }\n }\n\n output.add(strValue);\n this.unit.genCSS(context, output);\n },\n\n // In an operation between two Dimensions,\n // we default to the first Dimension's unit,\n // so `1px + 2` will yield `3px`.\n operate(context, op, other) {\n /* jshint noempty:false */\n let value = this._operate(context, op, this.value, other.value);\n let unit = this.unit.clone();\n\n if (op === '+' || op === '-') {\n if (unit.numerator.length === 0 && unit.denominator.length === 0) {\n unit = other.unit.clone();\n if (this.unit.backupUnit) {\n unit.backupUnit = this.unit.backupUnit;\n }\n } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {\n // do nothing\n } else {\n other = other.convertTo(this.unit.usedUnits());\n\n if (context.strictUnits && other.unit.toString() !== unit.toString()) {\n throw new Error(`Incompatible units. Change the units or use the unit function. `\n + `Bad units: '${unit.toString()}' and '${other.unit.toString()}'.`);\n }\n\n value = this._operate(context, op, this.value, other.value);\n }\n } else if (op === '*') {\n unit.numerator = unit.numerator.concat(other.unit.numerator).sort();\n unit.denominator = unit.denominator.concat(other.unit.denominator).sort();\n unit.cancel();\n } else if (op === '/') {\n unit.numerator = unit.numerator.concat(other.unit.denominator).sort();\n unit.denominator = unit.denominator.concat(other.unit.numerator).sort();\n unit.cancel();\n }\n return new Dimension(value, unit);\n },\n\n compare(other) {\n let a, b;\n\n if (!(other instanceof Dimension)) {\n return undefined;\n }\n\n if (this.unit.isEmpty() || other.unit.isEmpty()) {\n a = this;\n b = other;\n } else {\n a = this.unify();\n b = other.unify();\n if (a.unit.compare(b.unit) !== 0) {\n return undefined;\n }\n }\n\n return Node.numericCompare(a.value, b.value);\n },\n\n unify() {\n return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });\n },\n\n convertTo(conversions) {\n let value = this.value;\n const unit = this.unit.clone();\n let i;\n let groupName;\n let group;\n let targetUnit;\n let derivedConversions = {};\n let applyUnit;\n\n if (typeof conversions === 'string') {\n for (i in unitConversions) {\n if (unitConversions[i].hasOwnProperty(conversions)) {\n derivedConversions = {};\n derivedConversions[i] = conversions;\n }\n }\n conversions = derivedConversions;\n }\n applyUnit = function (atomicUnit, denominator) {\n /* jshint loopfunc:true */\n if (group.hasOwnProperty(atomicUnit)) {\n if (denominator) {\n value = value / (group[atomicUnit] / group[targetUnit]);\n } else {\n value = value * (group[atomicUnit] / group[targetUnit]);\n }\n\n return targetUnit;\n }\n\n return atomicUnit;\n };\n\n for (groupName in conversions) {\n if (conversions.hasOwnProperty(groupName)) {\n targetUnit = conversions[groupName];\n group = unitConversions[groupName];\n\n unit.map(applyUnit);\n }\n }\n\n unit.cancel();\n\n return new Dimension(value, unit);\n }\n});\n\nexport default Dimension;\n"]}
@@ -26,8 +26,9 @@ Operation.prototype = Object.assign(new node_1.default(), {
26
26
  if (b instanceof dimension_1.default && a instanceof color_1.default) {
27
27
  b = b.toColor();
28
28
  }
29
- if (!a.operate) {
30
- if (a instanceof Operation && a.op === '/' && context.math === MATH.PARENS_DIVISION) {
29
+ if (!a.operate || !b.operate) {
30
+ if ((a instanceof Operation || b instanceof Operation)
31
+ && a.op === '/' && context.math === MATH.PARENS_DIVISION) {
31
32
  return new Operation(this.op, [a, b], this.isSpaced);
32
33
  }
33
34
  throw { type: 'Operation',
@@ -1 +1 @@
1
- {"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G,CAAC,CAAC,OAAO,EAAE,CAAC;aACnB;YACD,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE;gBACZ,IAAI,CAAC,YAAY,SAAS,IAAI,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,eAAe,EAAE;oBACjF,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;iBACxD;gBACD,MAAM,EAAE,IAAI,EAAE,WAAW;oBACrB,OAAO,EAAE,8BAA8B,EAAE,CAAC;aACjD;YAED,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;SACpC;aAAM;YACH,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACxD;IACL,CAAC;IAED,MAAM,YAAC,OAAO,EAAE,MAAM;QAClB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;QACD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;QACD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,SAAS,CAAC","sourcesContent":["import Node from './node';\nimport Color from './color';\nimport Dimension from './dimension';\nimport * as Constants from '../constants';\nconst MATH = Constants.Math;\n\n\nconst Operation = function(op, operands, isSpaced) {\n this.op = op.trim();\n this.operands = operands;\n this.isSpaced = isSpaced;\n};\n\nOperation.prototype = Object.assign(new Node(), {\n type: 'Operation',\n\n accept(visitor) {\n this.operands = visitor.visitArray(this.operands);\n },\n\n eval(context) {\n let a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;\n\n if (context.isMathOn(this.op)) {\n op = this.op === './' ? '/' : this.op;\n if (a instanceof Dimension && b instanceof Color) {\n a = a.toColor();\n }\n if (b instanceof Dimension && a instanceof Color) {\n b = b.toColor();\n }\n if (!a.operate) {\n if (a instanceof Operation && a.op === '/' && context.math === MATH.PARENS_DIVISION) {\n return new Operation(this.op, [a, b], this.isSpaced);\n }\n throw { type: 'Operation',\n message: 'Operation on an invalid type' };\n }\n\n return a.operate(context, op, b);\n } else {\n return new Operation(this.op, [a, b], this.isSpaced);\n }\n },\n\n genCSS(context, output) {\n this.operands[0].genCSS(context, output);\n if (this.isSpaced) {\n output.add(' ');\n }\n output.add(this.op);\n if (this.isSpaced) {\n output.add(' ');\n }\n this.operands[1].genCSS(context, output);\n }\n});\n\nexport default Operation;\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../src/less/tree/operation.js"],"names":[],"mappings":";;;AAAA,wDAA0B;AAC1B,0DAA4B;AAC5B,kEAAoC;AACpC,8DAA0C;AAC1C,IAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;AAG5B,IAAM,SAAS,GAAG,UAAS,EAAE,EAAE,QAAQ,EAAE,QAAQ;IAC7C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,CAAC,CAAC;AAEF,SAAS,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,cAAI,EAAE,EAAE;IAC5C,IAAI,EAAE,WAAW;I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C,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;SACpC;aAAM;YACH,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACxD;IACL,CAAC;IAED,MAAM,YAAC,OAAO,EAAE,MAAM;QAClB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;QACD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACnB;QACD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,SAAS,CAAC","sourcesContent":["import Node from './node';\nimport Color from './color';\nimport Dimension from './dimension';\nimport * as Constants from '../constants';\nconst MATH = Constants.Math;\n\n\nconst Operation = function(op, operands, isSpaced) {\n this.op = op.trim();\n this.operands = operands;\n this.isSpaced = isSpaced;\n};\n\nOperation.prototype = Object.assign(new Node(), {\n type: 'Operation',\n\n accept(visitor) {\n this.operands = visitor.visitArray(this.operands);\n },\n\n eval(context) {\n let a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;\n\n if (context.isMathOn(this.op)) {\n op = this.op === './' ? '/' : this.op;\n if (a instanceof Dimension && b instanceof Color) {\n a = a.toColor();\n }\n if (b instanceof Dimension && a instanceof Color) {\n b = b.toColor();\n }\n if (!a.operate || !b.operate) {\n if (\n (a instanceof Operation || b instanceof Operation)\n && a.op === '/' && context.math === MATH.PARENS_DIVISION\n ) {\n return new Operation(this.op, [a, b], this.isSpaced);\n }\n throw { type: 'Operation',\n message: 'Operation on an invalid type' };\n }\n\n return a.operate(context, op, b);\n } else {\n return new Operation(this.op, [a, b], this.isSpaced);\n }\n },\n\n genCSS(context, output) {\n this.operands[0].genCSS(context, output);\n if (this.isSpaced) {\n output.add(' ');\n }\n output.add(this.op);\n if (this.isSpaced) {\n output.add(' ');\n }\n this.operands[1].genCSS(context, output);\n }\n});\n\nexport default Operation;\n"]}
@@ -15,7 +15,7 @@ UrlFileManager.prototype = Object.assign(new abstract_file_manager_js_1.default(
15
15
  return new Promise(function (fulfill, reject) {
16
16
  if (request === undefined) {
17
17
  try {
18
- request = require('native-request');
18
+ request = require('needle');
19
19
  }
20
20
  catch (e) {
21
21
  request = null;
@@ -28,19 +28,23 @@ UrlFileManager.prototype = Object.assign(new abstract_file_manager_js_1.default(
28
28
  var urlStr = isUrlRe.test(filename) ? filename : url_1.default.resolve(currentDirectory, filename);
29
29
  /** native-request currently has a bug */
30
30
  var hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr;
31
- request.get(hackUrlStr, function (error, body, status) {
32
- if (status === 404) {
33
- reject({ type: 'File', message: "resource '" + urlStr + "' was not found\n" });
31
+ request.get(hackUrlStr, { follow_max: 5 }, function (err, resp, body) {
32
+ if (err || resp && resp.statusCode >= 400) {
33
+ var message = resp && resp.statusCode === 404
34
+ ? "resource '" + urlStr + "' was not found\n"
35
+ : "resource '" + urlStr + "' gave this Error:\n " + (err || resp.statusMessage || resp.statusCode) + "\n";
36
+ reject({ type: 'File', message: message });
34
37
  return;
35
38
  }
36
- if (error) {
37
- reject({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n " + error + "\n" });
39
+ if (resp.statusCode >= 300) {
40
+ reject({ type: 'File', message: "resource '" + urlStr + "' caused too many redirects" });
38
41
  return;
39
42
  }
43
+ body = body.toString('utf8');
40
44
  if (!body) {
41
- logger_1.default.warn("Warning: Empty body (HTTP " + status + ") returned by \"" + urlStr + "\"");
45
+ logger_1.default.warn("Warning: Empty body (HTTP " + resp.statusCode + ") returned by \"" + urlStr + "\"");
42
46
  }
43
- fulfill({ contents: body, filename: urlStr });
47
+ fulfill({ contents: body || '', filename: urlStr });
44
48
  });
45
49
  });
46
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"url-file-manager.js","sourceRoot":"","sources":["../../src/less-node/url-file-manager.js"],"names":[],"mappings":";;;AAAA,IAAM,OAAO,GAAG,oBAAoB,CAAC;AACrC,oDAAsB;AACtB,IAAI,OAAO,CAAC;AACZ,kHAA+E;AAC/E,kEAAoC;AAEpC,IAAM,cAAc,GAAG,cAAY,CAAC,CAAA;AACpC,cAAc,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,kCAAmB,EAAE,EAAE;IAChE,QAAQ,YAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW;QACrD,OAAO,OAAO,CAAC,IAAI,CAAE,QAAQ,CAAE,IAAI,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtE,CAAC;IAED,QAAQ,YAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW;QACrD,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAC/B,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,IAAI;oBAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;iBAAE;gBAC5C,OAAO,CAAC,EAAE;oBAAE,OAAO,GAAG,IAAI,CAAC;iBAAE;aAChC;YACD,IAAI,CAAC,OAAO,EAAE;gBACV,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,0EAA0E,EAAE,CAAC,CAAC;gBAC9G,OAAO;aACV;YAED,IAAI,MAAM,GAAG,OAAO,CAAC,IAAI,CAAE,QAAQ,CAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;YAE3F,yCAAyC;YACzC,IAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;YAErE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,UAAC,KAAK,EAAE,IAAI,EAAE,MAAM;gBACxC,IAAI,MAAM,KAAK,GAAG,EAAE;oBAChB,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAa,MAAM,sBAAmB,EAAE,CAAC,CAAC;oBAC1E,OAAO;iBACV;gBACD,IAAI,KAAK,EAAE;oBACP,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAa,MAAM,8BAAyB,KAAK,OAAI,EAAE,CAAC,CAAC;oBACzF,OAAO;iBACV;gBACD,IAAI,CAAC,IAAI,EAAE;oBACP,gBAAM,CAAC,IAAI,CAAC,+BAA6B,MAAM,wBAAkB,MAAM,OAAG,CAAC,CAAC;iBAC/E;gBACD,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,cAAc,CAAC","sourcesContent":["const isUrlRe = /^(?:https?:)?\\/\\//i;\nimport url from 'url';\nlet request;\nimport AbstractFileManager from '../less/environment/abstract-file-manager.js';\nimport logger from '../less/logger';\n\nconst UrlFileManager = function() {}\nUrlFileManager.prototype = Object.assign(new AbstractFileManager(), {\n supports(filename, currentDirectory, options, environment) {\n return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);\n },\n\n loadFile(filename, currentDirectory, options, environment) {\n return new Promise((fulfill, reject) => {\n if (request === undefined) {\n try { request = require('native-request'); }\n catch (e) { request = null; }\n }\n if (!request) {\n reject({ type: 'File', message: 'optional dependency \\'native-request\\' required to import over http(s)\\n' });\n return;\n }\n\n let urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename);\n \n /** native-request currently has a bug */\n const hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr\n\n request.get(hackUrlStr, (error, body, status) => {\n if (status === 404) {\n reject({ type: 'File', message: `resource '${urlStr}' was not found\\n` });\n return;\n }\n if (error) {\n reject({ type: 'File', message: `resource '${urlStr}' gave this Error:\\n ${error}\\n` });\n return;\n }\n if (!body) {\n logger.warn(`Warning: Empty body (HTTP ${status}) returned by \"${urlStr}\"`);\n }\n fulfill({ contents: body, filename: urlStr });\n });\n });\n }\n});\n\nexport default UrlFileManager;\n"]}
1
+ {"version":3,"file":"url-file-manager.js","sourceRoot":"","sources":["../../src/less-node/url-file-manager.js"],"names":[],"mappings":";;;AAAA,IAAM,OAAO,GAAG,oBAAoB,CAAC;AACrC,oDAAsB;AACtB,IAAI,OAAO,CAAC;AACZ,kHAA+E;AAC/E,kEAAoC;AAEpC,IAAM,cAAc,GAAG,cAAY,CAAC,CAAA;AACpC,cAAc,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,kCAAmB,EAAE,EAAE;IAChE,QAAQ,YAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW;QACrD,OAAO,OAAO,CAAC,IAAI,CAAE,QAAQ,CAAE,IAAI,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtE,CAAC;IAED,QAAQ,YAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW;QACrD,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAC/B,IAAI,OAAO,KAAK,SAAS,EAAE;gBACvB,IAAI;oBAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;iBAAE;gBACpC,OAAO,CAAC,EAAE;oBAAE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IAAI,CAAC,IAAI,EAAE;oBACP,gBAAM,CAAC,IAAI,CAAC,+BAA6B,IAAI,CAAC,UAAU,wBAAkB,MAAM,OAAG,CAAC,CAAC;iBACxF;gBACD,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YACxD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC,CAAC;AAEH,kBAAe,cAAc,CAAC","sourcesContent":["const isUrlRe = /^(?:https?:)?\\/\\//i;\nimport url from 'url';\nlet request;\nimport AbstractFileManager from '../less/environment/abstract-file-manager.js';\nimport logger from '../less/logger';\n\nconst UrlFileManager = function() {}\nUrlFileManager.prototype = Object.assign(new AbstractFileManager(), {\n supports(filename, currentDirectory, options, environment) {\n return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);\n },\n\n loadFile(filename, currentDirectory, options, environment) {\n return new Promise((fulfill, reject) => {\n if (request === undefined) {\n try { request = require('needle'); }\n catch (e) { request = null; }\n }\n if (!request) {\n reject({ type: 'File', message: 'optional dependency \\'native-request\\' required to import over http(s)\\n' });\n return;\n }\n\n let urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename);\n\n /** native-request currently has a bug */\n const hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr\n\n request.get(hackUrlStr, { follow_max: 5 }, (err, resp, body) => {\n if (err || resp && resp.statusCode >= 400) {\n const message = resp && resp.statusCode === 404\n ? `resource '${urlStr}' was not found\\n`\n : `resource '${urlStr}' gave this Error:\\n ${err || resp.statusMessage || resp.statusCode}\\n`;\n reject({ type: 'File', message });\n return;\n }\n if (resp.statusCode >= 300) {\n reject({ type: 'File', message: `resource '${urlStr}' caused too many redirects` });\n return;\n }\n body = body.toString('utf8');\n if (!body) {\n logger.warn(`Warning: Empty body (HTTP ${resp.statusCode}) returned by \"${urlStr}\"`);\n }\n fulfill({ contents: body || '', filename: urlStr });\n });\n });\n }\n});\n\nexport default UrlFileManager;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "less",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "Leaner CSS",
5
5
  "homepage": "http://lesscss.org",
6
6
  "author": {
@@ -50,13 +50,15 @@
50
50
  "image-size": "~0.5.0",
51
51
  "make-dir": "^2.1.0",
52
52
  "mime": "^1.4.1",
53
- "native-request": "^1.0.5",
53
+ "needle": "^2.5.2",
54
54
  "source-map": "~0.6.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@less/test-data": "^4.0.0",
57
+ "@less/test-data": "^4.1.0",
58
58
  "@less/test-import-module": "^4.0.0",
59
+ "@rollup/plugin-commonjs": "^17.0.0",
59
60
  "@rollup/plugin-json": "^4.1.0",
61
+ "@rollup/plugin-node-resolve": "^11.0.0",
60
62
  "@typescript-eslint/eslint-plugin": "^3.3.0",
61
63
  "@typescript-eslint/parser": "^3.3.0",
62
64
  "benny": "^3.6.12",
@@ -82,22 +84,21 @@
82
84
  "mocha": "^6.2.1",
83
85
  "mocha-headless-chrome": "^2.0.3",
84
86
  "mocha-teamcity-reporter": "^3.0.0",
87
+ "nock": "^11.8.2",
85
88
  "npm-run-all": "^4.1.5",
86
89
  "performance-now": "^0.2.0",
87
90
  "phin": "^2.2.3",
88
91
  "promise": "^7.1.1",
89
92
  "read-glob": "^3.0.0",
90
93
  "resolve": "^1.17.0",
91
- "rollup": "^1.17.0",
92
- "rollup-plugin-commonjs": "^10.0.1",
93
- "rollup-plugin-node-resolve": "^5.2.0",
94
+ "rollup": "^2.34.1",
94
95
  "rollup-plugin-terser": "^5.1.1",
95
- "rollup-plugin-typescript2": "^0.24.3",
96
+ "rollup-plugin-typescript2": "^0.29.0",
96
97
  "semver": "^6.3.0",
97
98
  "shx": "^0.3.2",
98
99
  "time-grunt": "^1.3.0",
99
100
  "ts-node": "^8.4.1",
100
- "typescript": "^3.6.3",
101
+ "typescript": "^4.1.3",
101
102
  "uikit": "2.27.4"
102
103
  },
103
104
  "keywords": [
package/test/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  var lessTest = require('./less-test'),
2
2
  lessTester = lessTest(),
3
3
  path = require('path'),
4
- stylize = require('../lib/less-node/lessc-helper').stylize;
4
+ stylize = require('../lib/less-node/lessc-helper').stylize,
5
+ nock = require('nock');
5
6
 
6
7
  console.log('\n' + stylize('Less', 'underline') + '\n');
7
8
 
@@ -39,7 +40,7 @@ var testMap = [
39
40
  // TODO: Change this to rewriteUrls: false once the relativeUrls option is removed
40
41
  [{math: 'strict', relativeUrls: false, rootpath: 'folder (1)/'}, 'static-urls/'],
41
42
  [{math: 'strict', compress: true}, 'compression/'],
42
-
43
+
43
44
  [{math: 0, strictUnits: true}, 'units/strict/'],
44
45
  [{math: 0, strictUnits: false}, 'units/no-strict/'],
45
46
 
@@ -88,3 +89,20 @@ lessTester.testSyncronous({syncImport: true}, 'math/strict/css');
88
89
  lessTester.testNoOptions();
89
90
  lessTester.testJSImport();
90
91
  lessTester.finished();
92
+
93
+ (() => {
94
+ // Create new tester, since tests are not independent and tests
95
+ // above modify tester in a way that breaks remote imports.
96
+ lessTester = lessTest();
97
+ var scope = nock('https://example.com')
98
+ .get('/redirect.less').query(true)
99
+ .reply(301, null, { location: '/target.less' })
100
+ .get('/target.less').query(true)
101
+ .reply(200);
102
+ lessTester.runTestSet(
103
+ {},
104
+ 'import-redirect/',
105
+ lessTester.testImportRedirect(scope)
106
+ );
107
+ lessTester.finished();
108
+ })();
package/test/less-test.js CHANGED
@@ -1,5 +1,23 @@
1
1
  /* jshint latedef: nofunc */
2
2
 
3
+ var logger = require('../lib/less/logger').default;
4
+
5
+ var isVerbose = process.env.npm_config_loglevel !== 'concise';
6
+ logger.addListener({
7
+ info(msg) {
8
+ if (isVerbose) {
9
+ process.stdout.write(msg + '\n');
10
+ }
11
+ },
12
+ warn(msg) {
13
+ process.stdout.write(msg + '\n');
14
+ },
15
+ erro(msg) {
16
+ process.stdout.write(msg + '\n');
17
+ }
18
+ });
19
+
20
+
3
21
  module.exports = function() {
4
22
  var path = require('path'),
5
23
  fs = require('fs'),
@@ -14,8 +32,6 @@ module.exports = function() {
14
32
  var oneTestOnly = process.argv[2],
15
33
  isFinished = false;
16
34
 
17
- var isVerbose = process.env.npm_config_loglevel !== 'concise';
18
-
19
35
  var testFolder = path.dirname(require.resolve('@less/test-data'));
20
36
  var lessFolder = path.join(testFolder, 'less');
21
37
 
@@ -27,20 +43,6 @@ module.exports = function() {
27
43
  }
28
44
  }
29
45
 
30
- less.logger.addListener({
31
- info: function(msg) {
32
- if (isVerbose) {
33
- process.stdout.write(msg + '\n');
34
- }
35
- },
36
- warn: function(msg) {
37
- process.stdout.write(msg + '\n');
38
- },
39
- error: function(msg) {
40
- process.stdout.write(msg + '\n');
41
- }
42
- });
43
-
44
46
  var queueList = [],
45
47
  queueRunning = false;
46
48
  function queue(func) {
@@ -519,6 +521,23 @@ module.exports = function() {
519
521
  ok(stylize('OK\n', 'green'));
520
522
  }
521
523
 
524
+ function testImportRedirect(nockScope) {
525
+ return (name, err, css, doReplacements, sourcemap, baseFolder) => {
526
+ process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
527
+ if (err) {
528
+ fail('FAIL: ' + (err && err.message));
529
+ return;
530
+ }
531
+ const expected = 'h1 {\n color: red;\n}\n';
532
+ if (css !== expected) {
533
+ difference('FAIL', expected, css);
534
+ return;
535
+ }
536
+ nockScope.done();
537
+ ok('OK');
538
+ };
539
+ }
540
+
522
541
  return {
523
542
  runTestSet: runTestSet,
524
543
  runTestSetNormalOnly: runTestSetNormalOnly,
@@ -527,6 +546,7 @@ module.exports = function() {
527
546
  testSourcemap: testSourcemap,
528
547
  testSourcemapWithoutUrlAnnotation: testSourcemapWithoutUrlAnnotation,
529
548
  testImports: testImports,
549
+ testImportRedirect: testImportRedirect,
530
550
  testEmptySourcemap: testEmptySourcemap,
531
551
  testNoOptions: testNoOptions,
532
552
  testJSImport: testJSImport,