diff --git a/lib/less/parser/parser-input.js b/lib/less/parser/parser-input.js index aca272f1..5c799c62 100644 --- a/lib/less/parser/parser-input.js +++ b/lib/less/parser/parser-input.js @@ -211,7 +211,7 @@ module.exports = function() { return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA; }; - parserInput.start = function(str, chunkInput, parser, env) { + parserInput.start = function(str, chunkInput, env) { input = str; parserInput.i = j = currentPos = furthest = 0; @@ -227,12 +227,12 @@ module.exports = function() { // in the case it causes too much performance issues. if (chunkInput) { chunks = chunker(str, function fail(msg, index) { - throw new(LessError)(parser, { + throw new(LessError)({ index: index, type: 'Parse', message: msg, filename: env.currentFileInfo.filename - }, env); + }, env); //TODO works because env contains contents like importManager }); } else { chunks = [str]; diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js index b5e474be..70027d0d 100644 --- a/lib/less/parser/parser.js +++ b/lib/less/parser/parser.js @@ -42,8 +42,7 @@ module.exports = function(environment) { // // var Parser = function Parser(env) { - var parser, - parsers, + var parsers, parserInput = getParserInput(); // Top parser on an import tree must be sure there is one "env" @@ -73,10 +72,15 @@ var Parser = function Parser(env) { } function error(msg, type) { - var e = new Error(msg); - e.index = parserInput.i; - e.type = type || 'Syntax'; - throw e; + throw new LessError( + { + index: parserInput.i, + filename: env.currentFileInfo.filename, + type: type || 'Syntax', + message: msg + }, + imports + ); } function getDebugInfo(index) { @@ -92,9 +96,8 @@ var Parser = function Parser(env) { // // The Parser // - parser = { + return { - imports: imports, // // Parse an input string into an abstract syntax tree, // @param str A string containing 'less' markup @@ -122,7 +125,7 @@ var Parser = function Parser(env) { // with the `root` property set to true, so no `{}` are // output. The callback is called when the input is parsed. try { - parserInput.start(str, env.chunkInput, parser, env); + parserInput.start(str, env.chunkInput, env); root = new(tree.Ruleset)(null, this.parsers.primary()); root.root = true; @@ -618,7 +621,7 @@ var Parser = function Parser(env) { parserInput.restore(); }, args: function (isCall) { - var parsers = parser.parsers, entities = parsers.entities, + var entities = parsers.entities, returner = { args:null, variadic: false }, expressions = [], argsSemiColon = [], argsComma = [], isSemiColonSeperated, expressionContainsNamed, name, nameLoop, value, arg; @@ -1583,8 +1586,6 @@ var Parser = function Parser(env) { } } }; - - return parser; }; Parser.serializeVars = function(vars) { var s = '';