Skip to content

Commit 53bf877

Browse files
authored
Remove tree caching in import manager (#3498)
1 parent 0f271f3 commit 53bf877

File tree

8 files changed

+34
-91
lines changed

8 files changed

+34
-91
lines changed

bin/lessc

+8-21
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ contexts.Eval = /** @class */ (function () {
17621762
};
17631763
Eval.prototype.exitCalc = function () {
17641764
this.calcStack.pop();
1765-
if (!this.calcStack) {
1765+
if (!this.calcStack.length) {
17661766
this.inCalc = false;
17671767
}
17681768
};
@@ -8727,6 +8727,9 @@ var Parser = function Parser(context, imports, fileInfo) {
87278727
continue;
87288728
}
87298729
e = this.addition() || this.entity();
8730+
if (e instanceof tree.Comment) {
8731+
e = null;
8732+
}
87308733
if (e) {
87318734
entities.push(e);
87328735
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
@@ -10141,7 +10144,6 @@ var importManager = (function (environment) {
1014110144
this.context = context;
1014210145
// Deprecated? Unused outside of here, could be useful.
1014310146
this.queue = []; // Files which haven't been imported yet
10144-
this.files = {}; // Holds the imported parse trees.
1014510147
}
1014610148
/**
1014710149
* Add an import to be imported
@@ -10163,12 +10165,6 @@ var importManager = (function (environment) {
1016310165
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1016410166
}
1016510167
else {
10166-
// Inline imports aren't cached here.
10167-
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
10168-
// same name as they used to do before this comment and the condition below have been added.
10169-
if (!importManager.files[fullPath] && !importOptions.inline) {
10170-
importManager.files[fullPath] = { root: root, options: importOptions };
10171-
}
1017210168
if (e && !importManager.error) {
1017310169
importManager.error = e;
1017410170
}
@@ -10225,18 +10221,9 @@ var importManager = (function (environment) {
1022510221
fileParsedFunc(null, contents, resolvedFilename);
1022610222
}
1022710223
else {
10228-
// import (multiple) parse trees apparently get altered and can't be cached.
10229-
// TODO: investigate why this is
10230-
if (importManager.files[resolvedFilename]
10231-
&& !importManager.files[resolvedFilename].options.multiple
10232-
&& !importOptions.multiple) {
10233-
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
10234-
}
10235-
else {
10236-
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10237-
fileParsedFunc(e, root, resolvedFilename);
10238-
});
10239-
}
10224+
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10225+
fileParsedFunc(e, root, resolvedFilename);
10226+
});
1024010227
}
1024110228
};
1024210229
var promise;
@@ -10562,7 +10549,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
1056210549
* It's not clear what should / must be public and why.
1056310550
*/
1056410551
var initial = {
10565-
version: [3, 11, 1],
10552+
version: [3, 11, 2],
1056610553
data: data,
1056710554
tree: tree,
1056810555
Environment: environment$1,

dist/less.cjs.js

+8-21
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ contexts.Eval = /** @class */ (function () {
17581758
};
17591759
Eval.prototype.exitCalc = function () {
17601760
this.calcStack.pop();
1761-
if (!this.calcStack) {
1761+
if (!this.calcStack.length) {
17621762
this.inCalc = false;
17631763
}
17641764
};
@@ -8723,6 +8723,9 @@ var Parser = function Parser(context, imports, fileInfo) {
87238723
continue;
87248724
}
87258725
e = this.addition() || this.entity();
8726+
if (e instanceof tree.Comment) {
8727+
e = null;
8728+
}
87268729
if (e) {
87278730
entities.push(e);
87288731
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
@@ -10137,7 +10140,6 @@ var importManager = (function (environment) {
1013710140
this.context = context;
1013810141
// Deprecated? Unused outside of here, could be useful.
1013910142
this.queue = []; // Files which haven't been imported yet
10140-
this.files = {}; // Holds the imported parse trees.
1014110143
}
1014210144
/**
1014310145
* Add an import to be imported
@@ -10159,12 +10161,6 @@ var importManager = (function (environment) {
1015910161
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1016010162
}
1016110163
else {
10162-
// Inline imports aren't cached here.
10163-
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
10164-
// same name as they used to do before this comment and the condition below have been added.
10165-
if (!importManager.files[fullPath] && !importOptions.inline) {
10166-
importManager.files[fullPath] = { root: root, options: importOptions };
10167-
}
1016810164
if (e && !importManager.error) {
1016910165
importManager.error = e;
1017010166
}
@@ -10221,18 +10217,9 @@ var importManager = (function (environment) {
1022110217
fileParsedFunc(null, contents, resolvedFilename);
1022210218
}
1022310219
else {
10224-
// import (multiple) parse trees apparently get altered and can't be cached.
10225-
// TODO: investigate why this is
10226-
if (importManager.files[resolvedFilename]
10227-
&& !importManager.files[resolvedFilename].options.multiple
10228-
&& !importOptions.multiple) {
10229-
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
10230-
}
10231-
else {
10232-
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10233-
fileParsedFunc(e, root, resolvedFilename);
10234-
});
10235-
}
10220+
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10221+
fileParsedFunc(e, root, resolvedFilename);
10222+
});
1023610223
}
1023710224
};
1023810225
var promise;
@@ -10558,7 +10545,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
1055810545
* It's not clear what should / must be public and why.
1055910546
*/
1056010547
var initial = {
10561-
version: [3, 11, 1],
10548+
version: [3, 11, 2],
1056210549
data: data,
1056310550
tree: tree,
1056410551
Environment: environment$1,

dist/less.js

+9-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Less - Leaner CSS v3.11.1
2+
* Less - Leaner CSS v3.11.2
33
* http://lesscss.org
44
*
55
* Copyright (c) 2009-2020, Alexis Sellier <[email protected]>
@@ -1866,7 +1866,7 @@
18661866
};
18671867
Eval.prototype.exitCalc = function () {
18681868
this.calcStack.pop();
1869-
if (!this.calcStack) {
1869+
if (!this.calcStack.length) {
18701870
this.inCalc = false;
18711871
}
18721872
};
@@ -8981,6 +8981,9 @@
89818981
continue;
89828982
}
89838983
e = this.addition() || this.entity();
8984+
if (e instanceof tree.Comment) {
8985+
e = null;
8986+
}
89848987
if (e) {
89858988
entities.push(e);
89868989
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
@@ -10395,7 +10398,6 @@
1039510398
this.context = context;
1039610399
// Deprecated? Unused outside of here, could be useful.
1039710400
this.queue = []; // Files which haven't been imported yet
10398-
this.files = {}; // Holds the imported parse trees.
1039910401
}
1040010402
/**
1040110403
* Add an import to be imported
@@ -10417,12 +10419,6 @@
1041710419
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
1041810420
}
1041910421
else {
10420-
// Inline imports aren't cached here.
10421-
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
10422-
// same name as they used to do before this comment and the condition below have been added.
10423-
if (!importManager.files[fullPath] && !importOptions.inline) {
10424-
importManager.files[fullPath] = { root: root, options: importOptions };
10425-
}
1042610422
if (e && !importManager.error) {
1042710423
importManager.error = e;
1042810424
}
@@ -10479,18 +10475,9 @@
1047910475
fileParsedFunc(null, contents, resolvedFilename);
1048010476
}
1048110477
else {
10482-
// import (multiple) parse trees apparently get altered and can't be cached.
10483-
// TODO: investigate why this is
10484-
if (importManager.files[resolvedFilename]
10485-
&& !importManager.files[resolvedFilename].options.multiple
10486-
&& !importOptions.multiple) {
10487-
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
10488-
}
10489-
else {
10490-
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10491-
fileParsedFunc(e, root, resolvedFilename);
10492-
});
10493-
}
10478+
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
10479+
fileParsedFunc(e, root, resolvedFilename);
10480+
});
1049410481
}
1049510482
};
1049610483
var promise;
@@ -10816,7 +10803,7 @@
1081610803
* It's not clear what should / must be public and why.
1081710804
*/
1081810805
var initial = {
10819-
version: [3, 11, 1],
10806+
version: [3, 11, 2],
1082010807
data: data,
1082110808
tree: tree,
1082210809
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

+3-21
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ 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 = {}; // Holds the imported parse trees.
3029
}
3130

3231
/**
@@ -52,12 +51,6 @@ export default environment => {
5251
logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
5352
}
5453
else {
55-
// Inline imports aren't cached here.
56-
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
57-
// same name as they used to do before this comment and the condition below have been added.
58-
if (!importManager.files[fullPath] && !importOptions.inline) {
59-
importManager.files[fullPath] = { root, options: importOptions };
60-
}
6154
if (e && !importManager.error) { importManager.error = e; }
6255
callback(e, root, importedEqualsRoot, fullPath);
6356
}
@@ -122,20 +115,9 @@ export default environment => {
122115
} else if (importOptions.inline) {
123116
fileParsedFunc(null, contents, resolvedFilename);
124117
} else {
125-
126-
// import (multiple) parse trees apparently get altered and can't be cached.
127-
// TODO: investigate why this is
128-
if (importManager.files[resolvedFilename]
129-
&& !importManager.files[resolvedFilename].options.multiple
130-
&& !importOptions.multiple) {
131-
132-
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
133-
}
134-
else {
135-
new Parser(newEnv, importManager, newFileInfo).parse(contents, (e, root) => {
136-
fileParsedFunc(e, root, resolvedFilename);
137-
});
138-
}
118+
new Parser(newEnv, importManager, newFileInfo).parse(contents, (e, root) => {
119+
fileParsedFunc(e, root, resolvedFilename);
120+
});
139121
}
140122
};
141123
let promise;

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, 1],
45+
version: [3, 11, 2],
4646
data,
4747
tree,
4848
Environment,

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "less",
3-
"version": "3.11.1",
3+
"version": "3.11.2",
44
"description": "Leaner CSS",
55
"homepage": "http://lesscss.org",
66
"author": {
@@ -43,7 +43,7 @@
4343
"errno": "^0.1.1",
4444
"graceful-fs": "^4.1.2",
4545
"image-size": "~0.5.0",
46-
"make-dir":"^2.1.0",
46+
"make-dir": "^2.1.0",
4747
"mime": "^1.4.1",
4848
"promise": "^7.1.1",
4949
"request": "^2.83.0",

0 commit comments

Comments
 (0)