Skip to content

Commit

Permalink
Fixes #3508 (#3509)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Jun 5, 2020
1 parent 8338366 commit 6238bbc
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 38 deletions.
20 changes: 12 additions & 8 deletions bin/lessc
Expand Up @@ -1646,8 +1646,11 @@ var debugInfo = function (context, ctx, lineSeparator) {
}
return result;
};
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
debugInfo.asMediaQuery = function (ctx) {
if (!ctx.debugInfo) {
return '';
}
var filenameWithProtocol = ctx.debugInfo.fileName;
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
filenameWithProtocol = "file://" + filenameWithProtocol;
Expand Down Expand Up @@ -10110,12 +10113,8 @@ var parseTree = (function (SourceMapBuilder) {
if (options.sourceMap) {
result.map = sourceMapBuilder.getExternalSourceMap();
}
result.imports = [];
for (var file_1 in this.imports.files) {
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
result.imports.push(file_1);
}
}
var rootFilename = this.imports.rootFilename;
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
return result;
};
return ParseTree;
Expand Down Expand Up @@ -10144,6 +10143,7 @@ var importManager = (function (environment) {
this.context = context;
// Deprecated? Unused outside of here, could be useful.
this.queue = []; // Files which haven't been imported yet
this.files = []; // List of files imported
}
/**
* Add an import to be imported
Expand All @@ -10165,6 +10165,10 @@ var importManager = (function (environment) {
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
var files = importManager.files;
if (files.indexOf(fullPath) === -1) {
files.push(fullPath);
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10549,7 +10553,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 2],
version: [3, 11, 3],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
20 changes: 12 additions & 8 deletions dist/less.cjs.js
Expand Up @@ -1642,8 +1642,11 @@ var debugInfo = function (context, ctx, lineSeparator) {
}
return result;
};
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
debugInfo.asMediaQuery = function (ctx) {
if (!ctx.debugInfo) {
return '';
}
var filenameWithProtocol = ctx.debugInfo.fileName;
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
filenameWithProtocol = "file://" + filenameWithProtocol;
Expand Down Expand Up @@ -10106,12 +10109,8 @@ var parseTree = (function (SourceMapBuilder) {
if (options.sourceMap) {
result.map = sourceMapBuilder.getExternalSourceMap();
}
result.imports = [];
for (var file_1 in this.imports.files) {
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
result.imports.push(file_1);
}
}
var rootFilename = this.imports.rootFilename;
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
return result;
};
return ParseTree;
Expand Down Expand Up @@ -10140,6 +10139,7 @@ var importManager = (function (environment) {
this.context = context;
// Deprecated? Unused outside of here, could be useful.
this.queue = []; // Files which haven't been imported yet
this.files = []; // List of files imported
}
/**
* Add an import to be imported
Expand All @@ -10161,6 +10161,10 @@ var importManager = (function (environment) {
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
var files = importManager.files;
if (files.indexOf(fullPath) === -1) {
files.push(fullPath);
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10545,7 +10549,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 2],
version: [3, 11, 3],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
22 changes: 13 additions & 9 deletions dist/less.js
@@ -1,5 +1,5 @@
/**
* Less - Leaner CSS v3.11.2
* Less - Leaner CSS v3.11.3
* http://lesscss.org
*
* Copyright (c) 2009-2020, Alexis Sellier <self@cloudhead.net>
Expand Down Expand Up @@ -1750,8 +1750,11 @@
}
return result;
};
debugInfo.asComment = function (ctx) { return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n"; };
debugInfo.asComment = function (ctx) { return ctx.debugInfo ? "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n" : ''; };
debugInfo.asMediaQuery = function (ctx) {
if (!ctx.debugInfo) {
return '';
}
var filenameWithProtocol = ctx.debugInfo.fileName;
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
filenameWithProtocol = "file://" + filenameWithProtocol;
Expand Down Expand Up @@ -10364,12 +10367,8 @@
if (options.sourceMap) {
result.map = sourceMapBuilder.getExternalSourceMap();
}
result.imports = [];
for (var file_1 in this.imports.files) {
if (this.imports.files.hasOwnProperty(file_1) && file_1 !== this.imports.rootFilename) {
result.imports.push(file_1);
}
}
var rootFilename = this.imports.rootFilename;
result.imports = this.imports.files.filter(function (file) { return file !== rootFilename; });
return result;
};
return ParseTree;
Expand Down Expand Up @@ -10398,6 +10397,7 @@
this.context = context;
// Deprecated? Unused outside of here, could be useful.
this.queue = []; // Files which haven't been imported yet
this.files = []; // List of files imported
}
/**
* Add an import to be imported
Expand All @@ -10419,6 +10419,10 @@
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
var files = importManager.files;
if (files.indexOf(fullPath) === -1) {
files.push(fullPath);
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10803,7 +10807,7 @@
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 2],
version: [3, 11, 3],
data: data,
tree: tree,
Environment: environment,
Expand Down
4 changes: 2 additions & 2 deletions dist/less.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/less.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions lib/less/import-manager.js
Expand Up @@ -26,6 +26,7 @@ export default environment => {
this.context = context;
// Deprecated? Unused outside of here, could be useful.
this.queue = []; // Files which haven't been imported yet
this.files = []; // List of files imported
}

/**
Expand All @@ -51,6 +52,10 @@ export default environment => {
logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
}
else {
const files = importManager.files
if (files.indexOf(fullPath) === -1) {
files.push(fullPath)
}
if (e && !importManager.error) { importManager.error = e; }
callback(e, root, importedEqualsRoot, fullPath);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/less/index.js
Expand Up @@ -42,7 +42,7 @@ export default (environment, fileManagers) => {
* It's not clear what should / must be public and why.
*/
const initial = {
version: [3, 11, 2],
version: [3, 11, 3],
data,
tree,
Environment,
Expand Down
8 changes: 2 additions & 6 deletions lib/less/parse-tree.js
Expand Up @@ -52,12 +52,8 @@ export default SourceMapBuilder => {
result.map = sourceMapBuilder.getExternalSourceMap();
}

result.imports = [];
for (const file in this.imports.files) {
if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
result.imports.push(file);
}
}
const rootFilename = this.imports.rootFilename
result.imports = this.imports.files.filter(file => file !== rootFilename);
return result;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "less",
"version": "3.11.2",
"version": "3.11.3",
"description": "Leaner CSS",
"homepage": "http://lesscss.org",
"author": {
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Expand Up @@ -48,6 +48,12 @@ var testMap = [
}
return path.join('test/sourcemaps', filename) + '.json';
}],

[{math: 'strict', strictUnits: true, globalVars: true }, 'import/json/',
lessTester.testImports, null, true,
function(filename, type, baseFolder) {
return path.join(baseFolder, filename) + '.json';
}],
[{math: 'strict', strictUnits: true, sourceMap: {sourceMapFileInline: true}},
'sourcemaps-empty/', lessTester.testEmptySourcemap],
[{globalVars: true, banner: '/**\n * Test\n */\n'}, 'globalVars/',
Expand Down
46 changes: 44 additions & 2 deletions test/less-test.js
Expand Up @@ -140,6 +140,42 @@ module.exports = function() {
}
}

function testImports(name, err, compiledLess, doReplacements, sourcemap, baseFolder, imports) {
if (err) {
fail('ERROR: ' + (err && err.message));
return;
}

function stringify(str) {
return JSON.stringify(imports, null, ' ')
}

/** Imports are not sorted */
const importsString = stringify(imports.sort())

fs.readFile(path.join('test/less/', name) + '.json', 'utf8', function (e, expectedImports) {
if (e) {
fail('ERROR: ' + (e && e.message));
return;
}
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
expectedImports = stringify(JSON.parse(expectedImports).sort());
expectedImports = globalReplacements(expectedImports, baseFolder);

if (expectedImports === importsString) {
ok('OK');
} else if (err) {
fail('ERROR: ' + (err && err.message));
if (isVerbose) {
process.stdout.write('\n');
process.stdout.write(err.stack + '\n');
}
} else {
difference('FAIL', expectedImports, importsString);
}
});
}

function testErrors(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
fs.readFile(path.join(baseFolder, name) + '.txt', 'utf8', function (e, expectedErr) {
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
Expand Down Expand Up @@ -303,8 +339,13 @@ module.exports = function() {
}
doubleCallCheck = (new Error()).stack;

/**
* @todo - refactor so the result object is sent to the verify function
*/
if (verifyFunction) {
var verificationResult = verifyFunction(name, err, result && result.css, doReplacements, result && result.map, baseFolder);
var verificationResult = verifyFunction(
name, err, result && result.css, doReplacements, result && result.map, baseFolder, result && result.imports
);
release();
return verificationResult;
}
Expand Down Expand Up @@ -362,7 +403,7 @@ module.exports = function() {
process.stdout.write(stylize(msg, 'yellow') + '\n');
failedTests++;

diff(left, right);
diff(left || '', right || '');
endTest();
}

Expand Down Expand Up @@ -452,6 +493,7 @@ module.exports = function() {
testSyncronous: testSyncronous,
testErrors: testErrors,
testSourcemap: testSourcemap,
testImports: testImports,
testEmptySourcemap: testEmptySourcemap,
testNoOptions: testNoOptions,
prepBomTest: prepBomTest,
Expand Down
11 changes: 11 additions & 0 deletions test/less/import/json/index.json
@@ -0,0 +1,11 @@
[
"{path}/import/import-test-a.less",
"{path}/import/import-test-b.less",
"{path}/import/deeper/url-import.less",
"{path}/import/urls.less",
"{path}/import/import-test-c.less",
"{path}/import/deeper/deeper-2/url-import.less",
"{path}/import/deeper/deeper-2/url-import-2.less",
"{path}/import/import-test-f.less",
"{path}/import/import-test-e.less"
]
1 change: 1 addition & 0 deletions test/less/import/json/index.less
@@ -0,0 +1 @@
@import "../import-test-a";

0 comments on commit 6238bbc

Please sign in to comment.