From 540afe30dfdc268fc096866f8ee7b7a31b8d1e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Sat, 1 Apr 2023 00:03:44 +0200 Subject: [PATCH 1/3] remove phantom stuff --- packages/less/src/less-browser/index.js | 48 +++++++++++-------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/packages/less/src/less-browser/index.js b/packages/less/src/less-browser/index.js index 6ec83bb50..647037c0e 100644 --- a/packages/less/src/less-browser/index.js +++ b/packages/less/src/less-browser/index.js @@ -12,6 +12,10 @@ import ErrorReporting from './error-reporting'; import Cache from './cache'; import ImageSize from './image-size'; +/** + * @param {Window} window + * @param {Object} options + */ export default (window, options) => { const document = window.document; const less = lessRoot(); @@ -46,42 +50,32 @@ export default (window, options) => { return cloned; } - // only really needed for phantom - function bind(func, thisArg) { - const curryArgs = Array.prototype.slice.call(arguments, 2); - return function() { - const args = curryArgs.concat(Array.prototype.slice.call(arguments, 0)); - return func.apply(thisArg, args); - }; - } - function loadStyles(modifyVars) { const styles = document.getElementsByTagName('style'); - let style; - for (let i = 0; i < styles.length; i++) { - style = styles[i]; + for (let style of styles) { if (style.type.match(typePattern)) { - const instanceOptions = clone(options); - instanceOptions.modifyVars = modifyVars; + const instanceOptions = { + ...options, + modifyVars, + filename: document.location.href.replace(/#.*$/, ''), + } + const lessText = style.innerHTML || ''; - instanceOptions.filename = document.location.href.replace(/#.*$/, ''); /* jshint loopfunc:true */ - // use closure to store current style - less.render(lessText, instanceOptions, - bind((style, e, result) => { - if (e) { - errors.add(e, 'inline'); + less.render(lessText, instanceOptions, (err, result) => { + if (err) { + errors.add(err, 'inline'); + } else { + style.type = 'text/css'; + if (style.styleSheet) { + style.styleSheet.cssText = result.css; } else { - style.type = 'text/css'; - if (style.styleSheet) { - style.styleSheet.cssText = result.css; - } else { - style.innerHTML = result.css; - } + style.innerHTML = result.css; } - }, null, style)); + } + }); } } } From 9c56e20c59cc71248d11fd27194820c0f45d5df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Sat, 1 Apr 2023 00:08:38 +0200 Subject: [PATCH 2/3] lint fix --- packages/less/src/less-browser/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/less/src/less-browser/index.js b/packages/less/src/less-browser/index.js index 647037c0e..6a8b78560 100644 --- a/packages/less/src/less-browser/index.js +++ b/packages/less/src/less-browser/index.js @@ -58,7 +58,7 @@ export default (window, options) => { const instanceOptions = { ...options, modifyVars, - filename: document.location.href.replace(/#.*$/, ''), + filename: document.location.href.replace(/#.*$/, '') } const lessText = style.innerHTML || ''; From 8e00808e3e3a6ca88d9817346325269ea3d695a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20W=C3=A4rting?= Date: Sat, 1 Apr 2023 19:31:09 +0200 Subject: [PATCH 3/3] use deep clone --- packages/less/src/less-browser/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/less/src/less-browser/index.js b/packages/less/src/less-browser/index.js index 6a8b78560..0b0ac8768 100644 --- a/packages/less/src/less-browser/index.js +++ b/packages/less/src/less-browser/index.js @@ -56,7 +56,7 @@ export default (window, options) => { for (let style of styles) { if (style.type.match(typePattern)) { const instanceOptions = { - ...options, + ...clone(options), modifyVars, filename: document.location.href.replace(/#.*$/, '') }