Comparing version 0.47.3 to 0.48.0
@@ -156,2 +156,3 @@ | ||
, yellowgreen: [154, 205, 50] | ||
}; | ||
, rebeccapurple: [102, 51, 153] | ||
}; |
113
lib/lexer.js
@@ -62,13 +62,28 @@ | ||
this.lineno = 1; | ||
this.column = 1; | ||
// HACK! | ||
function comment(str, val, offset, s) { | ||
var commentIdx = s.lastIndexOf('//', offset) | ||
, inComment = s.lastIndexOf('/*', offset) > s.lastIndexOf('*/', offset) | ||
|| (~commentIdx && commentIdx > s.lastIndexOf('\n', offset) | ||
&& commentIdx > s.lastIndexOf("'", offset) | ||
&& commentIdx > s.lastIndexOf('"', offset)); | ||
var inComment = s.lastIndexOf('/*', offset) > s.lastIndexOf('*/', offset) | ||
, commentIdx = s.lastIndexOf('//', offset) | ||
, i = s.lastIndexOf('\n', offset) | ||
, double = 0 | ||
, single = 0; | ||
if (~commentIdx && commentIdx > i) { | ||
while (i != offset) { | ||
if ("'" == s[i]) single ? single-- : single++; | ||
if ('"' == s[i]) double ? double-- : double++; | ||
if ('/' == s[i] && '/' == s[i + 1]) { | ||
inComment = !single && !double; | ||
break; | ||
} | ||
++i; | ||
} | ||
} | ||
return inComment | ||
? str | ||
: val + '\u0085'; | ||
: val + '\r'; | ||
}; | ||
@@ -81,5 +96,5 @@ | ||
.replace(/\s+$/, '\n') | ||
.replace(/\\ *\n/g, '\u0085') | ||
.replace(/\r\n?/g, '\n') | ||
.replace(/((?:[,(]|:)(?!\/\/[^ ])) *(?:\/\/[^\n]*)?\n\s*/g, comment) | ||
.replace(/\\ *\n/g, '\r') | ||
.replace(/([,(:](?!\/\/[^ ])) *(?:\/\/[^\n]*)?\n\s*/g, comment) | ||
.replace(/\s*\n[ \t]*([,)])/g, comment); | ||
@@ -131,8 +146,30 @@ }; | ||
skip: function(len){ | ||
this.str = this.str.substr(Array.isArray(len) | ||
? len[0].length | ||
: len); | ||
var chunk = len[0]; | ||
len = chunk ? chunk.length : len; | ||
this.str = this.str.substr(len); | ||
if (chunk) { | ||
this.move(chunk); | ||
} else { | ||
this.column += len; | ||
} | ||
}, | ||
/** | ||
* Move current line and column position. | ||
* | ||
* @param {String} str | ||
* @api private | ||
*/ | ||
move: function(str){ | ||
var lines = str.match(/\n/g) | ||
, idx = str.lastIndexOf('\n'); | ||
if (lines) this.lineno += lines.length; | ||
this.column = ~idx | ||
? str.length - idx | ||
: this.column + str.length; | ||
}, | ||
/** | ||
* Fetch next token including those stashed by peek. | ||
@@ -146,13 +183,3 @@ * | ||
var tok = this.stashed() || this.advance(); | ||
switch (tok.type) { | ||
case 'newline': | ||
case 'indent': | ||
++this.lineno; | ||
break; | ||
case 'outdent': | ||
if ('outdent' != this.prev.type) ++this.lineno; | ||
} | ||
this.prev = tok; | ||
tok.lineno = this.lineno; | ||
return tok; | ||
@@ -191,3 +218,5 @@ }, | ||
advance: function() { | ||
return this.eos() | ||
var column = this.column | ||
, line = this.lineno | ||
, tok = this.eos() | ||
|| this.null() | ||
@@ -211,2 +240,3 @@ || this.sep() | ||
|| this.boolean() | ||
|| this.unicode() | ||
|| this.ident() | ||
@@ -217,2 +247,5 @@ || this.op() | ||
|| this.selector(); | ||
tok.lineno = line; | ||
tok.column = column; | ||
return tok; | ||
}, | ||
@@ -282,7 +315,7 @@ | ||
/** | ||
* '\u0085' | ||
* '\r' | ||
*/ | ||
eol: function() { | ||
if ('\u0085' == this.str[0]) { | ||
if ('\r' == this.str[0]) { | ||
++this.lineno; | ||
@@ -330,3 +363,4 @@ this.skip(1); | ||
, braces = 1 | ||
, css = ''; | ||
, css = '' | ||
, node; | ||
while (c = this.str[0]) { | ||
@@ -343,3 +377,5 @@ this.str = this.str.substr(1); | ||
css = css.replace(/\s*}$/, ''); | ||
return new Token('literal', new nodes.Literal(css)); | ||
node = new nodes.Literal(css); | ||
node.css = true; | ||
return new Token('literal', node); | ||
} | ||
@@ -458,3 +494,3 @@ }, | ||
}, | ||
/** | ||
@@ -567,3 +603,4 @@ * ',' | ||
, lines = str.split('\n').length - 1 | ||
, suppress = true; | ||
, suppress = true | ||
, inline = false; | ||
this.lineno += lines; | ||
@@ -576,3 +613,4 @@ this.skip(end + 2); | ||
} | ||
return new Token('comment', new nodes.Comment(str, suppress)); | ||
if (this.prev && ';' == this.prev.type) inline = true; | ||
return new Token('comment', new nodes.Comment(str, suppress, inline)); | ||
} | ||
@@ -597,2 +635,14 @@ }, | ||
/** | ||
* 'U+' [0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})? | ||
*/ | ||
unicode: function() { | ||
var captures; | ||
if (captures = /^u\+[0-9a-f?]{1,6}(?:-[0-9a-f]{1,6})?/i.exec(this.str)) { | ||
this.skip(captures); | ||
return new Token('literal', new nodes.Literal(captures[0])); | ||
} | ||
}, | ||
/** | ||
* -*[_a-zA-Z$] [-\w\d$]* '(' | ||
@@ -662,6 +712,3 @@ */ | ||
// Blank line | ||
if ('\n' == this.str[0]) { | ||
++this.lineno; | ||
return this.advance(); | ||
} | ||
if ('\n' == this.str[0]) return this.advance(); | ||
@@ -668,0 +715,0 @@ // Outdent |
@@ -44,2 +44,3 @@ /*! | ||
* the corresponding Stylus line | ||
* 'sourcemap' Generates a sourcemap in sourcemaps v3 format | ||
* | ||
@@ -101,2 +102,9 @@ * Examples: | ||
options.compile = options.compile || function(str, path){ | ||
// inline sourcemap | ||
if (options.sourcemap) { | ||
if ('boolean' == typeof options.sourcemap) | ||
options.sourcemap = {}; | ||
options.sourcemap.inline = true; | ||
} | ||
return stylus(str) | ||
@@ -106,3 +114,4 @@ .set('filename', path) | ||
.set('firebug', options.firebug) | ||
.set('linenos', options.linenos); | ||
.set('linenos', options.linenos) | ||
.set('sourcemap', options.sourcemap); | ||
}; | ||
@@ -109,0 +118,0 @@ |
@@ -46,2 +46,3 @@ | ||
args.lineno = expr.lineno; | ||
args.column = expr.column; | ||
args.isList = expr.isList; | ||
@@ -68,2 +69,3 @@ for (var i = 0; i < len; ++i) { | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -87,2 +89,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename, | ||
@@ -89,0 +92,0 @@ nodes: this.nodes |
@@ -48,2 +48,3 @@ /*! | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -76,4 +77,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
fileno: this.fileno | ||
}; | ||
}; |
@@ -66,2 +66,3 @@ /*! | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -84,2 +85,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -86,0 +88,0 @@ }; |
@@ -48,2 +48,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -78,2 +79,3 @@ if (this.val) clone.val = this.val.clone(parent, clone); | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -80,0 +82,0 @@ }; |
@@ -89,2 +89,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -123,2 +124,3 @@ clone.scope = this.scope; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename, | ||
@@ -125,0 +127,0 @@ nodes: this.nodes |
@@ -46,2 +46,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -80,2 +81,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -82,0 +84,0 @@ }; |
@@ -56,4 +56,5 @@ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -19,9 +19,11 @@ | ||
* @param {Boolean} suppress | ||
* @param {Boolean} inline | ||
* @api public | ||
*/ | ||
var Comment = module.exports = function Comment(str, suppress){ | ||
var Comment = module.exports = function Comment(str, suppress, inline){ | ||
Node.call(this); | ||
this.str = str; | ||
this.suppress = suppress; | ||
this.inline = inline; | ||
}; | ||
@@ -47,3 +49,5 @@ | ||
suppress: this.suppress, | ||
inline: this.inline, | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -50,0 +54,0 @@ }; |
@@ -52,2 +52,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -72,4 +73,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -83,2 +83,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -216,2 +217,3 @@ clone.nodes = this.nodes.map(function(node) { | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename, | ||
@@ -218,0 +220,0 @@ nodes: this.nodes |
@@ -66,4 +66,5 @@ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -77,2 +77,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -118,2 +119,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -120,0 +122,0 @@ }; |
@@ -85,2 +85,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
this.nodes.forEach(function(node){ | ||
@@ -107,4 +108,5 @@ clone.push(node.clone(parent, clone)); | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -50,4 +50,4 @@ | ||
+ this.h + ',' | ||
+ this.s.toFixed(0) + ',' | ||
+ this.l.toFixed(0) + ',' | ||
+ this.s.toFixed(0) + '%,' | ||
+ this.l.toFixed(0) + '%,' | ||
+ this.a + ')'; | ||
@@ -70,2 +70,3 @@ }; | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -90,2 +91,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -92,0 +94,0 @@ }; |
@@ -71,2 +71,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -94,2 +95,3 @@ clone.property = this.property; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -96,0 +98,0 @@ }; |
@@ -54,2 +54,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -75,4 +76,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -46,2 +46,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -65,4 +66,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -45,2 +45,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -67,2 +68,3 @@ clone.segments = this.segments.map(function(node) { return node.clone(parent, clone); }); | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -69,0 +71,0 @@ }; |
@@ -109,4 +109,5 @@ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -45,2 +45,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -63,2 +64,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -65,0 +67,0 @@ }; |
@@ -47,2 +47,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -65,2 +66,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -67,0 +69,0 @@ }; |
@@ -57,4 +57,5 @@ /*! | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -42,3 +42,4 @@ | ||
var Node = module.exports = function Node(){ | ||
this.lineno = nodes.lineno; | ||
this.lineno = nodes.lineno || 1; | ||
this.column = nodes.column || 1; | ||
this.filename = nodes.filename; | ||
@@ -104,2 +105,3 @@ }; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -106,0 +108,0 @@ }; |
@@ -85,4 +85,5 @@ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -133,3 +133,3 @@ | ||
default: | ||
str += key + ':' + val.toString() + ';'; | ||
str += key + ':' + val.toString().replace(/ , /g, '\\,') + ';'; | ||
} | ||
@@ -152,2 +152,3 @@ } | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -172,2 +173,3 @@ for (var key in this.vals) { | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -174,0 +176,0 @@ }; |
@@ -66,2 +66,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -86,2 +87,3 @@ this.nodes.forEach(function(node){ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -88,0 +90,0 @@ }; |
@@ -46,2 +46,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -66,2 +67,3 @@ clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); }); | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -68,0 +70,0 @@ }; |
@@ -46,2 +46,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -78,2 +79,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -80,0 +82,0 @@ }; |
@@ -41,2 +41,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -105,4 +106,5 @@ for (var i = 0; i < this.nodes.length; ++i) { | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -48,2 +48,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -167,4 +168,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -43,2 +43,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -60,4 +61,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -78,2 +78,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -99,2 +100,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -101,0 +103,0 @@ }; |
@@ -62,2 +62,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -93,4 +94,5 @@ this.nodes.forEach(function(node){ | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -66,2 +66,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -88,4 +89,5 @@ clone.inherits = this.inherits; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -63,2 +63,3 @@ /*! | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -81,2 +82,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -83,0 +85,0 @@ }; |
@@ -49,2 +49,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -68,4 +69,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -45,2 +45,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -63,4 +64,5 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
}; | ||
}; |
@@ -87,2 +87,3 @@ | ||
clone.lineno = this.lineno; | ||
clone.column = this.column; | ||
clone.filename = this.filename; | ||
@@ -105,2 +106,3 @@ return clone; | ||
lineno: this.lineno, | ||
column: this.column, | ||
filename: this.filename | ||
@@ -131,3 +133,3 @@ }; | ||
// percentages | ||
if (('-' == op || '+' == op) && '%' == right.type) { | ||
if ('%' != this.type && ('-' == op || '+' == op) && '%' == right.type) { | ||
right = new Unit(this.val * (right.val / 100), '%'); | ||
@@ -134,0 +136,0 @@ } else { |
@@ -300,4 +300,12 @@ /*! | ||
? this.stash.pop() | ||
: this.lexer.next(); | ||
nodes.lineno = tok.lineno; | ||
: this.lexer.next() | ||
, line = tok.lineno | ||
, column = tok.column || 1; | ||
if (tok.val && tok.val.nodeName) { | ||
tok.val.lineno = line; | ||
tok.val.column = column; | ||
} | ||
nodes.lineno = line; | ||
nodes.column = column; | ||
debug.lexer('%s %s', tok.type, tok.val || ''); | ||
@@ -983,4 +991,5 @@ return tok; | ||
extend: function(){ | ||
this.expect('extend'); | ||
var selectors = [] | ||
var tok = this.expect('extend') | ||
, selectors = [] | ||
, node | ||
, arr; | ||
@@ -993,3 +1002,6 @@ | ||
return new nodes.Extend(selectors); | ||
node = new nodes.Extend(selectors); | ||
node.lineno = tok.lineno; | ||
node.column = tok.column; | ||
return node; | ||
}, | ||
@@ -1391,3 +1403,4 @@ | ||
, scope = this.selectorScope | ||
, isRoot = 'root' == this.currentState(); | ||
, isRoot = 'root' == this.currentState() | ||
, selector; | ||
@@ -1402,3 +1415,8 @@ do { | ||
if (isRoot && scope) arr.unshift(new nodes.Literal(scope + ' ')); | ||
if (arr.length) group.push(new nodes.Selector(arr)); | ||
if (arr.length) { | ||
selector = new nodes.Selector(arr); | ||
selector.lineno = arr[0].lineno; | ||
selector.column = arr[0].column; | ||
group.push(selector); | ||
} | ||
} while (this.accept(',') || this.accept('newline')); | ||
@@ -1684,2 +1702,6 @@ | ||
this.state.pop(); | ||
if (expr.nodes.length) { | ||
expr.lineno = expr.nodes[0].lineno; | ||
expr.column = expr.nodes[0].column; | ||
} | ||
return expr; | ||
@@ -1686,0 +1708,0 @@ }, |
@@ -14,3 +14,2 @@ | ||
, EventEmitter = require('events').EventEmitter | ||
, Compiler = require('./visitor/compiler') | ||
, Evaluator = require('./visitor/evaluator') | ||
@@ -39,4 +38,4 @@ , Normalizer = require('./visitor/normalizer') | ||
options = options || {}; | ||
options.globals = {}; | ||
options.functions = {}; | ||
options.globals = options.globals || {}; | ||
options.functions = options.functions || {}; | ||
options.imports = [join(__dirname, 'functions')]; | ||
@@ -88,5 +87,10 @@ options.paths = options.paths || []; | ||
// compile | ||
var compiler = new Compiler(ast, this.options) | ||
var compiler = this.options.sourcemap | ||
? new (require('./visitor/sourcemapper'))(ast, this.options) | ||
: new (require('./visitor/compiler'))(ast, this.options) | ||
, css = compiler.compile(); | ||
// expose sourcemap | ||
if (this.options.sourcemap) this.sourcemap = compiler.map.toJSON(); | ||
var listeners = this.listeners('end'); | ||
@@ -103,3 +107,4 @@ if (fn) listeners.push(fn); | ||
options.filename = err.filename || this.options.filename; | ||
options.lineno = err.lineno || parser.lexer.lineno; | ||
options.lineno = err.lineno || parser.lexer.prev.lineno; | ||
options.column = err.column || parser.lexer.prev.column; | ||
if (!fn) throw utils.formatException(err, options); | ||
@@ -136,3 +141,4 @@ fn(utils.formatException(err, options)); | ||
options.filename = err.filename || this.options.filename; | ||
options.lineno = err.lineno || parser.lexer.lineno; | ||
options.lineno = err.lineno || parser.lexer.prev.lineno; | ||
options.column = err.column || parser.lexer.prev.column; | ||
throw utils.formatException(err, options); | ||
@@ -139,0 +145,0 @@ } |
@@ -106,3 +106,3 @@ | ||
* | ||
* at <context> (<filename>:<lineno>) | ||
* at <context> (<filename>:<lineno>:<column>) | ||
* | ||
@@ -123,3 +123,3 @@ * @return {String} | ||
if (node = block.node) { | ||
location = '(' + node.filename + ':' + (node.lineno + 1) + ')'; | ||
location = '(' + node.filename + ':' + (node.lineno + 1) + ':' + node.column + ')'; | ||
switch (node.nodeName) { | ||
@@ -126,0 +126,0 @@ case 'function': |
@@ -36,3 +36,3 @@ | ||
var val = ' ' + inspect(this.val); | ||
return '[Token:' + this.lineno + ' ' | ||
return '[Token:' + this.lineno + ':' + this.column + ' ' | ||
+ '\x1b[32m' + this.type + '\x1b[0m' | ||
@@ -39,0 +39,0 @@ + '\x1b[33m' + (this.val ? val : '') + '\x1b[0m' |
@@ -151,2 +151,3 @@ | ||
* - `lineno` context line number | ||
* - `column` context column number | ||
* - `input` input string | ||
@@ -162,2 +163,3 @@ * | ||
var lineno = options.lineno | ||
, column = options.column | ||
, filename = options.filename | ||
@@ -174,7 +176,10 @@ , str = options.input | ||
var curr = i + start; | ||
return (curr == lineno ? ' > ' : ' ') | ||
return ' ' | ||
+ Array(pad - curr.toString().length + 1).join(' ') | ||
+ curr | ||
+ '| ' | ||
+ line; | ||
+ line | ||
+ (curr == lineno | ||
? '\n' + Array(curr.toString().length + 5 + column).join('-') + '^' | ||
: ''); | ||
}).join('\n'); | ||
@@ -184,2 +189,3 @@ | ||
+ ':' + lineno | ||
+ ':' + column | ||
+ '\n' + context | ||
@@ -186,0 +192,0 @@ + '\n\n' + err.message + '\n' |
@@ -57,2 +57,15 @@ /*! | ||
/** | ||
* Output `str` | ||
* | ||
* @param {String} str | ||
* @param {Node} node | ||
* @return {String} | ||
* @api private | ||
*/ | ||
Compiler.prototype.out = function(str, node){ | ||
return str; | ||
}; | ||
/** | ||
* Return indentation string. | ||
@@ -93,3 +106,3 @@ * | ||
var ret = this.visit(node); | ||
if (ret) this.buf += ret + '\n'; | ||
if (ret) this.buf += this.out(ret + '\n', node); | ||
} | ||
@@ -105,4 +118,4 @@ return this.buf; | ||
var node | ||
, needBrackets | ||
, arr = []; | ||
, separator = this.compress ? '' : '\n' | ||
, needBrackets; | ||
@@ -113,3 +126,3 @@ if (block.hasProperties && !block.lacksRenderedSelectors) { | ||
if (needBrackets) { | ||
var arr = [this.compress ? '{' : ' {']; | ||
this.buf += this.out(this.compress ? '{' : ' {\n'); | ||
++this.indents; | ||
@@ -130,4 +143,13 @@ } | ||
continue; | ||
// inline comments | ||
case !this.compress && node.inline && 'comment': | ||
this.buf = this.buf.slice(0, -1); | ||
this.buf += this.out(' ' + this.visit(node) + '\n', node); | ||
break; | ||
case 'property': | ||
var ret = this.visit(node) + separator; | ||
this.buf += this.compress ? ret : this.out(ret, node); | ||
break; | ||
default: | ||
arr.push(this.visit(node)); | ||
this.buf += this.out(this.visit(node) + separator, node); | ||
} | ||
@@ -137,6 +159,4 @@ } | ||
--this.indents; | ||
arr.push(this.indent + '}'); | ||
this.buf += this.out(this.indent + '}' + separator); | ||
} | ||
this.buf += arr.join(this.compress ? '' : '\n'); | ||
this.buf += (this.compress ? '' : '\n'); | ||
} | ||
@@ -149,3 +169,2 @@ | ||
case 'group': | ||
case 'print': | ||
case 'block': | ||
@@ -164,7 +183,7 @@ case 'keyframes': | ||
if (!block.scope && !node.suppress) { | ||
this.buf += this.visit(node) + '\n'; | ||
this.buf += this.out(this.visit(node) + '\n', node); | ||
} | ||
break; | ||
case 'literal': | ||
this.buf += this.visit(node) + '\n'; | ||
this.buf += this.out(this.visit(node) + '\n', node); | ||
break; | ||
@@ -186,5 +205,5 @@ } | ||
this.buf += '@' + prefix + 'keyframes ' | ||
this.buf += this.out('@' + prefix + 'keyframes ' | ||
+ this.visit(node.val) | ||
+ (this.compress ? '{' : ' {\n'); | ||
+ (this.compress ? '{' : ' {\n'), node); | ||
@@ -197,3 +216,3 @@ this.keyframe = true; | ||
this.buf += '}' + (this.compress ? '' : '\n'); | ||
this.buf += this.out('}' + (this.compress ? '' : '\n')); | ||
}; | ||
@@ -209,9 +228,9 @@ | ||
this.buf += '@media '; | ||
this.buf += this.out('@media ', media); | ||
this.visit(val); | ||
this.buf += this.compress ? '{' : ' {\n'; | ||
this.buf += this.out(this.compress ? '{' : ' {\n'); | ||
++this.indents; | ||
this.visit(media.block); | ||
--this.indents; | ||
this.buf += '}' + (this.compress ? '' : '\n'); | ||
this.buf += this.out('}' + (this.compress ? '' : '\n')); | ||
}; | ||
@@ -226,3 +245,3 @@ | ||
this.visit(queries.nodes[i]); | ||
if (len - 1 != i) this.buf += ',' + (this.compress ? '' : ' '); | ||
if (len - 1 != i) this.buf += this.out(',' + (this.compress ? '' : ' ')); | ||
} | ||
@@ -237,7 +256,7 @@ }; | ||
var len = node.nodes.length; | ||
if (node.predicate) this.buf += node.predicate + ' '; | ||
if (node.type) this.buf += node.type + (len ? ' and ' : ''); | ||
if (node.predicate) this.buf += this.out(node.predicate + ' '); | ||
if (node.type) this.buf += this.out(node.type + (len ? ' and ' : '')); | ||
for (var i = 0; i < len; ++i) { | ||
this.visit(node.nodes[i]); | ||
if (len - 1 != i) this.buf += ' and '; | ||
if (len - 1 != i) this.buf += this.out(' and '); | ||
} | ||
@@ -252,7 +271,7 @@ }; | ||
if (!node.expr) { | ||
this.buf += node.name; | ||
this.buf += this.out(node.name); | ||
} else if (node.expr.isEmpty) { | ||
this.buf += '(' + node.name + ')'; | ||
this.buf += this.out('(' + node.name + ')'); | ||
} else { | ||
this.buf += '(' + node.name + ':' + (this.compress ? '' : ' ') + this.visit(node.expr) + ')'; | ||
this.buf += this.out('(' + node.name + ':' + (this.compress ? '' : ' ') + this.visit(node.expr) + ')'); | ||
} | ||
@@ -266,3 +285,3 @@ }; | ||
Compiler.prototype.visitImport = function(imported){ | ||
this.buf += '@import ' + this.visit(imported.path) + ';\n'; | ||
this.buf += this.out('@import ' + this.visit(imported.path) + ';\n', imported); | ||
}; | ||
@@ -275,5 +294,5 @@ | ||
Compiler.prototype.visitAtrule = function(atrule){ | ||
this.buf += this.indent + '@' + atrule.type; | ||
this.buf += this.out(this.indent + '@' + atrule.type, atrule); | ||
if (atrule.val) this.buf += ' ' + atrule.val.trim(); | ||
if (atrule.val) this.buf += this.out(' ' + atrule.val.trim()); | ||
@@ -283,7 +302,7 @@ if (atrule.hasOnlyProperties) { | ||
} else { | ||
this.buf += this.compress ? '{' : ' {\n'; | ||
this.buf += this.out(this.compress ? '{' : ' {\n'); | ||
++this.indents; | ||
this.visit(atrule.block); | ||
--this.indents; | ||
this.buf += this.indent + '}' + (this.compress ? '' : '\n'); | ||
this.buf += this.out(this.indent + '}' + (this.compress ? '' : '\n')); | ||
} | ||
@@ -313,10 +332,2 @@ }; | ||
/** | ||
* Visit Variable. | ||
*/ | ||
Compiler.prototype.visitVariable = function(variable){ | ||
return ''; | ||
}; | ||
/** | ||
* Visit Charset. | ||
@@ -344,4 +355,4 @@ */ | ||
Compiler.prototype.visitLiteral = function(lit){ | ||
var val = lit.val.trim(); | ||
if (!this.includeCSS) val = val.replace(/^ /gm, ''); | ||
var val = lit.val; | ||
if (lit.css) val = val.replace(/^ /gm, ''); | ||
return val; | ||
@@ -402,3 +413,3 @@ }; | ||
var stack = this.keyframe ? [] : this.stack | ||
, comma = this.compress ? ',' : ', '; | ||
, comma = this.compress ? ',' : ',\n'; | ||
@@ -409,10 +420,16 @@ stack.push(group.nodes); | ||
if (group.block.hasProperties) { | ||
var selectors = utils.compileSelectors.call(this, stack); | ||
if (selectors.length) { | ||
// keyframe blocks (10%, 20% { ... }) | ||
if (this.keyframe) { | ||
selectors = selectors.map(function(selector, i) { return i ? selector.trim() : selector; }); | ||
this.buf += selectors.join(comma); | ||
} else { | ||
this.buf += (this.selector = selectors.join(this.compress ? ',' : ',\n')); | ||
var selectors = utils.compileSelectors.call(this, stack) | ||
, len = selectors.length; | ||
if (len) { | ||
if (this.keyframe) comma = this.compress ? ',' : ', '; | ||
for (var i = 0; i < len; ++i) { | ||
var selector = selectors[i] | ||
, last = (i == len - 1); | ||
// keyframe blocks (10%, 20% { ... }) | ||
if (this.keyframe) selector = i ? selector.trim() : selector; | ||
this.buf += this.out(selector + (last ? '' : comma), group.nodes[i]); | ||
} | ||
@@ -503,9 +520,12 @@ } else { | ||
Compiler.prototype.visitProperty = function(prop){ | ||
var self = this | ||
, val = this.visit(prop.expr).trim(); | ||
return this.indent + (prop.name || prop.segments.join('')) | ||
+ (this.compress ? ':' + val : ': ' + val) | ||
+ (this.compress | ||
? (this.last ? '' : ';') | ||
: ';'); | ||
var val = this.visit(prop.expr).trim() | ||
, name = (prop.name || prop.segments.join('')) | ||
, arr = []; | ||
arr.push( | ||
this.out(this.indent), | ||
this.out(name + (this.compress ? ':' : ': '), prop), | ||
this.out(val, prop.expr), | ||
this.out(this.compress ? (this.last ? '' : ';') : ';') | ||
); | ||
return arr.join(''); | ||
}; | ||
@@ -512,0 +532,0 @@ |
@@ -151,3 +151,4 @@ | ||
err.filename = file; | ||
err.lineno = parser.lexer.lineno; | ||
err.lineno = parser.lexer.prev.lineno; | ||
err.column = parser.lexer.prev.column; | ||
err.input = str; | ||
@@ -154,0 +155,0 @@ throw err; |
@@ -62,3 +62,7 @@ | ||
var str = fs.readFileSync(file, 'utf8'); | ||
if (literal && !this.resolveURL) return new nodes.Literal(str.replace(/\r\n?/g, '\n')); | ||
if (literal && !this.resolveURL) { | ||
literal = new nodes.Literal(str.replace(/\r\n?/g, '\n')); | ||
literal.lineno = literal.column = 1; | ||
return literal; | ||
} | ||
@@ -73,3 +77,4 @@ // parse | ||
err.filename = file; | ||
err.lineno = parser.lexer.lineno; | ||
err.lineno = parser.lexer.prev.lineno; | ||
err.column = parser.lexer.prev.column; | ||
err.input = str; | ||
@@ -146,2 +151,3 @@ throw err; | ||
err.lineno = node.lineno; | ||
err.column = node.column; | ||
err.filename = node.filename; | ||
@@ -663,4 +669,10 @@ err.stylusStack = this.stack.toString(); | ||
Evaluator.prototype.visitRoot = function(block){ | ||
// normalize cached imports | ||
if (block != this.root) { | ||
block.constructor = nodes.Block; | ||
return this.visit(block); | ||
} | ||
for (var i = 0; i < block.nodes.length; ++i) { | ||
block.index = this.rootIndex = i; | ||
block.index = i; | ||
block.nodes[i] = this.visit(block.nodes[i]); | ||
@@ -786,6 +798,9 @@ } | ||
extend.selectors.forEach(function(selector){ | ||
// Cloning the selector for when we are in a loop and don't want it to affect | ||
// the selector nodes and cause the values to be different to expected | ||
selector = this.interpolate(selector.clone()).trim(); | ||
block.node.extends.push(selector); | ||
block.node.extends.push({ | ||
// Cloning the selector for when we are in a loop and don't want it to affect | ||
// the selector nodes and cause the values to be different to expected | ||
selector: this.interpolate(selector.clone()).trim(), | ||
lineno: selector.lineno, | ||
column: selector.column | ||
}); | ||
}, this); | ||
@@ -1115,3 +1130,4 @@ return nodes.null; | ||
err.filename = this.filename; | ||
err.lineno = parser.lexer.lineno; | ||
err.lineno = parser.lexer.prev.lineno; | ||
err.column = parser.lexer.prev.column; | ||
err.input = str; | ||
@@ -1216,2 +1232,3 @@ throw err; | ||
case 'atblock': | ||
case 'call': | ||
nodes = block.nodes; | ||
@@ -1218,0 +1235,0 @@ // scan siblings from the property index up |
@@ -35,2 +35,3 @@ | ||
this.map = {}; | ||
this.currentGroup = null; | ||
}; | ||
@@ -87,5 +88,5 @@ | ||
if (props.length) { | ||
var selector = new nodes.Selector([new nodes.Literal('&')]) | ||
, parentGroup = node.block.parent.node; | ||
var selector = new nodes.Selector([new nodes.Literal('&')]); | ||
selector.lineno = node.lineno; | ||
selector.column = node.column; | ||
selector.filename = node.filename; | ||
@@ -96,2 +97,3 @@ selector.val = '&'; | ||
group.lineno = node.lineno; | ||
group.column = node.column; | ||
group.filename = node.filename; | ||
@@ -101,2 +103,3 @@ | ||
block.lineno = node.lineno; | ||
block.column = node.column; | ||
block.filename = node.filename; | ||
@@ -116,3 +119,9 @@ | ||
}); | ||
node.group = parentGroup.clone(); | ||
if (!this.currentGroup) { | ||
var err = new Error('Failed to find a group that closest to the @media'); | ||
err.lineno = node.lineno; | ||
err.column = node.column; | ||
throw err; | ||
} | ||
node.group = this.currentGroup.clone(); | ||
node.bubbled = true; | ||
@@ -152,4 +161,3 @@ } | ||
Normalizer.prototype.visitBlock = function(block){ | ||
var ret = new nodes.Block | ||
, node; | ||
var node; | ||
@@ -168,3 +176,3 @@ if (block.hasProperties) { | ||
default: | ||
ret.push(this.visit(node)); | ||
this.visit(node); | ||
} | ||
@@ -177,5 +185,3 @@ } | ||
node = block.nodes[i]; | ||
// normalize cached imports | ||
if ('root' == node.nodeName) node.constructor = nodes.Block; | ||
ret.push(this.visit(node)); | ||
this.visit(node); | ||
} | ||
@@ -210,3 +216,3 @@ | ||
} | ||
s = new nodes.Selector([part]); | ||
s = new nodes.Selector([new nodes.Literal(part)]); | ||
s.val = part; | ||
@@ -218,2 +224,3 @@ s.block = group.block; | ||
stack.push(group.nodes); | ||
this.currentGroup = group; | ||
@@ -237,2 +244,10 @@ var selectors = utils.compileSelectors(stack, true); | ||
/** | ||
* Visit Function. | ||
*/ | ||
Normalizer.prototype.visitFunction = function(){ | ||
return nodes.null; | ||
}; | ||
/** | ||
* Visit Media. | ||
@@ -242,15 +257,18 @@ */ | ||
Normalizer.prototype.visitMedia = function(media){ | ||
var medias = [] | ||
, self = this; | ||
var medias = []; | ||
function mergeQueries(block) { | ||
block.nodes.forEach(function(node, i){ | ||
node = self.visit(node); | ||
if ('media' == node.nodeName) { | ||
node.val = media.val.merge(node.val); | ||
medias.push(node); | ||
block.nodes[i] = nodes.null; | ||
} else if (node.block) { | ||
mergeQueries(node.block); | ||
switch (node.nodeName) { | ||
case 'media': | ||
node.val = media.val.merge(node.val); | ||
medias.push(node); | ||
block.nodes[i] = nodes.null; | ||
break; | ||
case 'block': | ||
mergeQueries(node); | ||
break; | ||
default: | ||
if (node.block && node.block.nodes) | ||
mergeQueries(node.block); | ||
} | ||
@@ -305,4 +323,9 @@ }); | ||
group.block.node.extends.forEach(function(extend){ | ||
var groups = map[extend]; | ||
if (!groups) throw new Error('Failed to @extend "' + extend + '"'); | ||
var groups = map[extend.selector]; | ||
if (!groups) { | ||
var err = new Error('Failed to @extend "' + extend.selector + '"'); | ||
err.lineno = extend.lineno; | ||
err.column = extend.column; | ||
throw err; | ||
} | ||
selectors.forEach(function(selector){ | ||
@@ -309,0 +332,0 @@ var node = new nodes.Selector; |
{ | ||
"name": "stylus", | ||
"description": "Robust, expressive, and feature-rich CSS superset", | ||
"version": "0.47.3", | ||
"version": "0.48.0", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -36,3 +36,4 @@ "keywords": [ | ||
"sax": "0.5.x", | ||
"glob": "3.2.x" | ||
"glob": "3.2.x", | ||
"source-map": "0.1.x" | ||
}, | ||
@@ -39,0 +40,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
330442
75
12588
6
13
+ Addedsource-map@0.1.x
+ Addedamdefine@1.0.1(transitive)
+ Addedsource-map@0.1.43(transitive)