add option to disable javascript. Fixes #688

This commit is contained in:
Luke Page
2013-07-01 10:43:14 +01:00
parent 308bfe2e2b
commit 98f2fef2df
10 changed files with 56 additions and 26 deletions

View File

@@ -12,6 +12,7 @@
'compress', // option - whether to compress
'processImports', // option - whether to process imports. if false then imports will not be imported
'syncImport', // option - whether to import synchronously
'javascriptEnabled',// option - whether JavaScript is enabled. if undefined, defaults to true
'mime', // browser only - mime type for sheet import
'useFileCache', // browser only - whether to use the per file session cache
'currentFileInfo' // information about the current file - for error reporting and importing and making urls relative etc.

View File

@@ -33,6 +33,7 @@ var lessc_helper = {
sys.puts(" -M, --depends Output a makefile import dependency list to stdout");
sys.puts(" --no-color Disable colorized output.");
sys.puts(" --no-ie-compat Disable IE compatibility checks.");
sys.puts(" --no-js Disable JavaScript in less files");
sys.puts(" -l, --lint Syntax check only (lint).");
sys.puts(" -s, --silent Suppress output of error messages.");
sys.puts(" --strict-imports Force evaluation of imports.");
@@ -63,9 +64,7 @@ var lessc_helper = {
sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
sys.puts("Home page: <http://lesscss.org/>");
}
}
};
// Exports helper functions
for (var h in lessc_helper) { exports[h] = lessc_helper[h] }

View File

@@ -790,10 +790,13 @@ less.Parser = function Parser(env) {
javascript: function () {
var str, j = i, e;
if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
if (input.charAt(j) !== '`') { return }
if (input.charAt(j) === '~') { j++; e = true; } // Escaped strings
if (input.charAt(j) !== '`') { return; }
if (env.javascriptEnabled !== undefined && !env.javascriptEnabled) {
error("You are using JavaScript, which has been disabled.");
}
e && $('~');
if (e) { $('~'); }
if (str = $(/^`([^`]*)`/)) {
return new(tree.JavaScript)(str[1], i, e);