Comparing version 0.43.0 to 0.44.0-beta
@@ -1017,3 +1017,5 @@ | ||
exports['-math'] = function math(n, fn){ | ||
exports.math = function math(n, fn){ | ||
utils.assertType(n, 'unit', 'n'); | ||
utils.assertString(fn, 'fn'); | ||
return new nodes.Unit(Math[fn.string](n.val), n.type); | ||
@@ -1035,15 +1037,2 @@ }; | ||
/** | ||
* Buffer the given js `str`. | ||
* | ||
* @param {String} str | ||
* @return {JSLiteral} | ||
* @api private | ||
*/ | ||
exports.js = function js(str){ | ||
utils.assertString(str, 'str'); | ||
return new nodes.JSLiteral(str.val); | ||
}; | ||
/** | ||
* Adjust HSL `color` `prop` by `amount`. | ||
@@ -1058,3 +1047,6 @@ * | ||
exports['-adjust'] = function adjust(color, prop, amount){ | ||
exports.adjust = function adjust(color, prop, amount){ | ||
utils.assertColor(color, 'color'); | ||
utils.assertString(prop, 'prop'); | ||
utils.assertType(amount, 'unit', 'amount'); | ||
var hsl = color.hsla.clone(); | ||
@@ -1061,0 +1053,0 @@ prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string]; |
@@ -139,3 +139,3 @@ /*! | ||
// Compile to cssPath | ||
function compile() { | ||
function compile(changed) { | ||
debug('read %s', cssPath); | ||
@@ -146,3 +146,4 @@ fs.readFile(stylusPath, 'utf8', function(err, str){ | ||
var paths = style.options._imports = []; | ||
delete imports[stylusPath]; | ||
if (changed) style.options._changed = changed; | ||
imports[stylusPath] = null; | ||
style.render(function(err, css){ | ||
@@ -189,3 +190,3 @@ if (err) return next(err); | ||
} | ||
changed.length ? compile() : next(); | ||
changed.length ? compile(changed) : next(); | ||
}); | ||
@@ -192,0 +193,0 @@ } |
@@ -60,7 +60,16 @@ | ||
Arguments.prototype.clone = function(){ | ||
var clone = nodes.Expression.prototype.clone.call(this); | ||
clone.map = this.map; | ||
Arguments.prototype.clone = function(parent){ | ||
var clone = nodes.Expression.prototype.clone.call(this, parent); | ||
clone.map = {}; | ||
for (var key in this.map) { | ||
clone.map[key] = this.map[key].clone(parent, clone); | ||
} | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
Arguments.prototype.toJSON = function(){ | ||
this.__type = 'Arguments'; | ||
return this; | ||
}; |
@@ -44,5 +44,5 @@ /*! | ||
Atblock.prototype.clone = function(){ | ||
Atblock.prototype.clone = function(parent){ | ||
var clone = new Atblock; | ||
clone.block = this.block.clone(); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
@@ -63,1 +63,6 @@ clone.filename = this.filename; | ||
}; | ||
Atblock.prototype.toJSON = function(){ | ||
this.__type = 'Atblock'; | ||
return this; | ||
}; |
@@ -43,12 +43,9 @@ | ||
BinOp.prototype.clone = function(){ | ||
var clone = new BinOp( | ||
this.op | ||
, this.left.clone() | ||
, this.right ? | ||
this.right.clone() | ||
: null); | ||
BinOp.prototype.clone = function(parent){ | ||
var clone = new BinOp(this.op); | ||
clone.left = this.left.clone(parent, clone); | ||
clone.right = this.right && this.right.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
if (this.val) clone.val = this.val.clone(); | ||
if (this.val) clone.val = this.val.clone(parent, clone); | ||
return clone; | ||
@@ -66,1 +63,6 @@ }; | ||
}; | ||
BinOp.prototype.toJSON = function(){ | ||
this.__type = 'BinOp'; | ||
return this; | ||
}; |
@@ -85,4 +85,5 @@ | ||
Block.prototype.clone = function(){ | ||
var clone = new Block(this.parent, this.node); | ||
Block.prototype.clone = function(parent, node){ | ||
parent = parent || this.parent; | ||
var clone = new Block(parent, node || this.node); | ||
clone.lineno = this.lineno; | ||
@@ -92,19 +93,3 @@ clone.filename = this.filename; | ||
this.nodes.forEach(function(node){ | ||
node = node.clone(); | ||
switch (node.nodeName) { | ||
case 'each': | ||
case 'group': | ||
node.block.parent = clone; | ||
break; | ||
case 'media': | ||
case 'fontface': | ||
clone.scope = true; | ||
node.block.parent = clone; | ||
break; | ||
case 'ident': | ||
if ('function' == node.val.nodeName) { | ||
node.val.block.parent = clone; | ||
} | ||
} | ||
clone.push(node); | ||
clone.push(node.clone(clone, clone)); | ||
}); | ||
@@ -124,1 +109,6 @@ return clone; | ||
}; | ||
Block.prototype.toJSON = function(){ | ||
this.__type = 'Block'; | ||
return this; | ||
}; |
@@ -103,2 +103,7 @@ | ||
: 'false'; | ||
}; | ||
}; | ||
Boolean.prototype.toJSON = function(){ | ||
this.__type = 'Boolean'; | ||
return this; | ||
}; |
@@ -41,5 +41,6 @@ | ||
Call.prototype.clone = function(){ | ||
var clone = new Call(this.name, this.args.clone()); | ||
if (this.block) clone.block = this.block.clone(); | ||
Call.prototype.clone = function(parent){ | ||
var clone = new Call(this.name); | ||
clone.args = this.args.clone(parent, clone); | ||
if (this.block) clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
@@ -65,1 +66,6 @@ clone.filename = this.filename; | ||
}; | ||
Call.prototype.toJSON = function(){ | ||
this.__type = 'Call'; | ||
return this; | ||
}; |
@@ -43,1 +43,6 @@ | ||
}; | ||
Charset.prototype.toJSON = function(){ | ||
this.__type = 'Charset'; | ||
return this; | ||
}; |
@@ -34,2 +34,7 @@ | ||
Comment.prototype.toJSON = function(){ | ||
this.__type = 'Comment'; | ||
return this; | ||
}; | ||
/** | ||
@@ -44,2 +49,2 @@ * Return comment. | ||
return this.str; | ||
}; | ||
}; |
@@ -47,11 +47,14 @@ | ||
Each.prototype.clone = function(){ | ||
var clone = new Each( | ||
this.val | ||
, this.key | ||
, this.expr.clone() | ||
, this.block.clone()); | ||
Each.prototype.clone = function(parent){ | ||
var clone = new Each(this.val, this.key); | ||
clone.expr = this.expr.clone(parent, clone); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
}; | ||
Each.prototype.toJSON = function(){ | ||
this.__type = 'Each'; | ||
return this; | ||
}; |
@@ -79,3 +79,3 @@ | ||
Expression.prototype.clone = function(){ | ||
Expression.prototype.clone = function(parent){ | ||
var clone = new this.constructor(this.isList); | ||
@@ -85,5 +85,5 @@ clone.preserve = this.preserve; | ||
clone.filename = this.filename; | ||
for (var i = 0; i < this.nodes.length; ++i) { | ||
clone.push(this.nodes[i].clone()); | ||
} | ||
clone.nodes = this.nodes.map(function(node) { | ||
return node.clone(parent, clone); | ||
}); | ||
return clone; | ||
@@ -203,1 +203,5 @@ }; | ||
Expression.prototype.toJSON = function(){ | ||
this.__type = 'Expression'; | ||
return this; | ||
}; |
@@ -53,1 +53,6 @@ | ||
}; | ||
Extend.prototype.toJSON = function(){ | ||
this.__type = 'Extend'; | ||
return this; | ||
}; |
@@ -39,4 +39,5 @@ | ||
FontFace.prototype.clone = function(){ | ||
var clone = new FontFace(this.block.clone()); | ||
FontFace.prototype.clone = function(parent){ | ||
var clone = new FontFace(); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
@@ -57,1 +58,6 @@ clone.filename = this.filename; | ||
}; | ||
FontFace.prototype.toJSON = function(){ | ||
this.__type = 'FontFace'; | ||
return this; | ||
}; |
@@ -66,3 +66,3 @@ | ||
Function.prototype.clone = function(){ | ||
Function.prototype.clone = function(parent){ | ||
if (this.fn) { | ||
@@ -73,6 +73,5 @@ var clone = new Function( | ||
} else { | ||
var clone = new Function( | ||
this.name | ||
, this.params.clone() | ||
, this.block.clone()); | ||
var clone = new Function(this.name); | ||
clone.params = this.params.clone(parent, clone); | ||
clone.block = this.block.clone(parent, clone); | ||
} | ||
@@ -107,1 +106,6 @@ clone.lineno = this.lineno; | ||
}; | ||
Function.prototype.toJSON = function(){ | ||
this.__type = 'Function'; | ||
return this; | ||
}; |
@@ -82,11 +82,16 @@ | ||
Group.prototype.clone = function(){ | ||
Group.prototype.clone = function(parent){ | ||
var clone = new Group; | ||
clone.lineno = this.lineno; | ||
this.nodes.forEach(function(node){ | ||
clone.push(node.clone()); | ||
clone.push(node.clone(parent, clone)); | ||
}); | ||
clone.filename = this.filename; | ||
clone.block = this.block.clone(); | ||
clone.block = this.block.clone(parent, clone); | ||
return clone; | ||
}; | ||
Group.prototype.toJSON = function(){ | ||
this.__type = 'Group'; | ||
return this; | ||
}; |
@@ -62,3 +62,3 @@ | ||
HSLA.prototype.clone = function(){ | ||
HSLA.prototype.clone = function(parent){ | ||
var clone = new HSLA( | ||
@@ -74,2 +74,7 @@ this.h | ||
HSLA.prototype.toJSON = function(){ | ||
this.__type = 'HSLA'; | ||
return this; | ||
}; | ||
/** | ||
@@ -76,0 +81,0 @@ * Return rgba `RGBA` representation. |
@@ -66,10 +66,18 @@ | ||
Ident.prototype.clone = function(){ | ||
var clone = new Ident(this.name, this.val.clone(), this.mixin); | ||
Ident.prototype.clone = function(parent){ | ||
var clone = new Ident(this.name); | ||
clone.val = this.val.clone(parent, clone); | ||
clone.mixin = this.mixin; | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
clone.property = this.property; | ||
clone.rest = this.rest; | ||
return clone; | ||
}; | ||
Ident.prototype.toJSON = function(){ | ||
this.__type = 'Ident'; | ||
return this; | ||
}; | ||
/** | ||
@@ -76,0 +84,0 @@ * Return <name>. |
@@ -46,7 +46,7 @@ | ||
If.prototype.clone = function(){ | ||
var cond = this.cond.clone() | ||
, block = this.block.clone(); | ||
var clone = new If(cond, block); | ||
clone.elses = this.elses.map(function(node){ return node.clone(); }); | ||
If.prototype.clone = function(parent){ | ||
var clone = new If(); | ||
clone.cond = this.cond.clone(parent, clone); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.elses = this.elses.map(function(node){ return node.clone(parent, clone); }); | ||
clone.negate = this.negate; | ||
@@ -58,1 +58,6 @@ clone.postfix = this.postfix; | ||
}; | ||
If.prototype.toJSON = function(){ | ||
this.__type = 'If'; | ||
return this; | ||
}; |
@@ -40,4 +40,6 @@ | ||
Import.prototype.clone = function(){ | ||
var clone = new Import(this.path.nodeName ? this.path.clone() : this.path, this.once); | ||
Import.prototype.clone = function(parent){ | ||
var clone = new Import(); | ||
clone.path = this.path.nodeName ? this.path.clone(parent, clone) : this.path; | ||
clone.once = this.once; | ||
clone.mtime = this.mtime; | ||
@@ -48,1 +50,6 @@ clone.lineno = this.lineno; | ||
}; | ||
Import.prototype.toJSON = function(){ | ||
this.__type = 'Import'; | ||
return this; | ||
}; |
@@ -31,3 +31,2 @@ | ||
exports.Literal = require('./literal'); | ||
exports.JSLiteral = require('./jsliteral'); | ||
exports.Boolean = require('./boolean'); | ||
@@ -34,0 +33,0 @@ exports.Return = require('./return'); |
@@ -58,9 +58,9 @@ | ||
Keyframes.prototype.clone = function(){ | ||
Keyframes.prototype.clone = function(parent){ | ||
var clone = new Keyframes(this.name); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
clone.prefix = this.prefix; | ||
clone.frames = this.frames.map(function(node){ | ||
node.block = node.block.clone(); | ||
return node; | ||
this.frames.forEach(function(node){ | ||
clone.push(node.pos, node.block.clone(parent, clone)); | ||
}); | ||
@@ -70,2 +70,7 @@ return clone; | ||
Keyframes.prototype.toJSON = function(){ | ||
this.__type = 'Keyframes'; | ||
return this; | ||
}; | ||
/** | ||
@@ -72,0 +77,0 @@ * Return `@keyframes name`. |
@@ -94,1 +94,6 @@ | ||
}; | ||
Literal.prototype.toJSON = function(){ | ||
this.__type = 'Literal'; | ||
return this; | ||
}; |
@@ -40,8 +40,16 @@ | ||
Media.prototype.clone = function(){ | ||
var clone = new Media(this.val.clone()); | ||
clone.block = this.block.clone(); | ||
Media.prototype.clone = function(parent){ | ||
var clone = new Media; | ||
clone.val = this.val.clone(parent, clone); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
Media.prototype.toJSON = function(){ | ||
this.__type = 'Media'; | ||
return this; | ||
}; | ||
/** | ||
@@ -48,0 +56,0 @@ * Check if media block has properties. |
@@ -41,10 +41,17 @@ | ||
Member.prototype.clone = function(){ | ||
var clone = new Member(this.left.clone(), this.right.clone()); | ||
Member.prototype.clone = function(parent){ | ||
var clone = new Member; | ||
clone.left = this.left.clone(parent, clone); | ||
clone.right = this.right.clone(parent, clone); | ||
if (this.val) clone.val = this.val.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
if (this.val) clone.val = this.val.clone(); | ||
return clone; | ||
}; | ||
Member.prototype.toJSON = function(){ | ||
this.__type = 'Member'; | ||
return this; | ||
}; | ||
/** | ||
@@ -51,0 +58,0 @@ * Return a string representation of this node. |
@@ -11,10 +11,17 @@ var Node = require('./node') | ||
MozDocument.prototype.clone = function(){ | ||
MozDocument.prototype.clone = function(parent){ | ||
var clone = new MozDocument(this.val); | ||
clone.block = this.block.clone(); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
MozDocument.prototype.toJSON = function(){ | ||
this.__type = 'MozDocument'; | ||
return this; | ||
}; | ||
MozDocument.prototype.toString = function(){ | ||
return '@-moz-document ' + this.val; | ||
} |
@@ -17,215 +17,223 @@ | ||
/** | ||
* Node constructor. | ||
* Initialize a new `CoercionError` with the given `msg`. | ||
* | ||
* @api public | ||
* @param {String} msg | ||
* @api private | ||
*/ | ||
var Node = module.exports = function Node(){ | ||
this.lineno = nodes.lineno; | ||
Object.defineProperty(this, 'filename', { writable: true, value: nodes.filename }); | ||
}; | ||
function CoercionError(msg) { | ||
this.name = 'CoercionError' | ||
this.message = msg | ||
Error.captureStackTrace(this, CoercionError); | ||
} | ||
/** | ||
* Return this node. | ||
* | ||
* @return {Node} | ||
* @api public | ||
* Inherit from `Error.prototype`. | ||
*/ | ||
Node.prototype.__defineGetter__('first', function(){ | ||
return this; | ||
}); | ||
CoercionError.prototype.__proto__ = Error.prototype; | ||
/** | ||
* Return hash. | ||
* Node constructor. | ||
* | ||
* @return {String} | ||
* @api public | ||
*/ | ||
Node.prototype.__defineGetter__('hash', function(){ | ||
return this.val; | ||
}); | ||
var Node = module.exports = function Node(){ | ||
this.lineno = nodes.lineno; | ||
this.filename = nodes.filename; | ||
}; | ||
/** | ||
* Return node name. | ||
* | ||
* @return {String} | ||
* @api public | ||
*/ | ||
Node.prototype = { | ||
constructor: Node, | ||
Node.prototype.__defineGetter__('nodeName', function(){ | ||
return this.constructor.name.toLowerCase(); | ||
}); | ||
/** | ||
* Return this node. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
/** | ||
* Return this node. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
get first() { | ||
return this; | ||
}, | ||
Node.prototype.clone = function(){ | ||
return this; | ||
}; | ||
/** | ||
* Return hash. | ||
* | ||
* @return {String} | ||
* @api public | ||
*/ | ||
/** | ||
* Nodes by default evaluate to themselves. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
get hash() { | ||
return this.val; | ||
}, | ||
Node.prototype.eval = function(){ | ||
return new Evaluator(this).evaluate(); | ||
}; | ||
/** | ||
* Return node name. | ||
* | ||
* @return {String} | ||
* @api public | ||
*/ | ||
/** | ||
* Return true. | ||
* | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
get nodeName() { | ||
return this.constructor.name.toLowerCase(); | ||
}, | ||
Node.prototype.toBoolean = function(){ | ||
return nodes.true; | ||
}; | ||
/** | ||
* Return this node. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
/** | ||
* Return the expression, or wrap this node in an expression. | ||
* | ||
* @return {Expression} | ||
* @api public | ||
*/ | ||
clone: function(){ | ||
return this; | ||
}, | ||
Node.prototype.toExpression = function(){ | ||
if ('expression' == this.nodeName) return this; | ||
var expr = new nodes.Expression; | ||
expr.push(this); | ||
return expr; | ||
}; | ||
toJSON: function(){ | ||
return this; | ||
}, | ||
/** | ||
* Return false if `op` is generally not coerced. | ||
* | ||
* @param {String} op | ||
* @return {Boolean} | ||
* @api private | ||
*/ | ||
/** | ||
* Nodes by default evaluate to themselves. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
Node.prototype.shouldCoerce = function(op){ | ||
switch (op) { | ||
case 'is a': | ||
case 'in': | ||
case '||': | ||
case '&&': | ||
return false; | ||
default: | ||
return true; | ||
} | ||
}; | ||
eval: function(){ | ||
return new Evaluator(this).evaluate(); | ||
}, | ||
/** | ||
* Operate on `right` with the given `op`. | ||
* | ||
* @param {String} op | ||
* @param {Node} right | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
/** | ||
* Return true. | ||
* | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
Node.prototype.operate = function(op, right){ | ||
switch (op) { | ||
case 'is a': | ||
if ('string' == right.nodeName) { | ||
return nodes.Boolean(this.nodeName == right.val); | ||
} else { | ||
throw new Error('"is a" expects a string, got ' + right.toString()); | ||
} | ||
case '==': | ||
return nodes.Boolean(this.hash == right.hash); | ||
case '!=': | ||
return nodes.Boolean(this.hash != right.hash); | ||
case '>=': | ||
return nodes.Boolean(this.hash >= right.hash); | ||
case '<=': | ||
return nodes.Boolean(this.hash <= right.hash); | ||
case '>': | ||
return nodes.Boolean(this.hash > right.hash); | ||
case '<': | ||
return nodes.Boolean(this.hash < right.hash); | ||
case '||': | ||
return this.toBoolean().isTrue | ||
? this | ||
: right; | ||
case 'in': | ||
var vals = utils.unwrap(right).nodes | ||
, len = vals.length | ||
, hash = this.hash; | ||
if (!vals) throw new Error('"in" given invalid right-hand operand, expecting an expression'); | ||
toBoolean: function(){ | ||
return nodes.true; | ||
}, | ||
// 'prop' in obj | ||
if (1 == len && 'object' == vals[0].nodeName) { | ||
return nodes.Boolean(vals[0].has(this.hash)); | ||
} | ||
/** | ||
* Return the expression, or wrap this node in an expression. | ||
* | ||
* @return {Expression} | ||
* @api public | ||
*/ | ||
for (var i = 0; i < len; ++i) { | ||
if (hash == vals[i].hash) { | ||
return nodes.true; | ||
toExpression: function(){ | ||
if ('expression' == this.nodeName) return this; | ||
var expr = new nodes.Expression; | ||
expr.push(this); | ||
return expr; | ||
}, | ||
/** | ||
* Return false if `op` is generally not coerced. | ||
* | ||
* @param {String} op | ||
* @return {Boolean} | ||
* @api private | ||
*/ | ||
shouldCoerce: function(op){ | ||
switch (op) { | ||
case 'is a': | ||
case 'in': | ||
case '||': | ||
case '&&': | ||
return false; | ||
default: | ||
return true; | ||
} | ||
}, | ||
/** | ||
* Operate on `right` with the given `op`. | ||
* | ||
* @param {String} op | ||
* @param {Node} right | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
operate: function(op, right){ | ||
switch (op) { | ||
case 'is a': | ||
if ('string' == right.nodeName) { | ||
return nodes.Boolean(this.nodeName == right.val); | ||
} else { | ||
throw new Error('"is a" expects a string, got ' + right.toString()); | ||
} | ||
} | ||
return nodes.false; | ||
case '&&': | ||
var a = this.toBoolean() | ||
, b = right.toBoolean(); | ||
return a.isTrue && b.isTrue | ||
? right | ||
: a.isFalse | ||
case '==': | ||
return nodes.Boolean(this.hash == right.hash); | ||
case '!=': | ||
return nodes.Boolean(this.hash != right.hash); | ||
case '>=': | ||
return nodes.Boolean(this.hash >= right.hash); | ||
case '<=': | ||
return nodes.Boolean(this.hash <= right.hash); | ||
case '>': | ||
return nodes.Boolean(this.hash > right.hash); | ||
case '<': | ||
return nodes.Boolean(this.hash < right.hash); | ||
case '||': | ||
return this.toBoolean().isTrue | ||
? this | ||
: right; | ||
default: | ||
if ('[]' == op) { | ||
var msg = 'cannot perform ' | ||
+ this | ||
+ '[' + right + ']'; | ||
} else { | ||
var msg = 'cannot perform' | ||
+ ' ' + this | ||
+ ' ' + op | ||
+ ' ' + right; | ||
} | ||
throw new Error(msg); | ||
} | ||
}; | ||
case 'in': | ||
var vals = utils.unwrap(right).nodes | ||
, len = vals && vals.length | ||
, hash = this.hash; | ||
if (!vals) throw new Error('"in" given invalid right-hand operand, expecting an expression'); | ||
/** | ||
* Initialize a new `CoercionError` with the given `msg`. | ||
* | ||
* @param {String} msg | ||
* @api private | ||
*/ | ||
// 'prop' in obj | ||
if (1 == len && 'object' == vals[0].nodeName) { | ||
return nodes.Boolean(vals[0].has(this.hash)); | ||
} | ||
function CoercionError(msg) { | ||
this.name = 'CoercionError' | ||
this.message = msg | ||
Error.captureStackTrace(this, CoercionError); | ||
} | ||
for (var i = 0; i < len; ++i) { | ||
if (hash == vals[i].hash) { | ||
return nodes.true; | ||
} | ||
} | ||
return nodes.false; | ||
case '&&': | ||
var a = this.toBoolean() | ||
, b = right.toBoolean(); | ||
return a.isTrue && b.isTrue | ||
? right | ||
: a.isFalse | ||
? this | ||
: right; | ||
default: | ||
if ('[]' == op) { | ||
var msg = 'cannot perform ' | ||
+ this | ||
+ '[' + right + ']'; | ||
} else { | ||
var msg = 'cannot perform' | ||
+ ' ' + this | ||
+ ' ' + op | ||
+ ' ' + right; | ||
} | ||
throw new Error(msg); | ||
} | ||
}, | ||
/** | ||
* Inherit from `Error.prototype`. | ||
*/ | ||
/** | ||
* Default coercion throws. | ||
* | ||
* @param {Node} other | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
CoercionError.prototype.__proto__ = Error.prototype; | ||
/** | ||
* Default coercion throws. | ||
* | ||
* @param {Node} other | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
Node.prototype.coerce = function(other){ | ||
if (other.nodeName == this.nodeName) return other; | ||
throw new CoercionError('cannot coerce ' + other + ' to ' + this.nodeName); | ||
coerce: function(other){ | ||
if (other.nodeName == this.nodeName) return other; | ||
throw new CoercionError('cannot coerce ' + other + ' to ' + this.nodeName); | ||
} | ||
}; |
@@ -72,2 +72,7 @@ | ||
return null; | ||
}); | ||
}); | ||
Null.prototype.toJSON = function(){ | ||
this.__type = 'Null'; | ||
return this; | ||
}; |
@@ -148,3 +148,3 @@ | ||
Object.prototype.clone = function(){ | ||
Object.prototype.clone = function(parent){ | ||
var clone = new Object; | ||
@@ -154,3 +154,3 @@ clone.lineno = this.lineno; | ||
for (var key in this.vals) { | ||
clone.vals[key] = this.vals[key].clone(); | ||
clone.vals[key] = this.vals[key].clone(parent, clone); | ||
} | ||
@@ -160,2 +160,7 @@ return clone; | ||
Object.prototype.toJSON = function(){ | ||
this.__type = 'Object'; | ||
return this; | ||
}; | ||
/** | ||
@@ -162,0 +167,0 @@ * Return "{ <prop>: <val> }" |
@@ -35,2 +35,23 @@ | ||
/** | ||
* Return a clone of this node. | ||
* | ||
* @return {Node} | ||
* @api public | ||
*/ | ||
Page.prototype.clone = function(parent){ | ||
var clone = new Page; | ||
clone.selector = this.selector && this.selector.clone(parent, clone); | ||
clone.block = this.block.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
Page.prototype.toJSON = function(){ | ||
this.__type = 'Page'; | ||
return this; | ||
}; | ||
/** | ||
* Return `@page name`. | ||
@@ -37,0 +58,0 @@ * |
@@ -63,3 +63,3 @@ | ||
Params.prototype.clone = function(){ | ||
Params.prototype.clone = function(parent){ | ||
var clone = new Params; | ||
@@ -69,3 +69,3 @@ clone.lineno = this.lineno; | ||
this.nodes.forEach(function(node){ | ||
clone.push(node.clone()); | ||
clone.push(node.clone(parent, clone)); | ||
}); | ||
@@ -75,1 +75,6 @@ return clone; | ||
Params.prototype.toJSON = function(){ | ||
this.__type = 'Params'; | ||
return this; | ||
}; | ||
@@ -41,3 +41,3 @@ | ||
Property.prototype.clone = function(){ | ||
Property.prototype.clone = function(parent){ | ||
var clone = new Property(this.segments); | ||
@@ -47,7 +47,12 @@ clone.name = this.name; | ||
clone.filename = this.filename; | ||
clone.segments = this.segments.map(function(node){ return node.clone(); }); | ||
if (this.expr) clone.expr = this.expr.clone(); | ||
clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); }); | ||
if (this.expr) clone.expr = this.expr.clone(parent, clone); | ||
return clone; | ||
}; | ||
Property.prototype.toJSON = function(){ | ||
this.__type = 'Property'; | ||
return this; | ||
}; | ||
/** | ||
@@ -54,0 +59,0 @@ * Return string representation of this node. |
@@ -40,6 +40,6 @@ | ||
QueryExpr.prototype.clone = function(){ | ||
QueryExpr.prototype.clone = function(parent){ | ||
var clone = new QueryExpr; | ||
clone.segments = this.segments.map(function(node){ return node.clone(); }); | ||
if (this.expr) clone.expr = this.expr.clone(); | ||
clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); }); | ||
if (this.expr) clone.expr = this.expr.clone(parent, clone); | ||
if (this.name) clone.name = this.name; | ||
@@ -46,0 +46,0 @@ clone.lineno = this.lineno; |
@@ -38,3 +38,3 @@ | ||
QueryList.prototype.clone = function(){ | ||
QueryList.prototype.clone = function(parent){ | ||
var clone = new QueryList; | ||
@@ -44,3 +44,3 @@ clone.lineno = this.lineno; | ||
for (var i = 0; i < this.nodes.length; ++i) { | ||
clone.push(this.nodes[i].clone()); | ||
clone.push(this.nodes[i].clone(parent, clone)); | ||
} | ||
@@ -47,0 +47,0 @@ return clone; |
@@ -40,7 +40,7 @@ | ||
Query.prototype.clone = function(){ | ||
Query.prototype.clone = function(parent){ | ||
var clone = new Query; | ||
clone.predicate = this.predicate; | ||
for (var i = 0, len = this.nodes.length; i < len; ++i) { | ||
clone.push(this.nodes[i].clone()); | ||
clone.push(this.nodes[i].clone(parent, clone)); | ||
} | ||
@@ -47,0 +47,0 @@ clone.lineno = this.lineno; |
@@ -39,7 +39,13 @@ | ||
Return.prototype.clone = function(){ | ||
var clone = new Return(this.expr.clone()); | ||
Return.prototype.clone = function(parent){ | ||
var clone = new Return(); | ||
clone.expr = this.expr.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
}; | ||
Return.prototype.toJSON = function(){ | ||
this.__type = 'Return'; | ||
return this; | ||
}; |
@@ -15,3 +15,3 @@ | ||
, functions = require('../functions') | ||
, adjust = functions['-adjust'] | ||
, adjust = functions.adjust | ||
, nodes = require('./'); | ||
@@ -77,2 +77,3 @@ | ||
, this.a); | ||
clone.raw = this.raw; | ||
clone.lineno = this.lineno; | ||
@@ -83,2 +84,7 @@ clone.filename = this.filename; | ||
RGBA.prototype.toJSON = function(){ | ||
this.__type = 'RGBA'; | ||
return this; | ||
}; | ||
/** | ||
@@ -85,0 +91,0 @@ * Return true. |
@@ -62,1 +62,6 @@ | ||
}; | ||
Root.prototype.toJSON = function(){ | ||
this.__type = 'Root'; | ||
return this; | ||
}; |
@@ -63,8 +63,14 @@ | ||
Selector.prototype.clone = function(){ | ||
Selector.prototype.clone = function(parent){ | ||
var clone = new Selector; | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
clone.segments = this.segments.map(function(node){ return node.clone(); }); | ||
clone.inherits = this.inherits; | ||
clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); }); | ||
return clone; | ||
}; | ||
Selector.prototype.toJSON = function(){ | ||
this.__type = 'Selector'; | ||
return this; | ||
}; |
@@ -67,2 +67,7 @@ /*! | ||
String.prototype.toJSON = function(){ | ||
this.__type = 'String'; | ||
return this; | ||
}; | ||
/** | ||
@@ -69,0 +74,0 @@ * Return Boolean based on the length of this string. |
@@ -43,10 +43,15 @@ | ||
Ternary.prototype.clone = function(){ | ||
var clone = new Ternary( | ||
this.cond.clone() | ||
, this.trueExpr.clone() | ||
, this.falseExpr.clone()); | ||
Ternary.prototype.clone = function(parent){ | ||
var clone = new Ternary(); | ||
clone.cond = this.cond.clone(parent, clone); | ||
clone.trueExpr = this.trueExpr.clone(parent, clone); | ||
clone.falseExpr = this.falseExpr.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
}; | ||
Ternary.prototype.toJSON = function(){ | ||
this.__type = 'Ternary'; | ||
return this; | ||
}; |
@@ -41,7 +41,13 @@ | ||
UnaryOp.prototype.clone = function(){ | ||
var clone = new UnaryOp(this.op, this.expr.clone()); | ||
UnaryOp.prototype.clone = function(parent){ | ||
var clone = new UnaryOp(this.op); | ||
clone.expr = this.expr.clone(parent, clone); | ||
clone.lineno = this.lineno; | ||
clone.filename = this.filename; | ||
return clone; | ||
}; | ||
}; | ||
UnaryOp.prototype.toJSON = function(){ | ||
this.__type = 'UnaryOp'; | ||
return this; | ||
}; |
@@ -16,2 +16,16 @@ | ||
/** | ||
* Unit conversion table. | ||
*/ | ||
var FACTOR_TABLE = { | ||
'mm': {val: 1, label: 'mm'}, | ||
'cm': {val: 10, label: 'mm'}, | ||
'in': {val: 25.4, label: 'mm'}, | ||
'ms': {val: 1, label: 'ms'}, | ||
's': {val: 1000, label: 'ms'}, | ||
'Hz': {val: 1, label: 'Hz'}, | ||
'kHz': {val: 1000, label: 'Hz'} | ||
}; | ||
/** | ||
* Initialize a new `Unit` with the given `val` and unit `type` | ||
@@ -77,2 +91,7 @@ * such as "px", "pt", "in", etc. | ||
Unit.prototype.toJSON = function(){ | ||
this.__type = 'Unit'; | ||
return this; | ||
}; | ||
/** | ||
@@ -164,4 +183,4 @@ * Operate on `right` with the given `op`. | ||
, b = other | ||
, factorA = factor(a) | ||
, factorB = factor(b); | ||
, factorA = FACTOR_TABLE[a.type] | ||
, factorB = FACTOR_TABLE[b.type]; | ||
@@ -182,20 +201,1 @@ if (factorA && factorB && (factorA.label == factorB.label)) { | ||
}; | ||
/** | ||
* Convert a unit to base unit | ||
*/ | ||
function factor(unit) { | ||
var factorTable = { | ||
'mm': {val: 1, label: 'mm'}, | ||
'cm': {val: 10, label: 'mm'}, | ||
'in': {val: 25.4, label: 'mm'}, | ||
'ms': {val: 1, label: 'ms'}, | ||
's': {val: 1000, label: 'ms'}, | ||
'Hz': {val: 1, label: 'Hz'}, | ||
'kHz': {val: 1000, label: 'Hz'} | ||
}; | ||
return factorTable[unit.type]; | ||
}; | ||
@@ -16,3 +16,4 @@ | ||
, inspect = require('util').inspect | ||
, errors = require('./errors'); | ||
, errors = require('./errors') | ||
, cache = require('./cache'); | ||
@@ -153,3 +154,9 @@ // debuggers | ||
options = options || {}; | ||
this.lexer = new Lexer(str, options); | ||
Parser.cache = Parser.cache || cache(false !== options.cache | ||
? options.cache || 'memory' | ||
: false, options); | ||
this.hash = Parser.cache.key(str, options); | ||
if (!Parser.cache.has(this.hash)) { | ||
this.lexer = new Lexer(str, options); | ||
} | ||
this.prefix = options.prefix || ''; | ||
@@ -209,8 +216,13 @@ this.root = options.root || new nodes.Root; | ||
var block = this.parent = this.root; | ||
while ('eos' != this.peek().type) { | ||
if (this.accept('newline')) continue; | ||
var stmt = this.statement(); | ||
this.accept(';'); | ||
if (!stmt) this.error('unexpected token {peek}, not allowed at the root level'); | ||
block.push(stmt); | ||
if (Parser.cache.has(this.hash)) { | ||
block = Parser.cache.get(this.hash); | ||
} else { | ||
while ('eos' != this.peek().type) { | ||
if (this.accept('newline')) continue; | ||
var stmt = this.statement(); | ||
this.accept(';'); | ||
if (!stmt) this.error('unexpected token {peek}, not allowed at the root level'); | ||
block.push(stmt); | ||
} | ||
Parser.cache.set(this.hash, block); | ||
} | ||
@@ -617,3 +629,3 @@ return block; | ||
if (this.allowPostfix) { | ||
delete this.allowPostfix; | ||
this.allowPostfix = false; | ||
state = 'expression'; | ||
@@ -1506,3 +1518,3 @@ } | ||
/** | ||
* '+'? ident '(' expression ')' | ||
* '+'? ident '(' expression ')' block? | ||
*/ | ||
@@ -1509,0 +1521,0 @@ |
@@ -429,14 +429,17 @@ | ||
var HIDDEN_SELECTOR_RX = /^\s*\/?\$/ | ||
, ROOT_SELECTOR_RX = /^\//g | ||
, PARENT_SELECTOR_RX = /&/g; | ||
exports.compileSelectors = function(arr, leaveHidden){ | ||
var self = this | ||
, selectors = [] | ||
, buf = [] | ||
, hiddenSelectorRegexp = /^\s*\/?\$/; | ||
, buf = []; | ||
function interpolateParent(selector, buf) { | ||
var str = selector.val.replace(/^\//g, '').trim(); | ||
var str = selector.val.replace(ROOT_SELECTOR_RX, '').trim(); | ||
if (buf.length) { | ||
for (var i = 0, len = buf.length; i < len; ++i) { | ||
if (~buf[i].indexOf('&') || '/' === buf[i].charAt(0)) { | ||
str = buf[i].replace(/&/g, str).replace(/^\//g, '').trim(); | ||
str = buf[i].replace(PARENT_SELECTOR_RX, str).replace(ROOT_SELECTOR_RX, '').trim(); | ||
} else { | ||
@@ -453,3 +456,3 @@ str += ' ' + buf[i].trim(); | ||
arr[i].forEach(function(selector){ | ||
if (!leaveHidden && selector.val.match(hiddenSelectorRegexp)) return; | ||
if (!leaveHidden && selector.val.match(HIDDEN_SELECTOR_RX)) return; | ||
if (selector.inherits) { | ||
@@ -465,5 +468,5 @@ buf.unshift(selector.val); | ||
arr[0].forEach(function(selector){ | ||
if (!leaveHidden && selector.val.match(hiddenSelectorRegexp)) return; | ||
if (!leaveHidden && selector.val.match(HIDDEN_SELECTOR_RX)) return; | ||
var str = interpolateParent(selector, buf); | ||
if (~str.indexOf('&')) str = str.replace(/&/g, '').trim(); | ||
if (~str.indexOf('&')) str = str.replace(PARENT_SELECTOR_RX, '').trim(); | ||
if (!str.length) return; | ||
@@ -470,0 +473,0 @@ selectors.push((self.indent || '') + str.trimRight()); |
@@ -38,3 +38,2 @@ /*! | ||
this.stack = []; | ||
this.js = ''; | ||
}; | ||
@@ -103,3 +102,2 @@ | ||
case 'function': | ||
case 'jsliteral': | ||
case 'group': | ||
@@ -276,11 +274,2 @@ case 'unit': | ||
/** | ||
* Visit JSLiteral. | ||
*/ | ||
Compiler.prototype.visitJSLiteral = function(js){ | ||
this.js += '\n' + js.val.replace(/@selector/g, '"' + this.selector + '"'); | ||
return ''; | ||
}; | ||
/** | ||
* Visit Comment. | ||
@@ -287,0 +276,0 @@ */ |
@@ -96,3 +96,3 @@ | ||
// Evaluate imported "root" | ||
block.parent = this.root; | ||
block = block.clone(this.root); | ||
block.scope = false; | ||
@@ -685,3 +685,3 @@ var ret = this.visit(block); | ||
var ret = this.visit(new nodes.Call(name, args)); | ||
delete this.property; | ||
this.property = null; | ||
return ret; | ||
@@ -695,3 +695,3 @@ // Regular property | ||
prop.expr = this.visit(prop.expr); | ||
delete this.property; | ||
this.property = null; | ||
this.return--; | ||
@@ -902,8 +902,6 @@ return prop; | ||
var block = new nodes.Block(fn.block.parent); | ||
fn.block.parent = block; | ||
// Clone the function body | ||
// to prevent mutation of subsequent calls | ||
var body = fn.block.clone(); | ||
body.scope = fn.block.hasMedia; | ||
var body = fn.block.clone(block); | ||
@@ -910,0 +908,0 @@ // mixin block |
@@ -70,3 +70,2 @@ | ||
case 'function': | ||
case 'jsliteral': | ||
case 'unit': | ||
@@ -99,3 +98,2 @@ case 'atblock': | ||
case 'function': | ||
case 'jsliteral': | ||
case 'group': | ||
@@ -172,3 +170,3 @@ case 'unit': | ||
var selfSelector = new nodes.Selector(selfLiteral); | ||
var selfSelector = new nodes.Selector([selfLiteral]); | ||
selfSelector.lineno = media.lineno; | ||
@@ -175,0 +173,0 @@ selfSelector.filename = media.filename; |
{ | ||
"name": "stylus", | ||
"description": "Robust, expressive, and feature-rich CSS superset", | ||
"version": "0.43.0", | ||
"version": "0.44.0-beta", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -32,3 +32,4 @@ "keywords": [ | ||
"sax": "0.5.x", | ||
"glob": "3.2.x" | ||
"glob": "3.2.x", | ||
"circular-json": "0.1.x" | ||
}, | ||
@@ -35,0 +36,0 @@ "devDependencies": { |
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
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
293827
76
11124
6
16
+ Addedcircular-json@0.1.x
+ Addedcircular-json@0.1.6(transitive)
+ Addedwru@0.3.0(transitive)