better error message when import missing a semi-colon or malformed.

This commit is contained in:
Luke Page
2014-07-27 20:47:19 +01:00
parent 9fab6160a0
commit 1e04f3364d
2 changed files with 17 additions and 12 deletions

View File

@@ -225,7 +225,7 @@ less.Parser = function Parser(env) {
return oldi !== i || oldj !== j;
}
function expect(arg, msg) {
function expect(arg, msg, index) {
// some older browsers return typeof 'function' for RegExp
var result = (Object.prototype.toString.call(arg) === '[object Function]') ? arg.call(parsers) : $(arg);
if (result) {
@@ -1611,7 +1611,7 @@ less.Parser = function Parser(env) {
//
// @import "lib";
//
// Depending on our environemnt, importing is done differently:
// Depending on our environment, importing is done differently:
// In the browser, it's an XHR request, in Node, it would be a
// file-system operation. The function used for importing is
// stored in `import`, which we pass to the Import constructor.
@@ -1619,22 +1619,27 @@ less.Parser = function Parser(env) {
"import": function () {
var path, features, index = i;
save();
var dir = $re(/^@import?\s+/);
var options = (dir ? this.importOptions() : null) || {};
if (dir) {
var options = (dir ? this.importOptions() : null) || {};
if (dir && (path = this.entities.quoted() || this.entities.url())) {
features = this.mediaFeatures();
if ($char(';')) {
forget();
if ((path = this.entities.quoted() || this.entities.url())) {
features = this.mediaFeatures();
if (!$(';')) {
i = index;
error("missing semi-colon or unrecognised media features on import");
}
features = features && new(tree.Value)(features);
return new(tree.Import)(path, features, options, index, env.currentFileInfo);
}
else
{
i = index;
error("malformed import statement");
}
}
restore();
},
importOptions: function() {

View File

@@ -1,2 +1,2 @@
ParseError: Unrecognised input in {path}import-no-semi.less on line 1, column 1:
SyntaxError: missing semi-colon or unrecognised media features on import in {path}import-no-semi.less on line 1, column 1:
1 @import "this-statement-is-invalid.less"