Comparing version 0.11.11 to 0.11.12
0.11.12 / 2011-04-27 | ||
================== | ||
* Added `SyntaxError` and `ParseError` | ||
* Removed `stylus.parse()` | ||
* Fixed error reporting. Closes #44 | ||
0.11.11 / 2011-04-24 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -13,3 +13,4 @@ | ||
var Token = require('./token') | ||
, nodes = require('./nodes'); | ||
, nodes = require('./nodes') | ||
, errors = require('./errors'); | ||
@@ -70,3 +71,3 @@ /** | ||
this.indentRe = null; | ||
this.lineno = 0; | ||
this.lineno = 1; | ||
}; | ||
@@ -134,6 +135,9 @@ | ||
case 'newline': | ||
case 'selector': | ||
case 'indent': | ||
++this.lineno; | ||
break; | ||
case 'outdent': | ||
if ('outdent' != this.prev.type) ++this.lineno; | ||
} | ||
this.prev = tok; | ||
tok.lineno = this.lineno; | ||
@@ -556,3 +560,3 @@ return tok; | ||
if (this.str[0] === ' ' || this.str[0] === '\t') { | ||
throw new Error('Invalid indentation, you can use tabs or spaces to indent but not both'); | ||
throw new errors.SyntaxError('Invalid indentation, you can use tabs or spaces to indent but not both'); | ||
} | ||
@@ -559,0 +563,0 @@ |
@@ -51,4 +51,5 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
if (this.val) clone.val = this.val.clone(); | ||
return clone; | ||
}; |
@@ -71,2 +71,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
clone.scope = this.scope; | ||
@@ -73,0 +74,0 @@ this.nodes.forEach(function(node){ |
@@ -44,2 +44,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -46,0 +47,0 @@ }; |
@@ -54,3 +54,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -83,2 +83,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
for (var i = 0; i < this.nodes.length; ++i) { | ||
@@ -85,0 +86,0 @@ clone.push(this.nodes[i].clone()); |
@@ -78,2 +78,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -80,0 +81,0 @@ }; |
@@ -76,4 +76,5 @@ | ||
}); | ||
clone.filename = this.filename; | ||
clone.block = this.block.clone(); | ||
return clone; | ||
}; |
@@ -69,2 +69,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -71,0 +72,0 @@ }; |
@@ -68,2 +68,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -70,0 +71,0 @@ }; |
@@ -53,3 +53,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -25,3 +25,2 @@ | ||
Object.defineProperty(this, 'filename', { writable: true, value: nodes.filename }); | ||
Object.defineProperty(this, 'source', { writable: true, value: nodes.source }); | ||
}; | ||
@@ -28,0 +27,0 @@ |
@@ -66,2 +66,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
this.nodes.forEach(function(node){ | ||
@@ -68,0 +69,0 @@ clone.push(node.clone()); |
@@ -44,2 +44,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
this.segments = this.segments.map(function(node){ return node.clone(); }); | ||
@@ -46,0 +47,0 @@ if (this.expr) clone.expr = this.expr.clone(); |
@@ -42,3 +42,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -75,2 +75,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -77,0 +78,0 @@ }; |
@@ -54,3 +54,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -57,2 +57,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -59,0 +60,0 @@ }; |
@@ -49,3 +49,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -44,3 +44,4 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; |
@@ -72,2 +72,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
@@ -74,0 +75,0 @@ }; |
@@ -15,3 +15,4 @@ | ||
, Token = require('./token') | ||
, inspect = require('sys').inspect; | ||
, inspect = require('sys').inspect | ||
, errors = require('./errors'); | ||
@@ -89,3 +90,2 @@ /** | ||
options = options || {}; | ||
this.str = nodes.source = str; | ||
this.lexer = new Lexer(str, options); | ||
@@ -155,3 +155,3 @@ this.root = options.root || new nodes.Root; | ||
if (val.trim() == type.trim()) val = ''; | ||
throw new Error(msg.replace('{peek}', type + val)); | ||
throw new errors.ParseError(msg.replace('{peek}', type + val)); | ||
}, | ||
@@ -184,3 +184,3 @@ | ||
if (type != this.peek().type) { | ||
throw new Error('expected ' + type + ', got ' + this.peek()); | ||
throw new errors.ParseError('expected ' + type + ', got ' + this.peek()); | ||
} | ||
@@ -681,3 +681,3 @@ return this.next(); | ||
default: | ||
throw new Error('invalid ident "' + pos.val.name + '" in selector'); | ||
throw new errors.ParseError('invalid ident "' + pos.val.name + '" in selector'); | ||
} | ||
@@ -1190,3 +1190,3 @@ } else { | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
if (!node) throw new errors.ParseError('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.equality()); | ||
@@ -1207,3 +1207,3 @@ this.operand = false; | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
if (!node) throw new errors.ParseError('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.in()); | ||
@@ -1223,3 +1223,3 @@ this.operand = false; | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary in'); | ||
if (!node) throw new errors.ParseError('illegal unary in'); | ||
node = new nodes.BinOp('in', node, this.relational()); | ||
@@ -1245,3 +1245,3 @@ this.operand = false; | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
if (!node) throw new errors.ParseError('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.range()); | ||
@@ -1262,3 +1262,3 @@ this.operand = false; | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
if (!node) throw new errors.ParseError('illegal unary ' + op); | ||
node = new nodes.BinOp(op.val, node, this.additive()); | ||
@@ -1303,3 +1303,3 @@ this.operand = false; | ||
} else { | ||
if (!node) throw new Error('illegal unary ' + op); | ||
if (!node) throw new errors.ParseError('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.defined()); | ||
@@ -1320,3 +1320,3 @@ this.operand = false; | ||
if (this.accept('is defined')) { | ||
if (!node) throw new Error('illegal use of "is defined"'); | ||
if (!node) throw new errors.ParseError('illegal use of "is defined"'); | ||
node = new nodes.BinOp('is defined', node); | ||
@@ -1323,0 +1323,0 @@ } |
@@ -31,7 +31,6 @@ | ||
options.imports = [__dirname + '/functions']; | ||
options.paths = options.paths || []; | ||
options.filename = options.filename || 'stylus'; | ||
options.paths = options.paths || []; | ||
this.options = options; | ||
this.str = str; | ||
this.options = options; | ||
this.parser = new Parser(str, options); | ||
}; | ||
@@ -47,5 +46,6 @@ | ||
Renderer.prototype.render = function(fn){ | ||
var parser = this.parser = new Parser(this.str, this.options); | ||
try { | ||
var ast = this.parser.parse() | ||
, expr; | ||
nodes.filename = this.options.filename; | ||
var ast = parser.parse(); | ||
this.evaluator = new Evaluator(ast, this.options); | ||
@@ -55,8 +55,8 @@ ast = this.evaluator.evaluate(); | ||
} catch (err) { | ||
fn(utils.formatException( | ||
this | ||
, err | ||
, this.options)); | ||
var options = {}; | ||
options.input = err.input || this.str; | ||
options.filename = err.filename || this.options.filename; | ||
options.lineno = err.lineno || parser.lexer.lineno; | ||
fn(utils.formatException(err, options)); | ||
} | ||
nodes.source = null; | ||
}; | ||
@@ -63,0 +63,0 @@ |
@@ -133,3 +133,3 @@ | ||
if (node = block.node) { | ||
location = '(' + node.filename + ':' + node.lineno + ')'; | ||
location = '(' + node.filename + ':' + (node.lineno + 1) + ')'; | ||
switch (node.nodeName) { | ||
@@ -136,0 +136,0 @@ case 'function': |
@@ -13,2 +13,3 @@ | ||
var Renderer = require('./renderer') | ||
, Parser = require('./parser') | ||
, nodes = require('./nodes') | ||
@@ -27,3 +28,3 @@ , utils = require('./utils'); | ||
exports.version = '0.11.11'; | ||
exports.version = '0.11.12'; | ||
@@ -73,34 +74,2 @@ /** | ||
/** | ||
* Parse the given `str` with `options` and return the AST. | ||
* | ||
* Examples: | ||
* | ||
* css.parse(str); | ||
* // raw ast comprised of nodes | ||
* | ||
* css.parse(str).toObject(); | ||
* // plain object representation | ||
* | ||
* css.parse(str).toJSON(); | ||
* // JSON representation | ||
* | ||
* @param {String} str | ||
* @param {Object} options | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
exports.parse = function(str, options){ | ||
var renderer = new Renderer(str, options); | ||
try { | ||
return renderer.parser.parse(); | ||
} catch (err) { | ||
throw utils.formatException( | ||
renderer | ||
, err | ||
, options); | ||
} | ||
}; | ||
/** | ||
* Render the given `str` with `options` and callback `fn(err, css)`. | ||
@@ -107,0 +76,0 @@ * |
@@ -13,3 +13,2 @@ | ||
var nodes = require('./nodes') | ||
, inspect = require('sys').inspect | ||
, fs = require('fs'); | ||
@@ -59,5 +58,11 @@ | ||
/** | ||
* Format the given `err` in context to `renderer`. | ||
* Format the given `err` with the given `options`. | ||
* | ||
* @param {Renderer} renderer | ||
* Options: | ||
* | ||
* - `filename` context filename | ||
* - `context` context line count [8] | ||
* - `lineno` context line number | ||
* - `input` input string | ||
* | ||
* @param {Error} err | ||
@@ -69,22 +74,23 @@ * @param {Object} options | ||
exports.formatException = function(renderer, err, options){ | ||
var lineno = renderer.evaluator | ||
? renderer.evaluator.lineno | ||
: renderer.parser.lexer.lineno | ||
, contextLineno = lineno - 2 | ||
, contextLines = options.context || 8 | ||
, lastWidth = (contextLineno + contextLines).toString().length; | ||
exports.formatException = function(err, options){ | ||
var lineno = options.lineno | ||
, filename = options.filename | ||
, str = options.input | ||
, context = options.context || 8 | ||
, context = context /2 | ||
, lines = ('\n' + str).split('\n') | ||
, start = Math.max(lineno - context, 0) | ||
, end = Math.min(lines.length, lineno + context); | ||
var src = (err.str || renderer.str).split('\n') | ||
.slice(contextLineno, contextLineno + contextLines) | ||
.map(function(line){ | ||
var n = ++contextLineno | ||
, width = n.toString().length | ||
, pad = Array(lastWidth - width + 1).join(' '); | ||
return ' ' + pad + n + ': ' + inspect(line); | ||
}).join('\n'); | ||
var context = lines.slice(start, end).map(function(line, i){ | ||
var curr = i + start; | ||
return (curr == lineno ? ' > ' : ' ') | ||
+ curr | ||
+ '| ' | ||
+ line; | ||
}).join('\n'); | ||
err.message = renderer.options.filename | ||
err.message = filename | ||
+ ':' + lineno | ||
+ '\n' + src | ||
+ '\n' + context | ||
+ '\n\n' + err.message + '\n' | ||
@@ -206,1 +212,15 @@ + (err.stylusStack ? err.stylusStack + '\n' : ''); | ||
}; | ||
/** | ||
* Merge object `b` with `a`. | ||
* | ||
* @param {Object} a | ||
* @param {Object} b | ||
* @return {Object} a | ||
* @api private | ||
*/ | ||
exports.merge = function(a, b){ | ||
for (var k in b) a[k] = b[k]; | ||
return a; | ||
} |
@@ -50,2 +50,3 @@ | ||
this.calling = []; // TODO: remove, use stack | ||
this.importStack = []; | ||
}; | ||
@@ -72,7 +73,11 @@ | ||
} catch (err) { | ||
// TODO: less-lame hack to reference | ||
// the origin node source input | ||
this.lineno = this.lineno || node.lineno; | ||
err.str = err.str || node.source; | ||
err.stylusStack = err.stylusStack || this.stack.toString(); | ||
if (err.filename) throw err; | ||
err.lineno = node.lineno; | ||
err.filename = node.filename; | ||
err.stylusStack = this.stack.toString(); | ||
try { | ||
err.input = fs.readFileSync(err.filename, 'utf8'); | ||
} catch (err) { | ||
// ignore | ||
} | ||
throw err; | ||
@@ -522,3 +527,3 @@ } | ||
, root = this.root | ||
, stylus = require('../stylus') | ||
, Parser = require('../parser') | ||
, path = this.visit(import.path).first; | ||
@@ -548,6 +553,18 @@ | ||
// Parse the file | ||
this.importStack.push(found); | ||
nodes.filename = found; | ||
var str = fs.readFileSync(found, 'utf8') | ||
, block = new nodes.Block | ||
, block = stylus.parse(str, { filename: found, root: block }); | ||
, parser = new Parser(str, utils.merge({ root: block }, this.options)); | ||
try { | ||
block = parser.parse(); | ||
} catch (err) { | ||
err.filename = found; | ||
err.lineno = parser.lexer.lineno; | ||
err.input = str; | ||
throw err; | ||
} | ||
// Evaluate imported "root" | ||
@@ -558,2 +575,3 @@ block.parent = root; | ||
this.paths.pop(); | ||
this.importStack.pop(); | ||
@@ -560,0 +578,0 @@ return ret; |
{ "name": "stylus" | ||
, "description": "Robust, expressive, and feature-rich CSS superset" | ||
, "version": "0.11.11" | ||
, "version": "0.11.12" | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
@@ -5,0 +5,0 @@ , "keywords": ["css", "parser", "style", "stylesheets", "jade", "language"] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208410
65
7380