Skip to content

Commit 6238bbc

Browse files
authored
Fixes #3508 (#3509)
1 parent 8338366 commit 6238bbc

File tree

13 files changed

+111
-38
lines changed

13 files changed

+111
-38
lines changed

bin/lessc

+12-8
Original file line numberDiff line numberDiff line change
@@ -1646,8 +1646,11 @@ var debugInfo = function (context, ctx, lineSeparator) {
16461646
}
16471647
return result;
16481648
};
1649-
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
1649+
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
16501650
debugInfo.asMediaQuery = function (ctx) {
1651+
if (!ctx.debugInfo) {
1652+
return '';
1653+
}
16511654
var filenameWithProtocol = ctx.debugInfo.fileName;
16521655
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
16531656
filenameWithProtocol = "file://" + filenameWithProtocol;
@@ -10110,12 +10113,8 @@ var parseTree = (function (SourceMapBuilder) {
1011010113
if (options.sourceMap) {
1011110114
result.map = sourceMapBuilder.getExternalSourceMap();
1011210115
}
10113-
result.imports = [];
10114-
for (var file_1 in this.imports.files) {
10115-
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
10116-
result.imports.push(file_1);
10117-
}
10118-
}
10116+
var rootFilename = this.imports.rootFilename;
10117+
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
1011910118
return result;
1012010119
};
1012110120
return ParseTree;
@@ -10144,6 +10143,7 @@ var importManager = (function (environment) {
1014410143
this.context = context;
1014510144
// Deprecated? Unused outside of here, could be useful.
1014610145
this.queue = []; // Files which haven't been imported yet
10146+
this.files = []; // List of files imported
1014710147
}
1014810148
/**
1014910149
* Add an import to be imported
@@ -10165,6 +10165,10 @@ var importManager = (function (environment) {
1016510165
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1016610166
}
1016710167
else {
10168+
var files = importManager.files;
10169+
if (files.indexOf(fullPath) === -1) {
10170+
files.push(fullPath);
10171+
}
1016810172
if (e && !importManager.error) {
1016910173
importManager.error = e;
1017010174
}
@@ -10549,7 +10553,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
1054910553
* It's not clear what should / must be public and why.
1055010554
*/
1055110555
var initial = {
10552-
version: [3, 11, 2],
10556+
version: [3, 11, 3],
1055310557
data: data,
1055410558
tree: tree,
1055510559
Environment: environment$1,

dist/less.cjs.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,11 @@ var debugInfo = function (context, ctx, lineSeparator) {
16421642
}
16431643
return result;
16441644
};
1645-
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
1645+
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
16461646
debugInfo.asMediaQuery = function (ctx) {
1647+
if (!ctx.debugInfo) {
1648+
return '';
1649+
}
16471650
var filenameWithProtocol = ctx.debugInfo.fileName;
16481651
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
16491652
filenameWithProtocol = "file://" + filenameWithProtocol;
@@ -10106,12 +10109,8 @@ var parseTree = (function (SourceMapBuilder) {
1010610109
if (options.sourceMap) {
1010710110
result.map = sourceMapBuilder.getExternalSourceMap();
1010810111
}
10109-
result.imports = [];
10110-
for (var file_1 in this.imports.files) {
10111-
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
10112-
result.imports.push(file_1);
10113-
}
10114-
}
10112+
var rootFilename = this.imports.rootFilename;
10113+
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
1011510114
return result;
1011610115
};
1011710116
return ParseTree;
@@ -10140,6 +10139,7 @@ var importManager = (function (environment) {
1014010139
this.context = context;
1014110140
// Deprecated? Unused outside of here, could be useful.
1014210141
this.queue = []; // Files which haven't been imported yet
10142+
this.files = []; // List of files imported
1014310143
}
1014410144
/**
1014510145
* Add an import to be imported
@@ -10161,6 +10161,10 @@ var importManager = (function (environment) {
1016110161
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1016210162
}
1016310163
else {
10164+
var files = importManager.files;
10165+
if (files.indexOf(fullPath) === -1) {
10166+
files.push(fullPath);
10167+
}
1016410168
if (e && !importManager.error) {
1016510169
importManager.error = e;
1016610170
}
@@ -10545,7 +10549,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
1054510549
* It's not clear what should / must be public and why.
1054610550
*/
1054710551
var initial = {
10548-
version: [3, 11, 2],
10552+
version: [3, 11, 3],
1054910553
data: data,
1055010554
tree: tree,
1055110555
Environment: environment$1,

dist/less.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Less - Leaner CSS v3.11.2
2+
* Less - Leaner CSS v3.11.3
33
* http://lesscss.org
44
*
55
* Copyright (c) 2009-2020, Alexis Sellier <[email protected]>
@@ -1750,8 +1750,11 @@
17501750
}
17511751
return result;
17521752
};
1753-
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
1753+
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
17541754
debugInfo.asMediaQuery = function (ctx) {
1755+
if (!ctx.debugInfo) {
1756+
return '';
1757+
}
17551758
var filenameWithProtocol = ctx.debugInfo.fileName;
17561759
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
17571760
filenameWithProtocol = "file://" + filenameWithProtocol;
@@ -10364,12 +10367,8 @@
1036410367
if (options.sourceMap) {
1036510368
result.map = sourceMapBuilder.getExternalSourceMap();
1036610369
}
10367-
result.imports = [];
10368-
for (var file_1 in this.imports.files) {
10369-
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
10370-
result.imports.push(file_1);
10371-
}
10372-
}
10370+
var rootFilename = this.imports.rootFilename;
10371+
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
1037310372
return result;
1037410373
};
1037510374
return ParseTree;
@@ -10398,6 +10397,7 @@
1039810397
this.context = context;
1039910398
// Deprecated? Unused outside of here, could be useful.
1040010399
this.queue = []; // Files which haven't been imported yet
10400+
this.files = []; // List of files imported
1040110401
}
1040210402
/**
1040310403
* Add an import to be imported
@@ -10419,6 +10419,10 @@
1041910419
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1042010420
}
1042110421
else {
10422+
var files = importManager.files;
10423+
if (files.indexOf(fullPath) === -1) {
10424+
files.push(fullPath);
10425+
}
1042210426
if (e && !importManager.error) {
1042310427
importManager.error = e;
1042410428
}
@@ -10803,7 +10807,7 @@
1080310807
* It's not clear what should / must be public and why.
1080410808
*/
1080510809
var initial = {
10806-
version: [3, 11, 2],
10810+
version: [3, 11, 3],
1080710811
data: data,
1080810812
tree: tree,
1080910813
Environment: environment,

dist/less.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/less.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/less/import-manager.js

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default environment => {
2626
this.context = context;
2727
// Deprecated? Unused outside of here, could be useful.
2828
this.queue = []; // Files which haven't been imported yet
29+
this.files = []; // List of files imported
2930
}
3031

3132
/**
@@ -51,6 +52,10 @@ export default environment => {
5152
logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
5253
}
5354
else {
55+
const files = importManager.files
56+
if (files.indexOf(fullPath) === -1) {
57+
files.push(fullPath)
58+
}
5459
if (e && !importManager.error) { importManager.error = e; }
5560
callback(e, root, importedEqualsRoot, fullPath);
5661
}

lib/less/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default (environment, fileManagers) => {
4242
* It's not clear what should / must be public and why.
4343
*/
4444
const initial = {
45-
version: [3, 11, 2],
45+
version: [3, 11, 3],
4646
data,
4747
tree,
4848
Environment,

lib/less/parse-tree.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,8 @@ export default SourceMapBuilder => {
5252
result.map = sourceMapBuilder.getExternalSourceMap();
5353
}
5454

55-
result.imports = [];
56-
for (const file in this.imports.files) {
57-
if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
58-
result.imports.push(file);
59-
}
60-
}
55+
const rootFilename = this.imports.rootFilename
56+
result.imports = this.imports.files.filter(file => file !== rootFilename);
6157
return result;
6258
}
6359
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "less",
3-
"version": "3.11.2",
3+
"version": "3.11.3",
44
"description": "Leaner CSS",
55
"homepage": "http://lesscss.org",
66
"author": {

test/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ var testMap = [
4848
}
4949
return path.join('test/sourcemaps', filename) + '.json';
5050
}],
51+
52+
[{math: 'strict', strictUnits: true, globalVars: true }, 'import/json/',
53+
lessTester.testImports, null, true,
54+
function(filename, type, baseFolder) {
55+
return path.join(baseFolder, filename) + '.json';
56+
}],
5157
[{math: 'strict', strictUnits: true, sourceMap: {sourceMapFileInline: true}},
5258
'sourcemaps-empty/', lessTester.testEmptySourcemap],
5359
[{globalVars: true, banner: '/**\n * Test\n */\n'}, 'globalVars/',

test/less-test.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ module.exports = function() {
140140
}
141141
}
142142

