Skip to content

Commit

Permalink
Fixes: less#3300
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Aug 6, 2018
1 parent 4e903e8 commit 2053466
Show file tree
Hide file tree
Showing 11 changed files with 1,126 additions and 1,086 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ module.exports = function (grunt) {
keepRunner: true,
host: 'http://localhost:8081/',
vendor: [
'./node_modules/phantomjs-polyfill-object-assign/object-assign-polyfill.js',
'test/browser/vendor/promise.js',
'test/browser/jasmine-jsreporter.js',
'test/browser/common.js',
Expand Down
8 changes: 7 additions & 1 deletion lib/less-browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ module.exports = function(window, options) {
var typePattern = /^text\/(x-)?less$/;

function clone(obj) {
return JSON.parse(JSON.stringify(obj || {}));
var cloned = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
cloned[prop] = obj[prop];
}
}
return cloned;
}

// only really needed for phantom
Expand Down
4 changes: 2 additions & 2 deletions lib/less/source-map-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function (environment) {
sourceColumns,
i;

if (fileInfo) {
if (fileInfo && fileInfo.filename) {
var inputSource = this._contentsMap[fileInfo.filename];

// remove vars/banner added to the top of the file
Expand All @@ -77,7 +77,7 @@ module.exports = function (environment) {
lines = chunk.split('\n');
columns = lines[lines.length - 1];

if (fileInfo) {
if (fileInfo && fileInfo.filename) {
if (!mapLines) {
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
original: { line: sourceLines.length, column: sourceColumns.length},
Expand Down
31 changes: 12 additions & 19 deletions lib/less/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* jshint proto: true */
var Constants = require('./constants');
var clone = require('clone');

var utils = {
getLocation: function(index, inputStream) {
Expand Down Expand Up @@ -39,6 +40,9 @@ var utils = {
return cloned;
},
copyOptions: function(obj1, obj2) {
if (obj2 && obj2._defaults) {
return obj2;
}
var opts = utils.defaults(obj1, obj2);
if (opts.strictMath) {
opts.math = Constants.Math.STRICT_LEGACY;
Expand Down Expand Up @@ -79,26 +83,15 @@ var utils = {
return opts;
},
defaults: function(obj1, obj2) {
if (!obj2._defaults || obj2._defaults !== obj1) {
for (var prop in obj1) {
if (obj1.hasOwnProperty(prop)) {
if (!obj2.hasOwnProperty(prop)) {
obj2[prop] = obj1[prop];
}
else if (Array.isArray(obj1[prop])
&& Array.isArray(obj2[prop])) {

obj1[prop].forEach(function(p) {
if (obj2[prop].indexOf(p) === -1) {
obj2[prop].push(p);
}
});
}
}
}
var newObj = obj2 || {};
if (!obj2._defaults) {
newObj = {};
var defaults = clone(obj1);
newObj._defaults = defaults;
var cloned = obj2 ? clone(obj2) : {};
Object.assign(newObj, defaults, cloned);
}
obj2._defaults = obj1;
return obj2;
return newObj;
},
merge: function(obj1, obj2) {
for (var prop in obj2) {
Expand Down
Loading

0 comments on commit 2053466

Please sign in to comment.