Comparing version 0.7.3 to 0.7.4
0.7.4 / 2011-03-10 | ||
================== | ||
* Added `RGBA` node | ||
* Added `is a "color"` special-case, true for `HSLA` and `RGBA` nodes. | ||
Closes #180 | ||
* Performance; 2.5x faster compiles due to removing use of getters in `Parser` and `Lexer` (yes, they are really slow). | ||
* Removed `Color` node | ||
* Fixed stylus(1) `--watch` support due to dynamic __@import__ support. Closes #176 | ||
0.7.3 / 2011-03-09 | ||
@@ -3,0 +13,0 @@ ================== |
@@ -52,3 +52,3 @@ | ||
* | ||
* @param {Color|Unit} h | ||
* @param {RGBA|HSLA|Unit} h | ||
* @param {Unit} s | ||
@@ -65,3 +65,3 @@ * @param {Unit} l | ||
utils.assertColor(h); | ||
return h.hsl; | ||
return h.hsla; | ||
default: | ||
@@ -88,3 +88,3 @@ utils.assertType(h, nodes.Unit, 'hue'); | ||
* | ||
* @param {Color|Unit|HSLA} h | ||
* @param {Unit|HSLA|RGBA} h | ||
* @param {Unit} s | ||
@@ -101,3 +101,3 @@ * @param {Unit} l | ||
utils.assertColor(h, 'color'); | ||
return h.hsl; | ||
return h.hsla; | ||
}; | ||
@@ -140,3 +140,3 @@ | ||
* | ||
* @param {Color|HSLA} color | ||
* @param {RGBA|HSLA} color | ||
* @param {String} na,e | ||
@@ -165,3 +165,3 @@ * @return {Unit} | ||
* | ||
* @param {Color|HSLA} color | ||
* @param {RGBA|HSLA} color | ||
* @return {Unit} | ||
@@ -183,3 +183,3 @@ * @api public | ||
* | ||
* @param {Color|HSLA} color | ||
* @param {RGBA|HSLA} color | ||
* @return {Unit} | ||
@@ -201,3 +201,3 @@ * @api public | ||
* | ||
* @param {Color|HSLA} color | ||
* @param {RGBA|HSLA} color | ||
* @return {Unit} | ||
@@ -212,3 +212,3 @@ * @api public | ||
/** | ||
* Return a `Color` from the r,g,b,a channels. | ||
* Return a `RGBA` from the r,g,b,a channels. | ||
* | ||
@@ -226,7 +226,7 @@ * Examples: | ||
* | ||
* @param {Unit|Color|HSLA} r | ||
* @param {Unit|RGBA|HSLA} r | ||
* @param {Unit} g | ||
* @param {Unit} b | ||
* @param {Unit} a | ||
* @return {Color} | ||
* @return {RGBA} | ||
* @api public | ||
@@ -240,3 +240,3 @@ */ | ||
var color = r.rgba; | ||
return new nodes.Color( | ||
return new nodes.RGBA( | ||
color.r | ||
@@ -250,3 +250,3 @@ , color.g | ||
utils.assertType(g, nodes.Unit); | ||
return new nodes.Color( | ||
return new nodes.RGBA( | ||
color.r | ||
@@ -261,3 +261,3 @@ , color.g | ||
utils.assertType(a, nodes.Unit, 'alpha'); | ||
return new nodes.Color( | ||
return new nodes.RGBA( | ||
r.val | ||
@@ -271,3 +271,3 @@ , g.val | ||
/** | ||
* Return a `Color` from the r,g,b channels. | ||
* Return a `RGBA` from the r,g,b channels. | ||
* | ||
@@ -282,6 +282,6 @@ * Examples: | ||
* | ||
* @param {Unit|Color|HSLA} r | ||
* @param {Unit|RGBA|HSLA} r | ||
* @param {Unit} g | ||
* @param {Unit} b | ||
* @return {Color} | ||
* @return {RGBA} | ||
* @api public | ||
@@ -295,3 +295,3 @@ */ | ||
var color = r.rgba; | ||
return new nodes.Color( | ||
return new nodes.RGBA( | ||
color.r | ||
@@ -555,3 +555,3 @@ , color.g | ||
* | ||
* @param {Color|HSLA} color | ||
* @param {RGBA|HSLA} color | ||
* @param {String} prop | ||
@@ -564,3 +564,3 @@ * @param {Unit} amount | ||
exports['-adjust'] = function(color, prop, amount){ | ||
var hsl = color.hsl; | ||
var hsl = color.hsla; | ||
prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string]; | ||
@@ -567,0 +567,0 @@ if (!prop) throw new Error('invalid adjustment property'); |
127
lib/lexer.js
@@ -92,3 +92,3 @@ | ||
, buf = []; | ||
while ('eos' != (tok = this.next).type) { | ||
while ('eos' != (tok = this.next()).type) { | ||
buf.push(tok.inspect()); | ||
@@ -111,3 +111,3 @@ } | ||
var fetch = n - this.stash.length; | ||
while (fetch-- > 0) this.stash.push(this.advance); | ||
while (fetch-- > 0) this.stash.push(this.advance()); | ||
return this.stash[--n]; | ||
@@ -136,4 +136,4 @@ }, | ||
get next() { | ||
var tok = this.stashed || this.advance; | ||
next: function() { | ||
var tok = this.stashed() || this.advance(); | ||
switch (tok.type) { | ||
@@ -156,27 +156,27 @@ case 'newline': | ||
get advance() { | ||
return this.eos | ||
|| this.null | ||
|| this.sep | ||
|| this.keyword | ||
|| this.urlchars | ||
|| this.atrule | ||
|| this.media | ||
|| this.comment | ||
|| this.newline | ||
|| this.escaped | ||
|| this.important | ||
|| this.literal | ||
|| this.function | ||
|| this.brace | ||
|| this.paren | ||
|| this.color | ||
|| this.string | ||
|| this.unit | ||
|| this.namedop | ||
|| this.boolean | ||
|| this.ident | ||
|| this.op | ||
|| this.space | ||
|| this.selector; | ||
advance: function() { | ||
return this.eos() | ||
|| this.null() | ||
|| this.sep() | ||
|| this.keyword() | ||
|| this.urlchars() | ||
|| this.atrule() | ||
|| this.media() | ||
|| this.comment() | ||
|| this.newline() | ||
|| this.escaped() | ||
|| this.important() | ||
|| this.literal() | ||
|| this.function() | ||
|| this.brace() | ||
|| this.paren() | ||
|| this.color() | ||
|| this.string() | ||
|| this.unit() | ||
|| this.namedop() | ||
|| this.boolean() | ||
|| this.ident() | ||
|| this.op() | ||
|| this.space() | ||
|| this.selector(); | ||
}, | ||
@@ -191,3 +191,3 @@ | ||
get peek() { | ||
peek: function() { | ||
return this.lookahead(1); | ||
@@ -203,3 +203,3 @@ }, | ||
get stashed() { | ||
stashed: function() { | ||
return this.stash.shift(); | ||
@@ -212,3 +212,3 @@ }, | ||
get eos() { | ||
eos: function() { | ||
if (this.str.length) return; | ||
@@ -227,3 +227,3 @@ if (this.indentStack.length) { | ||
get urlchars() { | ||
urlchars: function() { | ||
var captures; | ||
@@ -241,3 +241,3 @@ if (!this.isURL) return; | ||
get sep() { | ||
sep: function() { | ||
var captures; | ||
@@ -254,3 +254,3 @@ if (captures = /^; */.exec(this.str)) { | ||
get space() { | ||
space: function() { | ||
var captures; | ||
@@ -267,3 +267,3 @@ if (captures = /^( +)/.exec(this.str)) { | ||
get escaped() { | ||
escaped: function() { | ||
var captures; | ||
@@ -281,3 +281,3 @@ if (captures = /^\\(.) */.exec(this.str)) { | ||
get literal() { | ||
literal: function() { | ||
// HACK attack !!! | ||
@@ -308,3 +308,3 @@ var captures; | ||
get important() { | ||
important: function() { | ||
var captures; | ||
@@ -321,3 +321,3 @@ if (captures = /^!important */.exec(this.str)) { | ||
get brace() { | ||
brace: function() { | ||
var captures; | ||
@@ -335,3 +335,3 @@ if (captures = /^([{}])/.exec(this.str)) { | ||
get paren() { | ||
paren: function() { | ||
var captures; | ||
@@ -350,3 +350,3 @@ if (captures = /^([()]) */.exec(this.str)) { | ||
get null() { | ||
null: function() { | ||
var captures; | ||
@@ -368,3 +368,3 @@ if (captures = /^(null)\b */.exec(this.str)) { | ||
get keyword() { | ||
keyword: function() { | ||
var captures; | ||
@@ -389,3 +389,3 @@ if (captures = /^(return|if|else|unless|for|in)\b */.exec(this.str)) { | ||
get namedop() { | ||
namedop: function() { | ||
var captures; | ||
@@ -437,3 +437,3 @@ if (captures = /^(not|and|or|is a|is defined|isnt|is not|is)\b( *)/.exec(this.str)) { | ||
get op() { | ||
op: function() { | ||
var captures; | ||
@@ -454,3 +454,3 @@ if (captures = /^([.]{2,3}|&&|\|\||[!<>=?]=|\*\*|[-+*\/%]=?|[,=?:!~<>&\[\]])( *)/.exec(this.str)) { | ||
get media() { | ||
media: function() { | ||
var captures; | ||
@@ -467,3 +467,3 @@ if (captures = /^@media *([^{\n]+)/.exec(this.str)) { | ||
get atrule() { | ||
atrule: function() { | ||
var captures; | ||
@@ -480,3 +480,3 @@ if (captures = /^@(import|keyframes|charset|page) */.exec(this.str)) { | ||
get comment() { | ||
comment: function() { | ||
// Single line | ||
@@ -487,3 +487,3 @@ if ('/' == this.str[0] && '/' == this.str[1]) { | ||
this.skip(end); | ||
return this.advance; | ||
return this.advance(); | ||
} | ||
@@ -501,3 +501,3 @@ | ||
? new Token('comment', str) | ||
: this.advance; | ||
: this.advance(); | ||
} | ||
@@ -510,3 +510,3 @@ }, | ||
get boolean() { | ||
boolean: function() { | ||
var captures; | ||
@@ -528,3 +528,3 @@ if (captures = /^(true|false)\b( *)/.exec(this.str)) { | ||
get function() { | ||
function: function() { | ||
var captures; | ||
@@ -545,3 +545,3 @@ if (captures = /^(-?[a-zA-Z$][-\w\d$]*)\(( *)/.exec(this.str)) { | ||
get ident() { | ||
ident: function() { | ||
var captures; | ||
@@ -559,3 +559,3 @@ if (captures = /^(-?[a-zA-Z$][-\w\d$]*)/.exec(this.str)) { | ||
get newline() { | ||
newline: function() { | ||
var captures, re; | ||
@@ -598,3 +598,3 @@ | ||
++this.lineno; | ||
return this.advance; | ||
return this.advance(); | ||
} | ||
@@ -626,3 +626,3 @@ | ||
get unit() { | ||
unit: function() { | ||
var captures; | ||
@@ -642,3 +642,3 @@ if (captures = unit.exec(this.str)) { | ||
get string() { | ||
string: function() { | ||
var captures; | ||
@@ -656,4 +656,5 @@ if (captures = /^("[^"]*"|'[^']*') */.exec(this.str)) { | ||
get color() { | ||
return this.hex6 || this.hex3; | ||
color: function() { | ||
return this.hex6() | ||
|| this.hex3(); | ||
}, | ||
@@ -665,3 +666,3 @@ | ||
get hex3() { | ||
hex3: function() { | ||
var captures; | ||
@@ -674,3 +675,3 @@ if (captures = /^#([a-fA-F0-9]{3}) */.exec(this.str)) { | ||
, b = parseInt(rgb[2] + rgb[2], 16) | ||
, color = new nodes.Color(r, g, b, 1); | ||
, color = new nodes.RGBA(r, g, b, 1); | ||
color.raw = captures[0]; | ||
@@ -685,3 +686,3 @@ return new Token('color', color); | ||
get hex6() { | ||
hex6: function() { | ||
var captures; | ||
@@ -694,3 +695,3 @@ if (captures = /^#([a-fA-F0-9]{6}) */.exec(this.str)) { | ||
, b = parseInt(rgb.substr(4, 2), 16) | ||
, color = new nodes.Color(r, g, b, 1); | ||
, color = new nodes.RGBA(r, g, b, 1); | ||
color.raw = captures[0]; | ||
@@ -705,3 +706,3 @@ return new Token('color', color); | ||
get selector() { | ||
selector: function() { | ||
var captures; | ||
@@ -708,0 +709,0 @@ if (captures = /^[^{\n,]+/.exec(this.str)) { |
@@ -31,3 +31,3 @@ | ||
this.a = clampAlpha(a); | ||
this.hsl = this; | ||
this.hsla = this; | ||
}; | ||
@@ -74,5 +74,5 @@ | ||
/** | ||
* Return rgba `Color` representation. | ||
* Return rgba `RGBA` representation. | ||
* | ||
* @return {Color} | ||
* @return {RGBA} | ||
* @api public | ||
@@ -82,3 +82,3 @@ */ | ||
HSLA.prototype.__defineGetter__('rgba', function(){ | ||
return nodes.Color.fromHSLA(this); | ||
return nodes.RGBA.fromHSLA(this); | ||
}); | ||
@@ -98,3 +98,3 @@ | ||
/** | ||
* Coerce color to HSLA. | ||
* Coerce RGBA to HSLA. | ||
* | ||
@@ -107,4 +107,4 @@ * @param {Node} other | ||
HSLA.prototype.coerce = function(other){ | ||
if (other instanceof nodes.Color) { | ||
return other.hsl; | ||
if (other instanceof nodes.RGBA) { | ||
return other.hsla; | ||
} else { | ||
@@ -162,3 +162,3 @@ return Node.prototype.coerce.call(this, other); | ||
* | ||
* @param {Color} color | ||
* @param {RGBA} color | ||
* @return {HSLA} | ||
@@ -168,7 +168,7 @@ * @api public | ||
exports.fromColor = function(color){ | ||
var r = color.r / 255 | ||
, g = color.g / 255 | ||
, b = color.b / 255 | ||
, a = color.a; | ||
exports.fromRGBA = function(rgba){ | ||
var r = rgba.r / 255 | ||
, g = rgba.g / 255 | ||
, b = rgba.b / 255 | ||
, a = rgba.a; | ||
@@ -175,0 +175,0 @@ var min = Math.min(r,g,b) |
@@ -26,3 +26,3 @@ | ||
exports.HSLA = require('./hsla'); | ||
exports.Color = require('./color'); | ||
exports.RGBA = require('./rgba'); | ||
exports.Ident = require('./ident'); | ||
@@ -29,0 +29,0 @@ exports.Group = require('./group'); |
@@ -107,3 +107,7 @@ | ||
if ('string' == right.nodeName) { | ||
return nodes.Boolean(this.nodeName == right.val); | ||
if ('color' == right.string) { | ||
return nodes.Boolean('rgba' == this.nodeName || 'hsla' == this.nodeName); | ||
} else { | ||
return nodes.Boolean(this.nodeName == right.val); | ||
} | ||
} else { | ||
@@ -110,0 +114,0 @@ throw new Error('"is a" expects a string, got ' + right.nodeName); |
@@ -114,3 +114,3 @@ | ||
get currentState() { | ||
currentState: function() { | ||
return this.state[this.state.length - 1]; | ||
@@ -128,5 +128,5 @@ }, | ||
var block = this.parent = this.root; | ||
while ('eos' != this.peek.type) { | ||
while ('eos' != this.peek().type) { | ||
if (this.accept('newline')) continue; | ||
var stmt = this.statement; | ||
var stmt = this.statement(); | ||
this.accept(';'); | ||
@@ -147,6 +147,6 @@ if (!stmt) this.error('unexpected token {peek}, not allowed at the root level'); | ||
error: function(msg){ | ||
var type = this.peek.type | ||
, val = undefined == this.peek.val | ||
var type = this.peek().type | ||
, val = undefined == this.peek().val | ||
? '' | ||
: ' ' + this.peek.toString(); | ||
: ' ' + this.peek().toString(); | ||
if (val.trim() == type.trim()) val = ''; | ||
@@ -166,4 +166,4 @@ throw new Error(msg.replace('{peek}', type + val)); | ||
accept: function(type){ | ||
if (type == this.peek.type) { | ||
return this.next; | ||
if (type == this.peek().type) { | ||
return this.next(); | ||
} | ||
@@ -181,6 +181,6 @@ }, | ||
expect: function(type){ | ||
if (type != this.peek.type) { | ||
throw new Error('expected ' + type + ', got ' + this.peek); | ||
if (type != this.peek().type) { | ||
throw new Error('expected ' + type + ', got ' + this.peek()); | ||
} | ||
return this.next; | ||
return this.next(); | ||
}, | ||
@@ -195,4 +195,4 @@ | ||
get next() { | ||
var tok = this.lexer.next; | ||
next: function() { | ||
var tok = this.lexer.next(); | ||
nodes.lineno = tok.lineno; | ||
@@ -209,4 +209,4 @@ return tok; | ||
get peek() { | ||
return this.lexer.peek; | ||
peek: function() { | ||
return this.lexer.peek(); | ||
}, | ||
@@ -266,4 +266,4 @@ | ||
get selectorToken() { | ||
if (this.isSelectorToken(1)) return this.next; | ||
selectorToken: function() { | ||
if (this.isSelectorToken(1)) return this.next(); | ||
}, | ||
@@ -275,5 +275,5 @@ | ||
get skipWhitespace() { | ||
while (~['space', 'indent', 'outdent', 'newline'].indexOf(this.peek.type)) | ||
this.next; | ||
skipWhitespace: function() { | ||
while (~['space', 'indent', 'outdent', 'newline'].indexOf(this.peek().type)) | ||
this.next(); | ||
}, | ||
@@ -285,5 +285,5 @@ | ||
get skipSpaces() { | ||
while ('space' == this.peek.type) | ||
this.next; | ||
skipSpaces: function() { | ||
while ('space' == this.peek().type) | ||
this.next(); | ||
}, | ||
@@ -307,3 +307,3 @@ | ||
get looksLikeSelector() { | ||
looksLikeSelector: function() { | ||
var i = 1; | ||
@@ -363,5 +363,5 @@ | ||
get statement() { | ||
statement: function() { | ||
var op | ||
, stmt = this.stmt | ||
, stmt = this.stmt() | ||
, state = this.prevState; | ||
@@ -384,3 +384,3 @@ | ||
if (op = this.accept('if') || this.accept('unless')) { | ||
stmt = new nodes.If(this.expression, stmt); | ||
stmt = new nodes.If(this.expression(), stmt); | ||
stmt.negate = 'unless' == op.type; | ||
@@ -410,4 +410,4 @@ this.accept(';'); | ||
get stmt() { | ||
var type = this.peek.type; | ||
stmt: function() { | ||
var type = this.peek().type; | ||
switch (type) { | ||
@@ -426,10 +426,10 @@ case 'selector': | ||
case 'if': | ||
return this[type]; | ||
return this[type](); | ||
case 'return': | ||
return this.return; | ||
return this.return(); | ||
case '{': | ||
return this.property; | ||
return this.property(); | ||
default: | ||
// Contextual selectors | ||
switch (this.currentState) { | ||
switch (this.currentState()) { | ||
case 'root': | ||
@@ -452,3 +452,3 @@ case 'selector': | ||
case '[': | ||
return this.selector; | ||
return this.selector(); | ||
} | ||
@@ -458,3 +458,3 @@ } | ||
// Expression fallback | ||
var expr = this.expression; | ||
var expr = this.expression(); | ||
if (expr.isEmpty) this.error('unexpected {peek}'); | ||
@@ -480,3 +480,3 @@ return expr; | ||
delim = '}'; | ||
this.skipWhitespace; | ||
this.skipWhitespace(); | ||
} else { | ||
@@ -487,12 +487,12 @@ delim = 'outdent'; | ||
while (delim != this.peek.type) { | ||
while (delim != this.peek().type) { | ||
// css-style | ||
if (this.css) { | ||
if (this.accept('newline')) continue; | ||
stmt = this.statement; | ||
stmt = this.statement(); | ||
this.accept(';'); | ||
this.skipWhitespace; | ||
this.skipWhitespace(); | ||
} else { | ||
if (this.accept('newline')) continue; | ||
stmt = this.statement; | ||
stmt = this.statement(); | ||
this.accept(';'); | ||
@@ -506,5 +506,5 @@ } | ||
if (this.css) { | ||
this.skipWhitespace; | ||
this.skipWhitespace(); | ||
this.expect('}'); | ||
this.skipSpaces; | ||
this.skipSpaces(); | ||
this.css = _; | ||
@@ -523,9 +523,9 @@ } else { | ||
get for() { | ||
for: function() { | ||
this.expect('for'); | ||
var key | ||
, val = this.id.name; | ||
if (this.accept(',')) key = this.id.name; | ||
, val = this.id().name; | ||
if (this.accept(',')) key = this.id().name; | ||
this.expect('in'); | ||
var each = new nodes.Each(val, key, this.expression); | ||
var each = new nodes.Each(val, key, this.expression()); | ||
this.state.push('for'); | ||
@@ -541,5 +541,5 @@ each.block = this.block(each); | ||
get return() { | ||
return: function() { | ||
this.expect('return'); | ||
var expr = this.expression; | ||
var expr = this.expression(); | ||
return expr.isEmpty | ||
@@ -554,5 +554,5 @@ ? new nodes.Return | ||
get unless() { | ||
unless: function() { | ||
this.expect('unless'); | ||
var node = new nodes.If(this.expression, true); | ||
var node = new nodes.If(this.expression(), true); | ||
this.state.push('conditional'); | ||
@@ -568,5 +568,5 @@ node.block = this.block(node, false); | ||
get if() { | ||
if: function() { | ||
this.expect('if'); | ||
var node = new nodes.If(this.expression); | ||
var node = new nodes.If(this.expression()); | ||
this.state.push('conditional'); | ||
@@ -576,3 +576,3 @@ node.block = this.block(node, false); | ||
if (this.accept('if')) { | ||
var cond = this.expression | ||
var cond = this.expression() | ||
, block = this.block(node, false); | ||
@@ -593,3 +593,3 @@ node.elses.push(new nodes.If(cond, block)); | ||
get media() { | ||
media: function() { | ||
var val = this.expect('media').val | ||
@@ -607,6 +607,6 @@ , media = new nodes.Media(val); | ||
get import() { | ||
import: function() { | ||
this.expect('import'); | ||
this.allowPostfix = true; | ||
return new nodes.Import(this.expression); | ||
return new nodes.Import(this.expression()); | ||
}, | ||
@@ -618,3 +618,3 @@ | ||
get charset() { | ||
charset: function() { | ||
this.expect('charset'); | ||
@@ -630,3 +630,3 @@ var str = this.expect('string').val; | ||
get page() { | ||
page: function() { | ||
var selector; | ||
@@ -649,11 +649,11 @@ this.expect('page'); | ||
get keyframes() { | ||
keyframes: function() { | ||
this.expect('keyframes'); | ||
var pos | ||
, _ = this.css | ||
, keyframes = new nodes.Keyframes(this.id); | ||
, keyframes = new nodes.Keyframes(this.id()); | ||
// css-sty;e | ||
if (this.css = this.accept('{')) { | ||
this.skipWhitespace; | ||
this.skipWhitespace(); | ||
} else { | ||
@@ -686,3 +686,3 @@ this.expect('indent'); | ||
this.state.pop(); | ||
if (this.css) this.skipWhitespace; | ||
if (this.css) this.skipWhitespace(); | ||
} | ||
@@ -692,3 +692,3 @@ | ||
if (this.css) { | ||
this.skipWhitespace; | ||
this.skipWhitespace(); | ||
this.expect('}'); | ||
@@ -707,3 +707,3 @@ this.css = _; | ||
get literal() { | ||
literal: function() { | ||
return this.expect('literal').val; | ||
@@ -716,3 +716,3 @@ }, | ||
get id() { | ||
id: function() { | ||
var tok = this.expect('ident'); | ||
@@ -730,3 +730,3 @@ this.accept('space'); | ||
get ident() { | ||
ident: function() { | ||
var i = 2 | ||
@@ -746,3 +746,3 @@ , la = this.lookahead(i).type; | ||
case '%=': | ||
return this.assignment | ||
return this.assignment(); | ||
// Operation | ||
@@ -771,19 +771,19 @@ case '-': | ||
// Prevent cyclic .ident, return literal | ||
if (this._ident == this.peek) { | ||
return this.id; | ||
if (this._ident == this.peek()) { | ||
return this.id(); | ||
} else { | ||
this._ident = this.peek; | ||
switch (this.currentState) { | ||
this._ident = this.peek(); | ||
switch (this.currentState()) { | ||
// unary op or selector in property / for | ||
case 'for': | ||
case 'selector': | ||
return this.property; | ||
return this.property(); | ||
// Part of a selector | ||
case 'root': | ||
return this.selector; | ||
return this.selector(); | ||
// Do not disrupt the ident when an operand | ||
default: | ||
return this.operand | ||
? this.id | ||
: this.expression; | ||
? this.id() | ||
: this.expression(); | ||
} | ||
@@ -793,5 +793,5 @@ } | ||
default: | ||
switch (this.currentState) { | ||
switch (this.currentState()) { | ||
case 'root': | ||
return this.selector; | ||
return this.selector(); | ||
case 'for': | ||
@@ -804,5 +804,5 @@ case 'page': | ||
case 'conditional': | ||
return this.property; | ||
return this.property(); | ||
default: | ||
return this.id; | ||
return this.id(); | ||
} | ||
@@ -816,3 +816,3 @@ } | ||
get interpolate() { | ||
interpolate: function() { | ||
var node | ||
@@ -823,3 +823,3 @@ , segs = []; | ||
this.state.push('interpolation'); | ||
segs.push(this.expression); | ||
segs.push(this.expression()); | ||
this.expect('}'); | ||
@@ -842,7 +842,7 @@ this.state.pop(); | ||
get property() { | ||
if (this.looksLikeSelector) return this.selector; | ||
property: function() { | ||
if (this.looksLikeSelector()) return this.selector(); | ||
// property | ||
var ident = this.interpolate | ||
var ident = this.interpolate() | ||
, ret = prop = new nodes.Property(ident); | ||
@@ -856,3 +856,3 @@ | ||
this.inProperty = true; | ||
prop.expr = this.list; | ||
prop.expr = this.list(); | ||
if (prop.expr.isEmpty) ret = ident[0]; | ||
@@ -875,3 +875,3 @@ this.inProperty = false; | ||
get selector() { | ||
selector: function() { | ||
var tok | ||
@@ -898,3 +898,3 @@ , arr | ||
// form a selector. | ||
while (tok = this.selectorToken) { | ||
while (tok = this.selectorToken()) { | ||
// Selector component | ||
@@ -937,6 +937,6 @@ switch (tok.type) { | ||
get assignment() { | ||
assignment: function() { | ||
var op | ||
, node | ||
, name = this.id.name; | ||
, name = this.id().name; | ||
@@ -952,3 +952,3 @@ if (op = | ||
this.state.push('assignment'); | ||
var expr = this.list; | ||
var expr = this.list(); | ||
if (expr.isEmpty) this.error('invalid right-hand side operand in assignment, got {peek}') | ||
@@ -982,3 +982,3 @@ node = new nodes.Ident(name, expr); | ||
get function() { | ||
function: function() { | ||
var parens = 1 | ||
@@ -1000,9 +1000,9 @@ , i = 2 | ||
// Definition or call | ||
switch (this.currentState) { | ||
switch (this.currentState()) { | ||
case 'expression': | ||
return this.functionCall; | ||
return this.functionCall(); | ||
default: | ||
return this.looksLikeFunctionDefinition(i) | ||
? this.functionDefinition | ||
: this.expression; | ||
? this.functionDefinition() | ||
: this.expression(); | ||
} | ||
@@ -1015,6 +1015,6 @@ }, | ||
get url() { | ||
url: function() { | ||
this.expect('function'); | ||
this.state.push('function arguments'); | ||
var args = this.args; | ||
var args = this.args(); | ||
this.expect(')'); | ||
@@ -1029,7 +1029,7 @@ this.state.pop(); | ||
get functionCall() { | ||
if ('url' == this.peek.val.name) return this.url; | ||
functionCall: function() { | ||
if ('url' == this.peek().val.name) return this.url(); | ||
var name = this.expect('function').val.name; | ||
this.state.push('function arguments'); | ||
var args = this.args; | ||
var args = this.args(); | ||
this.expect(')'); | ||
@@ -1044,3 +1044,3 @@ this.state.pop(); | ||
get functionDefinition() { | ||
functionDefinition: function() { | ||
var name = this.expect('function').val.name; | ||
@@ -1050,3 +1050,3 @@ | ||
this.state.push('function params'); | ||
var params = this.params; | ||
var params = this.params(); | ||
this.expect(')'); | ||
@@ -1070,3 +1070,3 @@ this.state.pop(); | ||
get params() { | ||
params: function() { | ||
var tok | ||
@@ -1081,3 +1081,3 @@ , node | ||
} else if (this.accept('=')) { | ||
node.val = this.expression; | ||
node.val = this.expression(); | ||
} | ||
@@ -1093,6 +1093,6 @@ this.accept(','); | ||
get args() { | ||
args: function() { | ||
var args = new nodes.Expression; | ||
do { | ||
args.push(this.expression); | ||
args.push(this.expression()); | ||
} while (this.accept(',')); | ||
@@ -1106,11 +1106,11 @@ return args; | ||
get list() { | ||
var node = this.expression; | ||
list: function() { | ||
var node = this.expression(); | ||
while (this.accept(',')) { | ||
if (node.isList) { | ||
list.push(this.expression); | ||
list.push(this.expression()); | ||
} else { | ||
var list = new nodes.Expression(true); | ||
list.push(node); | ||
list.push(this.expression); | ||
list.push(this.expression()); | ||
node = list; | ||
@@ -1126,7 +1126,7 @@ } | ||
get expression() { | ||
expression: function() { | ||
var node | ||
, expr = new nodes.Expression; | ||
this.state.push('expression'); | ||
while (node = this.negation) { | ||
while (node = this.negation()) { | ||
if (!node) this.error('unexpected token {peek} in expression'); | ||
@@ -1144,7 +1144,7 @@ expr.push(node); | ||
get negation() { | ||
negation: function() { | ||
if (this.accept('not')) { | ||
return new nodes.UnaryOp('!', this.negation); | ||
return new nodes.UnaryOp('!', this.negation()); | ||
} | ||
return this.ternary; | ||
return this.ternary(); | ||
}, | ||
@@ -1156,8 +1156,8 @@ | ||
get ternary() { | ||
var node = this.logical; | ||
ternary: function() { | ||
var node = this.logical(); | ||
if (this.accept('?')) { | ||
var trueExpr = this.expression; | ||
var trueExpr = this.expression(); | ||
this.expect(':'); | ||
var falseExpr = this.expression; | ||
var falseExpr = this.expression(); | ||
node = new nodes.Ternary(node, trueExpr, falseExpr); | ||
@@ -1172,7 +1172,7 @@ } | ||
get logical() { | ||
logical: function() { | ||
var op | ||
, node = this.typecheck; | ||
, node = this.typecheck(); | ||
while (op = this.accept('&&') || this.accept('||')) { | ||
node = new nodes.BinOp(op.type, node, this.typecheck); | ||
node = new nodes.BinOp(op.type, node, this.typecheck()); | ||
} | ||
@@ -1186,9 +1186,9 @@ return node; | ||
get typecheck() { | ||
typecheck: function() { | ||
var op | ||
, node = this.equality; | ||
, node = this.equality(); | ||
while (op = this.accept('is a')) { | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.equality); | ||
node = new nodes.BinOp(op.type, node, this.equality()); | ||
this.operand = false; | ||
@@ -1203,9 +1203,9 @@ } | ||
get equality() { | ||
equality: function() { | ||
var op | ||
, node = this.in; | ||
, node = this.in(); | ||
while (op = this.accept('==') || this.accept('!=')) { | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.in); | ||
node = new nodes.BinOp(op.type, node, this.in()); | ||
this.operand = false; | ||
@@ -1220,8 +1220,8 @@ } | ||
get in() { | ||
var node = this.relational; | ||
in: function() { | ||
var node = this.relational(); | ||
while (this.accept('in')) { | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary in'); | ||
node = new nodes.BinOp('in', node, this.relational); | ||
node = new nodes.BinOp('in', node, this.relational()); | ||
this.operand = false; | ||
@@ -1236,5 +1236,5 @@ } | ||
get relational() { | ||
relational: function() { | ||
var op | ||
, node = this.range; | ||
, node = this.range(); | ||
while (op = | ||
@@ -1248,3 +1248,3 @@ this.accept('>=') | ||
if (!node) throw new Error('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.range); | ||
node = new nodes.BinOp(op.type, node, this.range()); | ||
this.operand = false; | ||
@@ -1259,9 +1259,9 @@ } | ||
get range() { | ||
range: function() { | ||
var op | ||
, node = this.additive; | ||
, node = this.additive(); | ||
if (op = this.accept('...') || this.accept('..')) { | ||
this.operand = true; | ||
if (!node) throw new Error('illegal unary ' + op); | ||
node = new nodes.BinOp(op.val, node, this.additive); | ||
node = new nodes.BinOp(op.val, node, this.additive()); | ||
this.operand = false; | ||
@@ -1276,8 +1276,8 @@ } | ||
get additive() { | ||
additive: function() { | ||
var op | ||
, node = this.multiplicative; | ||
, node = this.multiplicative(); | ||
while (op = this.accept('+') || this.accept('-')) { | ||
this.operand = true; | ||
node = new nodes.BinOp(op.type, node, this.multiplicative); | ||
node = new nodes.BinOp(op.type, node, this.multiplicative()); | ||
this.operand = false; | ||
@@ -1292,5 +1292,5 @@ } | ||
get multiplicative() { | ||
multiplicative: function() { | ||
var op | ||
, node = this.defined; | ||
, node = this.defined(); | ||
while (op = | ||
@@ -1309,3 +1309,3 @@ this.accept('**') | ||
if (!node) throw new Error('illegal unary ' + op); | ||
node = new nodes.BinOp(op.type, node, this.defined); | ||
node = new nodes.BinOp(op.type, node, this.defined()); | ||
this.operand = false; | ||
@@ -1322,4 +1322,4 @@ } | ||
get defined() { | ||
var node = this.unary; | ||
defined: function() { | ||
var node = this.unary(); | ||
if (this.accept('is defined')) { | ||
@@ -1337,3 +1337,3 @@ if (!node) throw new Error('illegal use of "is defined"'); | ||
get unary() { | ||
unary: function() { | ||
var op | ||
@@ -1347,7 +1347,7 @@ , node; | ||
this.operand = true; | ||
node = new nodes.UnaryOp(op.type, this.unary); | ||
node = new nodes.UnaryOp(op.type, this.unary()); | ||
this.operand = false; | ||
return node; | ||
} | ||
return this.subscript; | ||
return this.subscript(); | ||
}, | ||
@@ -1360,6 +1360,6 @@ | ||
get subscript() { | ||
var node = this.primary; | ||
subscript: function() { | ||
var node = this.primary(); | ||
while (this.accept('[')) { | ||
node = new nodes.BinOp('[]', node, this.expression); | ||
node = new nodes.BinOp('[]', node, this.expression()); | ||
this.expect(']'); | ||
@@ -1381,3 +1381,3 @@ } | ||
get primary() { | ||
primary: function() { | ||
var op | ||
@@ -1389,3 +1389,3 @@ , node; | ||
this.parens = true; | ||
var expr = this.expression; | ||
var expr = this.expression(); | ||
this.expect(')'); | ||
@@ -1397,3 +1397,3 @@ this.parens = false; | ||
// Primitive | ||
switch (this.peek.type) { | ||
switch (this.peek().type) { | ||
case 'null': | ||
@@ -1405,9 +1405,9 @@ case 'unit': | ||
case 'boolean': | ||
return this.next.val; | ||
return this.next().val; | ||
case 'ident': | ||
return this.ident; | ||
return this.ident(); | ||
case 'function': | ||
return this.functionCall; | ||
return this.functionCall(); | ||
} | ||
} | ||
}; |
@@ -26,3 +26,3 @@ | ||
exports.version = '0.7.3'; | ||
exports.version = '0.7.4'; | ||
@@ -29,0 +29,0 @@ /** |
@@ -128,3 +128,3 @@ | ||
/** | ||
* Assert that `node` is a `Color` or `HSLA`. | ||
* Assert that `node` is a `RGBA` or `HSLA`. | ||
* | ||
@@ -138,6 +138,6 @@ * @param {Node} node | ||
exports.assertPresent(node, param); | ||
if (node instanceof nodes.Color) return; | ||
if (node instanceof nodes.RGBA) return; | ||
if (node instanceof nodes.HSLA) return; | ||
var actual = node.constructor.name | ||
, msg = 'expected Color or HSLA, but got ' + actual + ':' + node; | ||
, msg = 'expected RGBA or HSLA, but got ' + actual + ':' + node; | ||
throw new Error('TypeError: ' + msg); | ||
@@ -144,0 +144,0 @@ }; |
@@ -197,7 +197,7 @@ | ||
/** | ||
* Visit Color. | ||
* Visit RGBA. | ||
*/ | ||
Compiler.prototype.visitColor = function(color){ | ||
return color.toString(); | ||
Compiler.prototype.visitRGBA = function(rgba){ | ||
return rgba.toString(); | ||
}; | ||
@@ -204,0 +204,0 @@ |
@@ -47,2 +47,3 @@ | ||
this.warnings = options.warn; | ||
this.options = options; | ||
this.setup(); | ||
@@ -110,4 +111,4 @@ this.calling = []; // TODO: remove, use stack | ||
var rgb = colors[name] | ||
, color = new nodes.Color(rgb[0], rgb[1], rgb[2], 1) | ||
, node = new nodes.Ident(name, color); | ||
, rgba = new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1) | ||
, node = new nodes.Ident(name, rgba); | ||
scope.add(node); | ||
@@ -541,2 +542,6 @@ }); | ||
// Expose imports | ||
import.path = found; | ||
if (this.options._imports) this.options._imports.push(import); | ||
// Throw if import failed | ||
@@ -543,0 +548,0 @@ if (!found) throw new Error('failed to locate @import file ' + path); |
{ "name": "stylus" | ||
, "description": "Robust, expressive language which compiles to CSS" | ||
, "version": "0.7.3" | ||
, "version": "0.7.4" | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
@@ -5,0 +5,0 @@ , "keywords": ["css", "parser", "style", "stylesheets", "jade", "language"] |
Sorry, the diff of this file is not supported yet
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
187618
65
6611