143+
function testImports(name, err, compiledLess, doReplacements, sourcemap, baseFolder, imports) {
144+
if (err) {
145+
fail('ERROR: ' + (err && err.message));
146+
return;
147+
}
148+
149+
function stringify(str) {
150+
return JSON.stringify(imports, null, ' ')
151+
}
152+
153+
/** Imports are not sorted */
154+
const importsString = stringify(imports.sort())
155+
156+
fs.readFile(path.join('test/less/', name) + '.json', 'utf8', function (e, expectedImports) {
157+
if (e) {
158+
fail('ERROR: ' + (e && e.message));
159+
return;
160+
}
161+
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
162+
expectedImports = stringify(JSON.parse(expectedImports).sort());
163+
expectedImports = globalReplacements(expectedImports, baseFolder);
164+
165+
if (expectedImports === importsString) {
166+
ok('OK');
167+
} else if (err) {
168+
fail('ERROR: ' + (err && err.message));
169+
if (isVerbose) {
170+
process.stdout.write('\n');
171+
process.stdout.write(err.stack + '\n');
172+
}
173+
} else {
174+
difference('FAIL', expectedImports, importsString);
175+
}
176+
});
177+
}
178+
143179
function testErrors(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
144180
fs.readFile(path.join(baseFolder, name) + '.txt', 'utf8', function (e, expectedErr) {
145181
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
@@ -303,8 +339,13 @@ module.exports = function() {
303339
}
304340
doubleCallCheck = (new Error()).stack;
305341

342+
/**
343+
* @todo - refactor so the result object is sent to the verify function
344+
*/
306345
if (verifyFunction) {
307-
var verificationResult = verifyFunction(name, err, result && result.css, doReplacements, result && result.map, baseFolder);
346+
var verificationResult = verifyFunction(
347+
name, err, result && result.css, doReplacements, result && result.map, baseFolder, result && result.imports
348+
);
308349
release();
309350
return verificationResult;
310351
}
@@ -362,7 +403,7 @@ module.exports = function() {
362403
process.stdout.write(stylize(msg, 'yellow') + '\n');
363404
failedTests++;
364405

365-
diff(left, right);
406+
diff(left || '', right || '');
366407
endTest();
367408
}
368409

@@ -452,6 +493,7 @@ module.exports = function() {
452493
testSyncronous: testSyncronous,
453494
testErrors: testErrors,
454495
testSourcemap: testSourcemap,
496+
testImports: testImports,
455497
testEmptySourcemap: testEmptySourcemap,
456498
testNoOptions: testNoOptions,
457499
prepBomTest: prepBomTest,

test/less/import/json/index.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
"{path}/import/import-test-a.less",
3+
"{path}/import/import-test-b.less",
4+
"{path}/import/deeper/url-import.less",
5+
"{path}/import/urls.less",
6+
"{path}/import/import-test-c.less",
7+
"{path}/import/deeper/deeper-2/url-import.less",
8+
"{path}/import/deeper/deeper-2/url-import-2.less",
9+
"{path}/import/import-test-f.less",
10+
"{path}/import/import-test-e.less"
11+
]

test/less/import/json/index.less

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "../import-test-a";

0 commit comments

Comments
 (0)