Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tree caching in import manager #3498

Merged
merged 1 commit into from Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 8 additions & 21 deletions bin/lessc
Expand Up @@ -1762,7 +1762,7 @@ contexts.Eval = /** @class */ (function () {
};
Eval.prototype.exitCalc = function () {
this.calcStack.pop();
if (!this.calcStack) {
if (!this.calcStack.length) {
this.inCalc = false;
}
};
Expand Down Expand Up @@ -8727,6 +8727,9 @@ var Parser = function Parser(context, imports, fileInfo) {
continue;
}
e = this.addition() || this.entity();
if (e instanceof tree.Comment) {
e = null;
}
if (e) {
entities.push(e);
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
Expand Down Expand Up @@ -10141,7 +10144,6 @@ 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 = {}; // Holds the imported parse trees.
}
/**
* Add an import to be imported
Expand All @@ -10163,12 +10165,6 @@ var importManager = (function (environment) {
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
// Inline imports aren't cached here.
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
// same name as they used to do before this comment and the condition below have been added.
if (!importManager.files[fullPath] && !importOptions.inline) {
importManager.files[fullPath] = { root: root, options: importOptions };
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10225,18 +10221,9 @@ var importManager = (function (environment) {
fileParsedFunc(null, contents, resolvedFilename);
}
else {
// import (multiple) parse trees apparently get altered and can't be cached.
// TODO: investigate why this is
if (importManager.files[resolvedFilename]
&& !importManager.files[resolvedFilename].options.multiple
&& !importOptions.multiple) {
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
}
else {
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
};
var promise;
Expand Down Expand Up @@ -10562,7 +10549,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 1],
version: [3, 11, 2],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
29 changes: 8 additions & 21 deletions dist/less.cjs.js
Expand Up @@ -1758,7 +1758,7 @@ contexts.Eval = /** @class */ (function () {
};
Eval.prototype.exitCalc = function () {
this.calcStack.pop();
if (!this.calcStack) {
if (!this.calcStack.length) {
this.inCalc = false;
}
};
Expand Down Expand Up @@ -8723,6 +8723,9 @@ var Parser = function Parser(context, imports, fileInfo) {
continue;
}
e = this.addition() || this.entity();
if (e instanceof tree.Comment) {
e = null;
}
if (e) {
entities.push(e);
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
Expand Down Expand Up @@ -10137,7 +10140,6 @@ 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 = {}; // Holds the imported parse trees.
}
/**
* Add an import to be imported
Expand All @@ -10159,12 +10161,6 @@ var importManager = (function (environment) {
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
// Inline imports aren't cached here.
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
// same name as they used to do before this comment and the condition below have been added.
if (!importManager.files[fullPath] && !importOptions.inline) {
importManager.files[fullPath] = { root: root, options: importOptions };
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10221,18 +10217,9 @@ var importManager = (function (environment) {
fileParsedFunc(null, contents, resolvedFilename);
}
else {
// import (multiple) parse trees apparently get altered and can't be cached.
// TODO: investigate why this is
if (importManager.files[resolvedFilename]
&& !importManager.files[resolvedFilename].options.multiple
&& !importOptions.multiple) {
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
}
else {
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
};
var promise;
Expand Down Expand Up @@ -10558,7 +10545,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 1],
version: [3, 11, 2],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
31 changes: 9 additions & 22 deletions dist/less.js
@@ -1,5 +1,5 @@
/**
* Less - Leaner CSS v3.11.1
* Less - Leaner CSS v3.11.2
* http://lesscss.org
*
* Copyright (c) 2009-2020, Alexis Sellier <self@cloudhead.net>
Expand Down Expand Up @@ -1866,7 +1866,7 @@
};
Eval.prototype.exitCalc = function () {
this.calcStack.pop();
if (!this.calcStack) {
if (!this.calcStack.length) {
this.inCalc = false;
}
};
Expand Down Expand Up @@ -8981,6 +8981,9 @@
continue;
}
e = this.addition() || this.entity();
if (e instanceof tree.Comment) {
e = null;
}
if (e) {
entities.push(e);
// operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
Expand Down Expand Up @@ -10395,7 +10398,6 @@
this.context = context;
// Deprecated? Unused outside of here, could be useful.
this.queue = []; // Files which haven't been imported yet
this.files = {}; // Holds the imported parse trees.
}
/**
* Add an import to be imported
Expand All @@ -10417,12 +10419,6 @@
logger.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
}
else {
// Inline imports aren't cached here.
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
// same name as they used to do before this comment and the condition below have been added.
if (!importManager.files[fullPath] && !importOptions.inline) {
importManager.files[fullPath] = { root: root, options: importOptions };
}
if (e && !importManager.error) {
importManager.error = e;
}
Expand Down Expand Up @@ -10479,18 +10475,9 @@
fileParsedFunc(null, contents, resolvedFilename);
}
else {
// import (multiple) parse trees apparently get altered and can't be cached.
// TODO: investigate why this is
if (importManager.files[resolvedFilename]
&& !importManager.files[resolvedFilename].options.multiple
&& !importOptions.multiple) {
fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
}
else {
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
fileParsedFunc(e, root, resolvedFilename);
});
}
};
var promise;
Expand Down Expand Up @@ -10816,7 +10803,7 @@
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 1],
version: [3, 11, 2],
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.

24 changes: 3 additions & 21 deletions lib/less/import-manager.js
Expand Up @@ -26,7 +26,6 @@ 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 = {}; // Holds the imported parse trees.
}

/**
Expand All @@ -52,12 +51,6 @@ export default environment => {
logger.info(`The file ${fullPath} was skipped because it was not found and the import was marked optional.`);
}
else {
// Inline imports aren't cached here.
// If we start to cache them, please make sure they won't conflict with non-inline imports of the
// same name as they used to do before this comment and the condition below have been added.
if (!importManager.files[fullPath] && !importOptions.inline) {
importManager.files[fullPath] = { root, options: importOptions };
}
if (e && !importManager.error) { importManager.error = e; }
callback(e, root, importedEqualsRoot, fullPath);
}
Expand Down Expand Up @@ -122,20 +115,9 @@ export default environment => {
} else if (importOptions.inline) {
fileParsedFunc(null, contents, resolvedFilename);
} else {

// import (multiple) parse trees apparently get altered and can't be cached.
// TODO: investigate why this is
if (importManager.files[resolvedFilename]
&& !importManager.files[resolvedFilename].options.multiple
&& !importOptions.multiple) {

fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
}
else {
new Parser(newEnv, importManager, newFileInfo).parse(contents, (e, root) => {
fileParsedFunc(e, root, resolvedFilename);
});
}
new Parser(newEnv, importManager, newFileInfo).parse(contents, (e, root) => {
fileParsedFunc(e, root, resolvedFilename);
});
}
};
let promise;
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, 1],
version: [3, 11, 2],
data,
tree,
Environment,
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "less",
"version": "3.11.1",
"version": "3.11.2",
"description": "Leaner CSS",
"homepage": "http://lesscss.org",
"author": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"errno": "^0.1.1",
"graceful-fs": "^4.1.2",
"image-size": "~0.5.0",
"make-dir":"^2.1.0",
"make-dir": "^2.1.0",
"mime": "^1.4.1",
"promise": "^7.1.1",
"request": "^2.83.0",
Expand Down