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

feat: add disablePlugins flag for render() options #3701

Merged
merged 7 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ const Parser = function Parser(context, imports, fileInfo) {
//
parse: function (str, callback, additionalData) {
let root;
let error = null;
let err = null;
Copy link
Contributor Author

@broofa broofa Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Had to rename this, as it was shadowing the error function.

let globalVars;
let modifyVars;
let ignored;
let preText = '';

// Optionally disable @plugin parsing
if (additionalData && additionalData.disablePlugins) {
parsers.plugin = function() {
var dir = parserInput.$re(/^@plugin?\s+/);
if (dir) {
error('@plugin not supported');
}
}
};

globalVars = (additionalData && additionalData.globalVars) ? `${Parser.serializeVars(additionalData.globalVars)}\n` : '';
modifyVars = (additionalData && additionalData.modifyVars) ? `\n${Parser.serializeVars(additionalData.modifyVars)}` : '';

Expand Down Expand Up @@ -226,7 +236,7 @@ const Parser = function Parser(context, imports, fileInfo) {
}
}

error = new LessError({
err = new LessError({
type: 'Parse',
message,
index: endInfo.furthest,
Expand All @@ -235,7 +245,7 @@ const Parser = function Parser(context, imports, fileInfo) {
}

const finish = e => {
e = error || e || imports.error;
e = err || e || imports.error;

if (e) {
if (!(e instanceof LessError)) {
Expand Down
1 change: 1 addition & 0 deletions packages/less/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ lessTester.testSyncronous({syncImport: true}, '_main/import');
lessTester.testSyncronous({syncImport: true}, '_main/plugin');
lessTester.testSyncronous({syncImport: true}, 'math/strict/css');
lessTester.testNoOptions();
lessTester.testDisablePlugins();
lessTester.testJSImport();
lessTester.finished();

Expand Down
16 changes: 16 additions & 0 deletions packages/less/test/less-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,21 @@ module.exports = function() {
};
}

function testDisablePlugins() {
less.render(
'@plugin "../../plugin/some_plugin";',
{disablePlugins: true},
function(err) {
const EXPECTED = '@plugin not supported';
if (!err || String(err).indexOf(EXPECTED) < 0) {
fail('ERROR: Expected "' + EXPECTED + '" error');
return;
}
ok(stylize('OK\n', 'green'));
}
);
}

return {
runTestSet: runTestSet,
runTestSetNormalOnly: runTestSetNormalOnly,
Expand All @@ -575,6 +590,7 @@ module.exports = function() {
testImportRedirect: testImportRedirect,
testEmptySourcemap: testEmptySourcemap,
testNoOptions: testNoOptions,
testDisablePlugins: testDisablePlugins,
testJSImport: testJSImport,
finished: finished
};
Expand Down