change new(name) to new name

This commit is contained in:
Konstantin Käfer 2011-01-21 16:17:52 -05:00
parent 90ac51a804
commit 81f8a7b298
21 changed files with 106 additions and 90 deletions

View File

@ -103,7 +103,7 @@ fs.readFile(input, 'utf-8', function (e, data) {
}); });
}); });
} else if (options.json) { } else if (options.json) {
new(mess.Renderer)({ new mess.Renderer({
paths: [path.dirname(input)], paths: [path.dirname(input)],
optimization: options.optimization, optimization: options.optimization,
filename: input filename: input
@ -116,7 +116,7 @@ fs.readFile(input, 'utf-8', function (e, data) {
} }
}); });
} else { } else {
new(mess.Parser)({ new mess.Parser({
paths: [path.dirname(input)], paths: [path.dirname(input)],
optimization: options.optimization, optimization: options.optimization,
filename: input filename: input

View File

@ -74,7 +74,7 @@ for (var i = 0; i < links.length; i++) {
less.refresh = function (reload) { less.refresh = function (reload) {
var startTime = endTime = new(Date); var startTime = endTime = new Date;
loadStyleSheets(function (root, sheet, env) { loadStyleSheets(function (root, sheet, env) {
if (env.local) { if (env.local) {
@ -83,9 +83,9 @@ less.refresh = function (reload) {
log("parsed " + sheet.href + " successfully."); log("parsed " + sheet.href + " successfully.");
createCSS(root.toCSS(), sheet, env.lastModified); createCSS(root.toCSS(), sheet, env.lastModified);
} }
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms'); log("css for " + sheet.href + " generated in " + (new Date - endTime) + 'ms');
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms'); (env.remaining === 0) && log("css generated in " + (new Date - startTime) + 'ms');
endTime = new(Date); endTime = new Date;
}, reload); }, reload);
loadStyles(); loadStyles();
@ -98,7 +98,7 @@ function loadStyles() {
var styles = document.getElementsByTagName('style'); var styles = document.getElementsByTagName('style');
for (var i = 0; i < styles.length; i++) { for (var i = 0; i < styles.length; i++) {
if (styles[i].type.match(typePattern)) { if (styles[i].type.match(typePattern)) {
new(less.Parser)().parse(styles[i].innerHTML || '', function (e, tree) { new less.Parser().parse(styles[i].innerHTML || '', function (e, tree) {
styles[i].type = 'text/css'; styles[i].type = 'text/css';
styles[i].innerHTML = tree.toCSS(); styles[i].innerHTML = tree.toCSS();
}); });
@ -126,15 +126,15 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
xhr(sheet.href, sheet.type, function (data, lastModified) { xhr(sheet.href, sheet.type, function (data, lastModified) {
if (!reload && styles && lastModified && if (!reload && styles && lastModified &&
(new(Date)(lastModified).valueOf() === (new Date(lastModified).valueOf() ===
new(Date)(styles.timestamp).valueOf())) { new Date(styles.timestamp).valueOf())) {
// Use local copy // Use local copy
createCSS(styles.css, sheet); createCSS(styles.css, sheet);
callback(null, sheet, { local: true, remaining: remaining }); callback(null, sheet, { local: true, remaining: remaining });
} else { } else {
// Use remote copy (re-parse) // Use remote copy (re-parse)
try { try {
new(less.Parser)({ new less.Parser({
optimization: less.optimization, optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')], paths: [href.replace(/[\w\.-]+$/, '')],
mime: sheet.type mime: sheet.type
@ -152,7 +152,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
} }
} }
}, function (status, url) { }, function (status, url) {
throw new(Error)("Couldn't load " + url + " (" + status + ")"); throw new Error("Couldn't load " + url + " (" + status + ")");
}); });
} }
@ -187,7 +187,7 @@ function createCSS(styles, sheet, lastModified) {
try { try {
css.styleSheet.cssText = styles; css.styleSheet.cssText = styles;
} catch (e) { } catch (e) {
throw new(Error)("Couldn't reassign styleSheet.cssText."); throw new Error("Couldn't reassign styleSheet.cssText.");
} }
} else { } else {
(function (node) { (function (node) {
@ -248,10 +248,10 @@ function xhr(url, type, callback, errback) {
function getXMLHttpRequest() { function getXMLHttpRequest() {
if (window.XMLHttpRequest) { if (window.XMLHttpRequest) {
return new(XMLHttpRequest); return new XMLHttpRequest;
} else { } else {
try { try {
return new(ActiveXObject)("MSXML2.XMLHTTP.3.0"); return new ActiveXObject("MSXML2.XMLHTTP.3.0");
} catch (e) { } catch (e) {
log("browser doesn't support AJAX."); log("browser doesn't support AJAX.");
return null; return null;

View File

@ -7,7 +7,7 @@ tree.functions = {
rgba: function (r, g, b, a) { rgba: function (r, g, b, a) {
var rgb = [r, g, b].map(function (c) { return number(c) }), var rgb = [r, g, b].map(function (c) { return number(c) }),
a = number(a); a = number(a);
return new(tree.Color)(rgb, a); return new tree.Color(rgb, a);
}, },
hsl: function (h, s, l) { hsl: function (h, s, l) {
return this.hsla(h, s, l, 1.0); return this.hsla(h, s, l, 1.0);
@ -33,16 +33,16 @@ tree.functions = {
} }
}, },
hue: function (color) { hue: function (color) {
return new(tree.Dimension)(Math.round(color.toHSL().h)); return new tree.Dimension(Math.round(color.toHSL().h));
}, },
saturation: function (color) { saturation: function (color) {
return new(tree.Dimension)(Math.round(color.toHSL().s * 100), '%'); return new tree.Dimension(Math.round(color.toHSL().s * 100), '%');
}, },
lightness: function (color) { lightness: function (color) {
return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%'); return new tree.Dimension(Math.round(color.toHSL().l * 100), '%');
}, },
alpha: function (color) { alpha: function (color) {
return new(tree.Dimension)(color.toHSL().a); return new tree.Dimension(color.toHSL().a);
}, },
saturate: function (color, amount) { saturate: function (color, amount) {
var hsl = color.toHSL(); var hsl = color.toHSL();
@ -112,13 +112,13 @@ tree.functions = {
var alpha = color1.alpha * p + color2.alpha * (1 - p); var alpha = color1.alpha * p + color2.alpha * (1 - p);
return new(tree.Color)(rgb, alpha); return new tree.Color(rgb, alpha);
}, },
greyscale: function (color) { greyscale: function (color) {
return this.desaturate(color, new(tree.Dimension)(100)); return this.desaturate(color, new tree.Dimension(100));
}, },
e: function (str) { e: function (str) {
return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str); return new tree.Anonymous(str instanceof tree.JavaScript ? str.evaluated : str);
}, },
'%': function (quoted /* arg, arg, ...*/) { '%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1), var args = Array.prototype.slice.call(arguments, 1),
@ -129,7 +129,7 @@ tree.functions = {
.replace(/%[da]/, args[i].toCSS()); .replace(/%[da]/, args[i].toCSS());
} }
str = str.replace(/%%/g, '%'); str = str.replace(/%%/g, '%');
return new(tree.Quoted)('"' + str + '"', str); return new tree.Quoted('"' + str + '"', str);
} }
}; };

View File

@ -17,7 +17,7 @@ var mess = {
callback = options, options = {}; callback = options, options = {};
} }
var parser = new(this.Parser)(options), var parser = new this.Parser(options),
ee; ee;
if (callback) { if (callback) {
@ -25,7 +25,7 @@ var mess = {
callback(e, root.toCSS()); callback(e, root.toCSS());
}); });
} else { } else {
ee = new(require('events').EventEmitter); ee = new require('events'.EventEmitter);
process.nextTick(function() { process.nextTick(function() {
parser.parse(input, function(e, root) { parser.parse(input, function(e, root) {
@ -110,7 +110,7 @@ mess.Parser.importer = function(file, paths, callback) {
fs.readFile(pathname, 'utf-8', function(e, data) { fs.readFile(pathname, 'utf-8', function(e, data) {
if (e) sys.error(e); if (e) sys.error(e);
new(mess.Parser)({ new mess.Parser({
paths: [path.dirname(pathname)], paths: [path.dirname(pathname)],
filename: pathname filename: pathname
}).parse(data, function(e, root) { }).parse(data, function(e, root) {

View File

@ -272,7 +272,7 @@ mess.Parser = function Parser(env) {
// The whole syntax tree is held under a Ruleset node, // The whole syntax tree is held under a Ruleset node,
// with the `root` property set to true, so no `{}` are // with the `root` property set to true, so no `{}` are
// output. The callback is called when the input is parsed. // output. The callback is called when the input is parsed.
root = new(tree.Ruleset)([], $(this.parsers.primary)); root = new tree.Ruleset([], $(this.parsers.primary));
root.root = true; root.root = true;
root.toCSS = (function(evaluate) { root.toCSS = (function(evaluate) {
@ -474,9 +474,9 @@ mess.Parser = function Parser(env) {
if (input.charAt(i) !== '/') return; if (input.charAt(i) !== '/') return;
if (input.charAt(i + 1) === '/') { if (input.charAt(i + 1) === '/') {
return new(tree.Comment)($(/^\/\/.*/), true); return new tree.Comment($(/^\/\/.*/), true);
} else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) { } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) {
return new(tree.Comment)(comment); return new tree.Comment(comment);
} }
}, },
@ -494,7 +494,7 @@ mess.Parser = function Parser(env) {
if (input.charAt(i) !== '"' && input.charAt(i) !== "'") return; if (input.charAt(i) !== '"' && input.charAt(i) !== "'") return;
if (str = $(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/)) { if (str = $(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/)) {
return new(tree.Quoted)(str[0], str[1] || str[2]); return new tree.Quoted(str[0], str[1] || str[2]);
} }
}, },
@ -502,7 +502,7 @@ mess.Parser = function Parser(env) {
var str; var str;
// todo: <= // todo: <=
if (str = $(/^=|!=|<=|>=|<|>/)) { if (str = $(/^=|!=|<=|>=|<|>/)) {
return new(tree.Comparison)(str); return new tree.Comparison(str);
} }
}, },
@ -513,7 +513,7 @@ mess.Parser = function Parser(env) {
// //
keyword: function() { keyword: function() {
var k; var k;
if (k = $(/^[A-Za-z-]+/)) { return new(tree.Keyword)(k) } if (k = $(/^[A-Za-z-]+/)) { return new tree.Keyword(k) }
}, },
// //
@ -537,7 +537,7 @@ mess.Parser = function Parser(env) {
if (! $(')')) return; if (! $(')')) return;
if (name) { return new(tree.Call)(name, args) } if (name) { return new tree.Call(name, args) }
}, },
arguments: function() { arguments: function() {
var args = [], arg; var args = [], arg;
@ -567,10 +567,10 @@ mess.Parser = function Parser(env) {
if (input.charAt(i) !== 'u' || !$(/^url\(/)) return; if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
value = $(this.entities.quoted) || $(this.entities.variable) || value = $(this.entities.quoted) || $(this.entities.variable) ||
$(/^[-\w%@$\/.&=:;#+?]+/) || ''; $(/^[-\w%@$\/.&=:;#+?]+/) || '';
if (! $(')')) throw new(Error)('missing closing ) for url()'); if (! $(')')) throw new Error('missing closing ) for url()');
return new(tree.URL)((value.value || value.data || value instanceof tree.Variable) return new tree.URL((value.value || value.data || value instanceof tree.Variable)
? value : new(tree.Anonymous)(value), imports.paths); ? value : new tree.Anonymous(value), imports.paths);
}, },
// //
@ -585,7 +585,7 @@ mess.Parser = function Parser(env) {
var name, index = i; var name, index = i;
if (input.charAt(i) === '@' && (name = $(/^@[\w-]+/))) { if (input.charAt(i) === '@' && (name = $(/^@[\w-]+/))) {
return new(tree.Variable)(name, index); return new tree.Variable(name, index);
} }
}, },
@ -600,7 +600,7 @@ mess.Parser = function Parser(env) {
var rgb; var rgb;
if (input.charAt(i) === '#' && (rgb = $(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/))) { if (input.charAt(i) === '#' && (rgb = $(/^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/))) {
return new(tree.Color)(rgb[1]); return new tree.Color(rgb[1]);
} }
}, },
@ -614,7 +614,7 @@ mess.Parser = function Parser(env) {
if ((c > 57 || c < 45) || c === 47) return; if ((c > 57 || c < 45) || c === 47) return;
if (value = $(/^(-?\d*\.?\d+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/)) { if (value = $(/^(-?\d*\.?\d+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/)) {
return new(tree.Dimension)(value[1], value[2]); return new tree.Dimension(value[1], value[2]);
} }
}, },
@ -629,7 +629,7 @@ mess.Parser = function Parser(env) {
if (input.charAt(i) !== '`') { return } if (input.charAt(i) !== '`') { return }
if (str = $(/^`([^`]*)`/)) { if (str = $(/^`([^`]*)`/)) {
return new(tree.JavaScript)(str[1], i); return new tree.JavaScript(str[1], i);
} }
} }
}, },
@ -666,14 +666,14 @@ mess.Parser = function Parser(env) {
if (s !== '.' && s !== '#') { return } if (s !== '.' && s !== '#') { return }
while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) { while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) {
elements.push(new(tree.Element)(c, e)); elements.push(new tree.Element(c, e));
c = $('>'); c = $('>');
} }
$('(') && (args = $(this.entities.arguments)) && $(')'); $('(') && (args = $(this.entities.arguments)) && $(')');
if (elements.length > 0 && ($(';') || peek('}'))) { if (elements.length > 0 && ($(';') || peek('}'))) {
throw 'Calls are not yet supported'; throw 'Calls are not yet supported';
return new(tree.mixin.Call)(elements, args, index); return new tree.mixin.Call(elements, args, index);
} }
}, },
@ -713,7 +713,7 @@ mess.Parser = function Parser(env) {
if (value = $(this.expression)) { if (value = $(this.expression)) {
params.push({ name: param.name, value: value }); params.push({ name: param.name, value: value });
} else { } else {
throw new(Error)('Expected value'); throw new Error('Expected value');
} }
} else { } else {
params.push({ name: param.name }); params.push({ name: param.name });
@ -723,13 +723,13 @@ mess.Parser = function Parser(env) {
} }
if (! $(',')) { break } if (! $(',')) { break }
} }
if (! $(')')) throw new(Error)('Expected )'); if (! $(')')) throw new Error('Expected )');
ruleset = $(this.block); ruleset = $(this.block);
if (ruleset) { if (ruleset) {
throw 'Definitions should not exist here'; throw 'Definitions should not exist here';
return new(tree.mixin.Definition)(name, params, ruleset); return new tree.mixin.Definition(name, params, ruleset);
} }
} }
} }
@ -829,9 +829,9 @@ mess.Parser = function Parser(env) {
(val = $(this.entities.quoted) || $(/^[\w-]+/))) { (val = $(this.entities.quoted) || $(/^[\w-]+/))) {
if (! $(']')) return; if (! $(']')) return;
if (key == 'zoom') { if (key == 'zoom') {
return new(tree.ZoomFilter)(op, val, memo); return new tree.ZoomFilter(op, val, memo);
} else { } else {
return new(tree.Filter)(key, op, val, memo); return new tree.Filter(key, op, val, memo);
} }
} }
} }
@ -872,11 +872,11 @@ mess.Parser = function Parser(env) {
if (selectors.length === 1 && if (selectors.length === 1 &&
selectors[0].elements.length && selectors[0].elements.length &&
selectors[0].elements[0].value === 'Map') { selectors[0].elements[0].value === 'Map') {
var rs = new(tree.Ruleset)(selectors, rules); var rs = new tree.Ruleset(selectors, rules);
rs.is_map = true; rs.is_map = true;
return rs; return rs;
} }
return new(tree.Ruleset)(selectors, rules); return new tree.Ruleset(selectors, rules);
} else { } else {
// Backtrack // Backtrack
restore(); restore();
@ -893,7 +893,7 @@ mess.Parser = function Parser(env) {
important = $(this.important); important = $(this.important);
if (value && $(this.end)) { if (value && $(this.end)) {
return new(tree.Rule)(name, value, important, memo); return new tree.Rule(name, value, important, memo);
} else { } else {
furthest = i; furthest = i;
restore(); restore();
@ -907,7 +907,7 @@ mess.Parser = function Parser(env) {
while (e = $(this.shorthand) || $(this.entity)) { while (e = $(this.shorthand) || $(this.entity)) {
expression.push(e); expression.push(e);
} }
value.push(new(tree.Expression)(expression)); value.push(new tree.Expression(expression));
if ($(',')) { if ($(',')) {
while (e = $(this.expression)) { while (e = $(this.expression)) {
@ -915,7 +915,7 @@ mess.Parser = function Parser(env) {
if (! $(',')) { break } if (! $(',')) { break }
} }
} }
return new(tree.Value)(value); return new tree.Value(value);
}, },
// //
@ -935,7 +935,7 @@ mess.Parser = function Parser(env) {
} }
if (expressions.length > 0) { if (expressions.length > 0) {
return new(tree.Value)(expressions); return new tree.Value(expressions);
} }
}, },
important: function() { important: function() {
@ -954,7 +954,7 @@ mess.Parser = function Parser(env) {
var m, a, op, operation; var m, a, op, operation;
if (m = $(this.operand)) { if (m = $(this.operand)) {
while ((op = ($('/') || $('*'))) && (a = $(this.operand))) { while ((op = ($('/') || $('*'))) && (a = $(this.operand))) {
operation = new(tree.Operation)(op, [operation || m, a]); operation = new tree.Operation(op, [operation || m, a]);
} }
return operation || m; return operation || m;
} }
@ -964,7 +964,7 @@ mess.Parser = function Parser(env) {
if (m = $(this.multiplication)) { if (m = $(this.multiplication)) {
while ((op = $(/^[-+]\s+/) || (input.charAt(i - 1) != ' ' && ($('+') || $('-')))) && while ((op = $(/^[-+]\s+/) || (input.charAt(i - 1) != ' ' && ($('+') || $('-')))) &&
(a = $(this.multiplication))) { (a = $(this.multiplication))) {
operation = new(tree.Operation)(op, [operation || m, a]); operation = new tree.Operation(op, [operation || m, a]);
} }
return operation || m; return operation || m;
} }
@ -994,7 +994,7 @@ mess.Parser = function Parser(env) {
entities.push(e); entities.push(e);
} }
if (entities.length > 0) { if (entities.length > 0) {
return new(tree.Expression)(entities); return new tree.Expression(entities);
} }
}, },
property: function() { property: function() {

View File

@ -48,7 +48,7 @@ mess.Renderer = function Renderer(env) {
* @param {Function} callback * @param {Function} callback
*/ */
grab: function(uri, callback) { grab: function(uri, callback) {
new(External)(this.env).process(uri, callback); new External(this.env).process(uri, callback);
}, },
/** /**
@ -148,7 +148,7 @@ mess.Renderer = function Renderer(env) {
var options = {}, var options = {},
group = this.group(); group = this.group();
for (var i = 0, l = results.length; i < l; i++) { for (var i = 0, l = results.length; i < l; i++) {
new(mess.Parser)(_.extend(_.extend({ new mess.Parser(_.extend(_.extend({
filename: s filename: s
}, that.env), this.env)).parse(results[i][1], }, that.env), this.env)).parse(results[i][1],
function(err, tree) { function(err, tree) {
@ -361,7 +361,7 @@ mess.Renderer = function Renderer(env) {
for (sym in by_symbolizer) { for (sym in by_symbolizer) {
// Create styles out of chains of one-symbolizer rules, // Create styles out of chains of one-symbolizer rules,
// and assign those styles to layers // and assign those styles to layers
var new_style = new(mess.tree.Style)( var new_style = new mess.tree.Style(
l.id, l.id,
sym, sym,
that.process_chain(by_symbolizer[sym])); that.process_chain(by_symbolizer[sym]));
@ -369,7 +369,7 @@ mess.Renderer = function Renderer(env) {
output.push(new_style.toXML(env)); output.push(new_style.toXML(env));
} }
var nl = new(mess.tree.Layer)(l); var nl = new mess.tree.Layer(l);
output.push(nl.toXML()); output.push(nl.toXML());
}); });

View File

@ -26,7 +26,7 @@ tree.Call.prototype = {
if (this.name in tree.functions) { // 1. if (this.name in tree.functions) { // 1.
return tree.functions[this.name].apply(tree.functions, args); return tree.functions[this.name].apply(tree.functions, args);
} else { // 2. } else { // 2.
return new(tree.Anonymous)(this.name + return new tree.Anonymous(this.name +
'(' + args.map(function(a) { return a.toCSS() }).join(', ') + ')'); '(' + args.map(function(a) { return a.toCSS() }).join(', ') + ')');
} }
}, },

View File

@ -62,7 +62,7 @@ tree.Color.prototype = {
for (var c = 0; c < 3; c++) { for (var c = 0; c < 3; c++) {
result[c] = tree.operate(op, this.rgb[c], other.rgb[c]); result[c] = tree.operate(op, this.rgb[c], other.rgb[c]);
} }
return new(tree.Color)(result); return new tree.Color(result);
}, },
toHSL: function() { toHSL: function() {

View File

@ -15,7 +15,7 @@ tree.Comparison.prototype = {
'>=': '&gt;='}[this.value]; '>=': '&gt;='}[this.value];
}, },
negate: function() { negate: function() {
return new(tree.Comparison)({ return new tree.Comparison({
'<': '>=', '<': '>=',
'<=': '>', '<=': '>',
'>': '<=', '>': '<=',

View File

@ -20,7 +20,7 @@ tree.Definition.prototype.clone = function() {
* NOTE: does not clone objects besides creating a new Ruleset. * NOTE: does not clone objects besides creating a new Ruleset.
*/ */
tree.Definition.prototype.filter_symbolizer = function(symbolizer) { tree.Definition.prototype.filter_symbolizer = function(symbolizer) {
return new(tree.Definition)(this.selector, return new tree.Definition(this.selector,
this.rules.filter(function(rule) { this.rules.filter(function(rule) {
return rule.symbolizer == symbolizer; return rule.symbolizer == symbolizer;
}) })

View File

@ -12,7 +12,7 @@ tree.Dimension = function(value, unit) {
tree.Dimension.prototype = { tree.Dimension.prototype = {
eval: function() { return this }, eval: function() { return this },
toColor: function() { toColor: function() {
return new(tree.Color)([this.value, this.value, this.value]); return new tree.Color([this.value, this.value, this.value]);
}, },
toCSS: function() { toCSS: function() {
return this.value; return this.value;
@ -25,7 +25,7 @@ tree.Dimension.prototype = {
// conversions such that `100cm + 10mm` would yield // conversions such that `100cm + 10mm` would yield
// `101cm`. // `101cm`.
operate: function(op, other) { operate: function(op, other) {
return new(tree.Dimension); return new tree.Dimension;
(tree.operate(op, this.value, other.value), (tree.operate(op, this.value, other.value),
this.unit || other.unit); this.unit || other.unit);
} }

View File

@ -3,7 +3,7 @@
tree.Directive = function(name, value) { tree.Directive = function(name, value) {
this.name = name; this.name = name;
if (Array.isArray(value)) { if (Array.isArray(value)) {
this.ruleset = new(tree.Ruleset)([], value); this.ruleset = new tree.Ruleset([], value);
} else { } else {
this.value = value; this.value = value;
} }

View File

@ -1,12 +1,10 @@
(function(tree) { (function(tree) {
tree.Expression = function(value) { tree.Expression = function(value) { this.value = value };
this.value = value;
};
tree.Expression.prototype = { tree.Expression.prototype = {
eval: function(env) { eval: function(env) {
if (this.value.length > 1) { if (this.value.length > 1) {
return new(tree.Expression)(this.value.map(function(e) { return new tree.Expression(this.value.map(function(e) {
return e.eval(env); return e.eval(env);
})); }));
} else { } else {

View File

@ -24,7 +24,7 @@ tree.Filter.prototype.toXML = function(env) {
* TODO: should this have an index? * TODO: should this have an index?
*/ */
tree.Filter.prototype.negate = function() { tree.Filter.prototype.negate = function() {
return new(tree.Filter)(this.key, this.op.negate(), this.val); return new tree.Filter(this.key, this.op.negate(), this.val);
}; };
})(require('mess/tree')); })(require('mess/tree'));

View File

@ -29,7 +29,7 @@ tree.Import = function(path, imports) {
if (! this.css) { if (! this.css) {
imports.push(this.path, function(root) { imports.push(this.path, function(root) {
if (! root) { if (! root) {
throw new(Error)('Error parsing ' + that.path); throw new Error('Error parsing ' + that.path);
} }
that.root = root; that.root = root;
}); });
@ -59,7 +59,7 @@ tree.Import.prototype = {
if (this.css) { if (this.css) {
return this; return this;
} else { } else {
ruleset = new(tree.Ruleset)(null, this.root.rules.slice(0)); ruleset = new tree.Ruleset(null, this.root.rules.slice(0));
for (var i = 0; i < ruleset.rules.length; i++) { for (var i = 0; i < ruleset.rules.length; i++) {
if (ruleset.rules[i] instanceof tree.Import) { if (ruleset.rules[i] instanceof tree.Import) {

View File

@ -10,7 +10,7 @@ tree.JavaScript.prototype = {
}, },
eval: function(env) { eval: function(env) {
var result, var result,
expression = new(Function)('return (' + this.expression + ')'), expression = new Function('return (' + this.expression + ')'),
context = {}; context = {};
for (var k in env.frames[0].variables()) { for (var k in env.frames[0].variables()) {

View File

@ -2,7 +2,7 @@
tree.mixin = {}; tree.mixin = {};
tree.mixin.Call = function(elements, args, index) { tree.mixin.Call = function(elements, args, index) {
this.selector = new(tree.Selector)(elements); this.selector = new tree.Selector(elements);
this.arguments = args; this.arguments = args;
this.index = index; this.index = index;
}; };
@ -42,7 +42,7 @@ tree.mixin.Call.prototype = {
tree.mixin.Definition = function(name, params, rules) { tree.mixin.Definition = function(name, params, rules) {
this.name = name; this.name = name;
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])]; this.selectors = [new tree.Selector([new tree.Element(null, name)])];
this.params = params; this.params = params;
this.arity = params.length; this.arity = params.length;
this.rules = rules; this.rules = rules;
@ -62,19 +62,19 @@ tree.mixin.Definition.prototype = {
rulesets: function() { return this.parent.rulesets.apply(this) }, rulesets: function() { return this.parent.rulesets.apply(this) },
eval: function(env, args) { eval: function(env, args) {
var frame = new(tree.Ruleset)(null, []), context; var frame = new tree.Ruleset(null, []), context;
for (var i = 0, val; i < this.params.length; i++) { for (var i = 0, val; i < this.params.length; i++) {
if (this.params[i].name) { if (this.params[i].name) {
if (val = (args && args[i]) || this.params[i].value) { if (val = (args && args[i]) || this.params[i].value) {
frame.rules.unshift(new(tree.Rule)(this.params[i].name, val.eval(env))); frame.rules.unshift(new tree.Rule(this.params[i].name, val.eval(env)));
} else { } else {
throw { message: 'wrong number of arguments for ' + this.name + throw { message: 'wrong number of arguments for ' + this.name +
' (' + args.length + ' for ' + this.arity + ')' }; ' (' + args.length + ' for ' + this.arity + ')' };
} }
} }
} }
return new(tree.Ruleset)(null, this.rules.slice(0)).eval({ return new tree.Ruleset(null, this.rules.slice(0)).eval({
frames: [this, frame].concat(this.frames, env.frames) frames: [this, frame].concat(this.frames, env.frames)
}); });
}, },

View File

@ -2,11 +2,14 @@
tree.Rule = function(name, value, important, index) { tree.Rule = function(name, value, important, index) {
this.name = name; this.name = name;
this.value = (value instanceof tree.Value) ? this.value = (value instanceof tree.Value) ?
value : new(tree.Value)([value]); value : new tree.Value([value]);
this.important = important ? ' ' + important.trim() : ''; this.important = important ? ' ' + important.trim() : '';
this.index = index; this.index = index;
this.symbolizer = tree.Reference.symbolizer(this.name); this.symbolizer = tree.Reference.symbolizer(this.name);
this.variable = (name.charAt(0) === '@');
if (name.charAt(0) === '@') {
this.variable = true;
} else { this.variable = false }
}; };
tree.Rule.prototype.toCSS = function(env) { tree.Rule.prototype.toCSS = function(env) {
@ -34,9 +37,12 @@ tree.Rule.prototype.toCSS = function(env) {
}; };
} }
if (this.variable) { if (!this.value) {
return '' console.log(this);
} else { }
if (this.variable) { return '' }
else {
return tree.Reference.selectorName(this.name) + return tree.Reference.selectorName(this.name) +
'="' + '="' +
this.value.toCSS(env, this.name) + this.value.toCSS(env, this.name) +
@ -45,10 +51,22 @@ tree.Rule.prototype.toCSS = function(env) {
}; };
tree.Rule.prototype.eval = function(context) { tree.Rule.prototype.eval = function(context) {
return new(tree.Rule)(this.name, return new tree.Rule(this.name,
this.value.eval(context), this.value.eval(context),
this.important, this.important,
this.index); this.index);
}; };
tree.Shorthand = function(a, b) {
this.a = a;
this.b = b;
};
tree.Shorthand.prototype = {
toCSS: function(env) {
return this.a.toCSS(env) + '/' + this.b.toCSS(env);
},
eval: function() { return this }
};
})(require('mess/tree')); })(require('mess/tree'));

View File

@ -8,7 +8,7 @@ tree.Ruleset = function(selectors, rules) {
}; };
tree.Ruleset.prototype = { tree.Ruleset.prototype = {
eval: function(env) { eval: function(env) {
var ruleset = new(tree.Ruleset)(this.selectors, this.rules.slice(0)); var ruleset = new tree.Ruleset(this.selectors, this.rules.slice(0));
ruleset.root = this.root; ruleset.root = this.root;
@ -101,7 +101,7 @@ tree.Ruleset.prototype = {
if (match = selector.match(rule.selectors[j])) { if (match = selector.match(rule.selectors[j])) {
if (selector.elements.length > 1) { if (selector.elements.length > 1) {
Array.prototype.push.apply(rules, rule.find( Array.prototype.push.apply(rules, rule.find(
new(tree.Selector)(selector.elements.slice(1)), self)); new tree.Selector(selector.elements.slice(1)), self));
} else { } else {
rules.push(rule); rules.push(rule);
} }

View File

@ -18,7 +18,7 @@ tree.URL.prototype = {
return this.value.toCSS(); return this.value.toCSS();
}, },
eval: function(ctx) { eval: function(ctx) {
return this.attrs ? this : new(tree.URL)(this.value.eval(ctx), this.paths); return this.attrs ? this : new tree.URL(this.value.eval(ctx), this.paths);
} }
}; };

View File

@ -9,7 +9,7 @@ tree.Value.prototype = {
if (this.value.length === 1) { if (this.value.length === 1) {
return this.value[0].eval(env); return this.value[0].eval(env);
} else { } else {
return new(tree.Value)(this.value.map(function(v) { return new tree.Value(this.value.map(function(v) {
return v.eval(env); return v.eval(env);
})); }));
} }