Comparing version 0.49.3 to 0.50.0
@@ -54,5 +54,6 @@ /** | ||
MemoryCache.prototype.get = function(key) { | ||
var item = this._cache[key]; | ||
var item = this._cache[key] | ||
, val = item.value.clone(); | ||
if (item == this.tail) return item.value; | ||
if (item == this.tail) return val; | ||
if (item.next) { | ||
@@ -70,3 +71,3 @@ if (item == this.head) this.head = item.next; | ||
return item.value.clone(); | ||
return val; | ||
}; | ||
@@ -73,0 +74,0 @@ |
@@ -140,3 +140,3 @@ /*! | ||
Converter.prototype.visitRule = function(node){ | ||
var buf = this.indent + node.selectors.join(',\n') + '\n'; | ||
var buf = this.indent + node.selectors.join(',\n' + this.indent) + '\n'; | ||
++this.indents; | ||
@@ -143,0 +143,0 @@ for (var i = 0, len = node.declarations.length; i < len; ++i) { |
@@ -652,4 +652,6 @@ | ||
exports.contrast = function contrast(top, bottom){ | ||
if ('rgba' != top.nodeName && 'hsla' != top.nodeName) { | ||
return new nodes.Literal('contrast(' + (top.isNull ? '' : top.toString()) + ')'); | ||
} | ||
var result = new nodes.Object(); | ||
utils.assertColor(top); | ||
top = top.rgba; | ||
@@ -1511,4 +1513,8 @@ bottom = bottom || new nodes.RGBA(255, 255, 255, 1); | ||
utils.assertType(dest, 'object', 'dest'); | ||
for (var i = 1, len = arguments.length; i < len; ++i) { | ||
utils.merge(dest.vals, utils.unwrap(arguments[i]).first.vals); | ||
var last = utils.unwrap(arguments[arguments.length - 1]).first | ||
, deep = (true === last.val); | ||
for (var i = 1, len = arguments.length - deep; i < len; ++i) { | ||
utils.merge(dest.vals, utils.unwrap(arguments[i]).first.vals, deep); | ||
} | ||
@@ -1519,2 +1525,18 @@ return dest; | ||
/** | ||
* Remove the given `key` from the `object`. | ||
* | ||
* @param {Object} object | ||
* @param {String} key | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
exports.remove = function remove(object, key){ | ||
utils.assertType(object, 'object', 'object'); | ||
utils.assertString(key, 'key'); | ||
delete object.vals[key.string]; | ||
return object; | ||
}; | ||
/** | ||
* Return the current selector or compile `sel` selector. | ||
@@ -1542,2 +1564,24 @@ * | ||
/** | ||
* Returns true if the given selector exists. | ||
* | ||
* @param {String} sel | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
exports['selector-exists'] = function selectorExists(sel) { | ||
utils.assertString(sel, 'selector'); | ||
if (!this.__selectorsMap__) { | ||
var Normalizer = require('../visitor/normalizer') | ||
, visitor = new Normalizer(this.root.clone()); | ||
visitor.visit(visitor.root); | ||
this.__selectorsMap__ = visitor.map; | ||
} | ||
return sel.string in this.__selectorsMap__; | ||
}; | ||
/** | ||
* Prefix css classes in a block | ||
@@ -1606,2 +1650,32 @@ * | ||
/** | ||
* Returns a list of units from `start` to `stop` | ||
* by `step`. If `step` argument is omitted, | ||
* it defaults to 1. | ||
* | ||
* @param {Unit} start | ||
* @param {Unit} stop | ||
* @param {Unit} [step] | ||
* @return {Expression} | ||
* @api public | ||
*/ | ||
exports.range = function range(start, stop, step){ | ||
utils.assertType(start, 'unit', 'start'); | ||
utils.assertType(stop, 'unit', 'stop'); | ||
if (step) { | ||
utils.assertType(step, 'unit', 'step'); | ||
if (0 == step.val) { | ||
throw new Error('ArgumentError: "step" argument must not be zero'); | ||
} | ||
} else { | ||
step = new nodes.Unit(1); | ||
} | ||
var list = new nodes.Expression; | ||
for (var i = start.val; i <= stop.val; i += step.val) { | ||
list.push(new nodes.Unit(i, start.type)); | ||
} | ||
return list; | ||
}; | ||
/** | ||
* Attempt to parse unit `str`. | ||
@@ -1608,0 +1682,0 @@ * |
@@ -54,4 +54,4 @@ /** | ||
// Absolute | ||
if (url.protocol) return literal; | ||
// Absolute or hash | ||
if (url.protocol || !url.pathname) return literal; | ||
@@ -58,0 +58,0 @@ // Lookup |
@@ -126,5 +126,5 @@ | ||
self.nodes[n] = val; | ||
} else if ('string' == unit.nodeName) { | ||
} else if (unit.string) { | ||
node = self.nodes[0]; | ||
if (node && 'object' == node.nodeName) node.set(unit.val, val.clone()); | ||
if (node && 'object' == node.nodeName) node.set(unit.string, val.clone()); | ||
} | ||
@@ -141,4 +141,4 @@ }); | ||
node = vals[unit.val < 0 ? vals.length + unit.val : unit.val]; | ||
} else if ('string' == unit.nodeName && 'object' == vals[0].nodeName) { | ||
node = vals[0].get(unit.val); | ||
} else if ('object' == vals[0].nodeName) { | ||
node = vals[0].get(unit.string); | ||
} | ||
@@ -145,0 +145,0 @@ if (node) expr.push(node); |
@@ -96,2 +96,17 @@ | ||
return this.get(right.hash); | ||
case '==': | ||
var vals = this.vals | ||
, a | ||
, b; | ||
if ('object' != right.nodeName || this.length != right.length) | ||
return nodes.false; | ||
for (var key in vals) { | ||
a = vals[key]; | ||
b = right.vals[key]; | ||
if (a.operate(op, b).isFalse) | ||
return nodes.false; | ||
} | ||
return nodes.true; | ||
case '!=': | ||
return this.operate('==', right).negate(); | ||
default: | ||
@@ -98,0 +113,0 @@ return Node.prototype.operate.call(this, op, right); |
@@ -26,2 +26,3 @@ | ||
this.segments = segs; | ||
this.optional = false; | ||
}; | ||
@@ -43,3 +44,3 @@ | ||
Selector.prototype.toString = function(){ | ||
return this.segments.join(''); | ||
return this.segments.join('') + (this.optional ? ' !optional' : ''); | ||
}; | ||
@@ -73,2 +74,3 @@ | ||
clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); }); | ||
clone.optional = this.optional; | ||
return clone; | ||
@@ -89,2 +91,3 @@ }; | ||
segments: this.segments, | ||
optional: this.optional, | ||
val: this.val, | ||
@@ -91,0 +94,0 @@ lineno: this.lineno, |
@@ -72,5 +72,3 @@ | ||
Unit.prototype.toString = function(){ | ||
var n = this.val; | ||
if ('px' == this.type) n = n.toFixed(0); | ||
return n + (this.type || ''); | ||
return this.val + (this.type || ''); | ||
}; | ||
@@ -77,0 +75,0 @@ |
@@ -510,2 +510,5 @@ /*! | ||
if ('&' == this.lookahead(i + 1).type) | ||
return true; | ||
if ('.' == this.lookahead(i).type && 'ident' == this.lookahead(i + 1).type) | ||
@@ -832,3 +835,8 @@ return true; | ||
} else { | ||
if (this.accept('newline') || this.accept('indent')) continue; | ||
if (this.accept('newline')) continue; | ||
if ('indent' == this.peek().type | ||
&& 'outdent' == this.lookahead(2).type) { | ||
this.accept('indent'); | ||
continue; | ||
} | ||
stmt = this.statement(); | ||
@@ -1057,3 +1065,7 @@ this.accept(';'); | ||
if ('(' == this.peek().type) { | ||
if ('(' == this.lookahead(2).type) { | ||
var la = this.lookahead(2).type; | ||
if ('ident' == la || '{' == la) { | ||
return this.feature(); | ||
} else { | ||
this.expect('('); | ||
@@ -1068,3 +1080,2 @@ var node = new nodes.Expression; | ||
} | ||
return this.feature(); | ||
} | ||
@@ -1080,2 +1091,3 @@ }, | ||
, selectors = [] | ||
, sel | ||
, node | ||
@@ -1086,3 +1098,15 @@ , arr; | ||
arr = this.selectorParts(); | ||
if (arr.length) selectors.push(new nodes.Selector(arr)); | ||
if (!arr.length) continue; | ||
sel = new nodes.Selector(arr); | ||
selectors.push(sel); | ||
if ('!' !== this.peek().type) continue; | ||
tok = this.lookahead(2); | ||
if ('ident' !== tok.type || 'optional' !== tok.val.name) continue; | ||
this.skip(['!', 'ident']); | ||
sel.optional = true; | ||
} while(this.accept(',')); | ||
@@ -1983,3 +2007,5 @@ | ||
this.operand = true; | ||
node = new nodes.UnaryOp(op.type, this.unary()); | ||
node = this.unary(); | ||
if (!node) this.error('illegal unary "' + op + '"'); | ||
node = new nodes.UnaryOp(op.type, node); | ||
this.operand = false; | ||
@@ -1992,3 +2018,3 @@ return node; | ||
/** | ||
* member ('[' expression ']' ('.' id)? '='?)+ | ||
* member ('[' expression ']')+ '='? | ||
* | member | ||
@@ -2003,14 +2029,10 @@ */ | ||
this.expect(']'); | ||
if (this.accept('.')) { | ||
id = new nodes.Ident(this.expect('ident').val.string); | ||
node = new nodes.Member(node, id); | ||
} | ||
// TODO: TernaryOp :) | ||
if (this.accept('=')) { | ||
node.op += '='; | ||
node.val = this.expression(); | ||
// @block support | ||
if (node.val.isEmpty) this.assignAtblock(node.val); | ||
} | ||
} | ||
// TODO: TernaryOp :) | ||
if (this.accept('=')) { | ||
node.op += '='; | ||
node.val = this.list(); | ||
// @block support | ||
if (node.val.isEmpty) this.assignAtblock(node.val); | ||
} | ||
return node; | ||
@@ -2033,3 +2055,3 @@ }, | ||
if (this.accept('=')) { | ||
node.val = this.expression(); | ||
node.val = this.list(); | ||
// @block support | ||
@@ -2036,0 +2058,0 @@ if (node.val.isEmpty) this.assignAtblock(node.val); |
@@ -100,10 +100,2 @@ | ||
if (this.options.sourcemap) this.sourcemap = compiler.map.toJSON(); | ||
var listeners = this.listeners('end'); | ||
if (fn) listeners.push(fn); | ||
for (var i = 0, len = listeners.length; i < len; i++) { | ||
var ret = listeners[i](null, css); | ||
if (ret) css = ret; | ||
} | ||
if (!fn) return css; | ||
} catch (err) { | ||
@@ -113,7 +105,16 @@ var options = {}; | ||
options.filename = err.filename || this.options.filename; | ||
options.lineno = err.lineno || parser.lexer.prev.lineno; | ||
options.column = err.column || parser.lexer.prev.column; | ||
options.lineno = err.lineno || parser.lexer.lineno; | ||
options.column = err.column || parser.lexer.column; | ||
if (!fn) throw utils.formatException(err, options); | ||
fn(utils.formatException(err, options)); | ||
return fn(utils.formatException(err, options)); | ||
} | ||
// fire `end` event | ||
var listeners = this.listeners('end'); | ||
if (fn) listeners.push(fn); | ||
for (var i = 0, len = listeners.length; i < len; i++) { | ||
var ret = listeners[i](null, css); | ||
if (ret) css = ret; | ||
} | ||
if (!fn) return css; | ||
}; | ||
@@ -147,4 +148,4 @@ | ||
options.filename = err.filename || this.options.filename; | ||
options.lineno = err.lineno || parser.lexer.prev.lineno; | ||
options.column = err.column || parser.lexer.prev.column; | ||
options.lineno = err.lineno || parser.lexer.lineno; | ||
options.column = err.column || parser.lexer.column; | ||
throw utils.formatException(err, options); | ||
@@ -151,0 +152,0 @@ } |
@@ -387,8 +387,21 @@ | ||
* @param {Object} b | ||
* @param {Boolean} [deep] | ||
* @return {Object} a | ||
* @api private | ||
*/ | ||
exports.merge = function(a, b, deep) { | ||
for (var k in b) { | ||
if (deep && a[k]) { | ||
var nodeA = exports.unwrap(a[k]).first | ||
, nodeB = exports.unwrap(b[k]).first; | ||
exports.merge = function(a, b){ | ||
for (var k in b) a[k] = b[k]; | ||
if ('object' == nodeA.nodeName && 'object' == nodeB.nodeName) { | ||
a[k].first.vals = exports.merge(nodeA.vals, nodeB.vals, deep); | ||
} else { | ||
a[k] = b[k]; | ||
} | ||
} else { | ||
a[k] = b[k]; | ||
} | ||
} | ||
return a; | ||
@@ -447,2 +460,3 @@ }; | ||
, selectors = [] | ||
, indent = (this.indent || '') | ||
, buf = []; | ||
@@ -473,3 +487,3 @@ | ||
} else { | ||
selectors.push(interpolateParent(selector, buf)); | ||
selectors.push(indent + interpolateParent(selector, buf)); | ||
} | ||
@@ -483,3 +497,3 @@ }); | ||
if (!str.length) return; | ||
selectors.push((self.indent || '') + str.trimRight()); | ||
selectors.push(indent + str.trimRight()); | ||
}); | ||
@@ -486,0 +500,0 @@ } |
@@ -177,5 +177,5 @@ /*! | ||
case 'comment': | ||
// only show comments inside when outside of scope and unsuppressed | ||
if (!block.scope && !node.suppress) { | ||
this.buf += this.out(this.visit(node) + '\n', node); | ||
// only show unsuppressed comments | ||
if (!node.suppress) { | ||
this.buf += this.out(this.indent + this.visit(node) + '\n', node); | ||
} | ||
@@ -182,0 +182,0 @@ break; |
@@ -152,4 +152,4 @@ | ||
err.filename = file; | ||
err.lineno = parser.lexer.prev.lineno; | ||
err.column = parser.lexer.prev.column; | ||
err.lineno = parser.lexer.lineno; | ||
err.column = parser.lexer.column; | ||
err.input = str; | ||
@@ -156,0 +156,0 @@ throw err; |
@@ -29,3 +29,3 @@ | ||
*/ | ||
function importFile(node, file, literal, index) { | ||
function importFile(node, file, literal) { | ||
var importStack = this.importStack | ||
@@ -76,4 +76,4 @@ , Parser = require('../parser') | ||
} catch (err) { | ||
var line = parser.lexer.prev.lineno | ||
, column = parser.lexer.prev.column; | ||
var line = parser.lexer.lineno | ||
, column = parser.lexer.column; | ||
@@ -93,8 +93,8 @@ if (this.includeCSS && this.resolveURL) { | ||
// Evaluate imported "root" | ||
block = block.clone(this.root); | ||
block.parent = this.root; | ||
block = block.clone(this.currentBlock); | ||
block.parent = this.currentBlock; | ||
block.scope = false; | ||
var ret = this.visit(block); | ||
importStack.pop(); | ||
if (importStack.length || index) this.paths.pop(); | ||
if (!this.resolveURL) this.paths.pop(); | ||
@@ -841,2 +841,3 @@ return ret; | ||
selector: this.interpolate(selector.clone()).trim(), | ||
optional: selector.optional, | ||
lineno: selector.lineno, | ||
@@ -859,4 +860,3 @@ column: selector.column | ||
, found | ||
, literal | ||
, index; | ||
, literal; | ||
@@ -878,4 +878,4 @@ this.return--; | ||
// Absolute URL | ||
if (/url\s*\(\s*['"]?(?:https?:)?\/\//i.test(path)) { | ||
// Absolute URL or hash | ||
if (/url\s*\(\s*['"]?(?:#|(?:https?:)?\/\/)/i.test(path)) { | ||
if (imported.once) throw new Error('You cannot @require a url'); | ||
@@ -900,3 +900,2 @@ return imported; | ||
found = utils.lookupIndex(name, this.paths, this.filename); | ||
index = true; | ||
} | ||
@@ -910,3 +909,3 @@ | ||
for (var i = 0, len = found.length; i < len; ++i) { | ||
block.push(importFile.call(this, imported, found[i], literal, index)); | ||
block.push(importFile.call(this, imported, found[i], literal)); | ||
} | ||
@@ -1180,4 +1179,4 @@ | ||
err.filename = this.filename; | ||
err.lineno = parser.lexer.prev.lineno; | ||
err.column = parser.lexer.prev.column; | ||
err.lineno = parser.lexer.lineno; | ||
err.column = parser.lexer.column; | ||
err.input = str; | ||
@@ -1328,2 +1327,3 @@ throw err; | ||
case 'media': | ||
case 'call': | ||
return block; | ||
@@ -1330,0 +1330,0 @@ } |
@@ -33,4 +33,6 @@ | ||
Visitor.call(this, root); | ||
this.hoist = options['hoist atrules']; | ||
this.stack = []; | ||
this.map = {}; | ||
this.imports = []; | ||
}; | ||
@@ -52,3 +54,13 @@ | ||
Normalizer.prototype.normalize = function(){ | ||
return this.visit(this.root); | ||
var ret = this.visit(this.root); | ||
if (this.hoist) { | ||
// hoist @import | ||
if (this.imports.length) ret.nodes = this.imports.concat(ret.nodes); | ||
// hoist @charset | ||
if (this.charset) ret.nodes = [this.charset].concat(ret.nodes); | ||
} | ||
return ret; | ||
}; | ||
@@ -117,11 +129,2 @@ | ||
var group = this.closestGroup(node.block); | ||
if (!group) { | ||
var err = new Error('Failed to find a group that closest to the @' + node.nodeName); | ||
err.lineno = node.lineno; | ||
err.column = node.column; | ||
throw err; | ||
} | ||
node.group = group.clone(); | ||
node.bubbled = true; | ||
@@ -221,3 +224,3 @@ } | ||
default: | ||
this.visit(node); | ||
block.nodes[i] = this.visit(node); | ||
} | ||
@@ -230,3 +233,3 @@ } | ||
node = block.nodes[i]; | ||
this.visit(node); | ||
block.nodes[i] = this.visit(node); | ||
} | ||
@@ -299,3 +302,3 @@ | ||
var medias = [] | ||
, group = this.closestGroup(media.block) | ||
, group | ||
, parent; | ||
@@ -325,2 +328,4 @@ | ||
if (medias.length) { | ||
group = this.closestGroup(media.block); | ||
medias.forEach(function(node){ | ||
@@ -335,4 +340,5 @@ if (group) { | ||
if (node.bubbled && (!group || 'group' == parent.node.nodeName)) { | ||
node.group.block = node.block.nodes[0].block; | ||
node.block.nodes[0] = node.group; | ||
group = this.closestGroup(node.block).clone(); | ||
group.block = node.block.nodes[0].block; | ||
node.block.nodes[0] = group; | ||
} | ||
@@ -375,2 +381,20 @@ }, this); | ||
/** | ||
* Visit Import. | ||
*/ | ||
Normalizer.prototype.visitImport = function(node){ | ||
this.imports.push(node); | ||
return this.hoist ? nodes.null : node; | ||
}; | ||
/** | ||
* Visit Charset. | ||
*/ | ||
Normalizer.prototype.visitCharset = function(node){ | ||
this.charset = node; | ||
return this.hoist ? nodes.null : node; | ||
}; | ||
/** | ||
* Apply `group` extensions. | ||
@@ -390,2 +414,3 @@ * | ||
if (!groups) { | ||
if (extend.optional) return; | ||
var err = new Error('Failed to @extend "' + extend.selector + '"'); | ||
@@ -392,0 +417,0 @@ err.lineno = extend.lineno; |
@@ -41,4 +41,10 @@ /*! | ||
this.comment = sourcemap.comment; | ||
if (extname(this.dest) === '.css') { | ||
this.basename = basename(this.dest); | ||
} else { | ||
this.basename = basename(this.filename, extname(this.filename)) + '.css'; | ||
} | ||
this.map = new SourceMapGenerator({ | ||
file: basename(this.filename, extname(this.filename)) + '.css', | ||
file: this.basename, | ||
sourceRoot: sourcemap.sourceRoot || null | ||
@@ -65,3 +71,3 @@ }); | ||
var css = compile.call(this) | ||
, out = basename(this.filename, extname(this.filename)) + '.css.map' | ||
, out = this.basename + '.map' | ||
, url = this.normalizePath(this.dest | ||
@@ -68,0 +74,0 @@ ? join(this.dest, out) |
{ | ||
"name": "stylus", | ||
"description": "Robust, expressive, and feature-rich CSS superset", | ||
"version": "0.49.3", | ||
"version": "0.50.0", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -13,3 +13,3 @@ # Stylus [![Build Status](https://travis-ci.org/LearnBoost/stylus.svg?branch=master)](https://travis-ci.org/LearnBoost/stylus) | ||
``` | ||
```sass | ||
border-radius() | ||
@@ -50,3 +50,3 @@ -webkit-border-radius: arguments | ||
``` | ||
```sass | ||
border-radius() { | ||
@@ -125,2 +125,3 @@ -webkit-border-radius: arguments | ||
- [Grails](http://grails.org/plugin/stylus-asset-pipeline) | ||
- [Derby](https://github.com/derbyjs/derby-stylus) | ||
@@ -127,0 +128,0 @@ ### CMS Support |
Sorry, the diff of this file is not supported yet
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
343122
13046
167