From 81f8a7b29885765779d0c9547d33a6edca521345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 21 Jan 2011 16:17:52 -0500 Subject: [PATCH] change new(name) to new name --- bin/messc | 4 +-- lib/mess/browser.js | 24 +++++++-------- lib/mess/functions.js | 18 +++++------ lib/mess/index.js | 6 ++-- lib/mess/parser.js | 60 ++++++++++++++++++------------------- lib/mess/renderer.js | 8 ++--- lib/mess/tree/call.js | 2 +- lib/mess/tree/color.js | 2 +- lib/mess/tree/comparison.js | 2 +- lib/mess/tree/definition.js | 2 +- lib/mess/tree/dimension.js | 4 +-- lib/mess/tree/directive.js | 2 +- lib/mess/tree/expression.js | 6 ++-- lib/mess/tree/filter.js | 2 +- lib/mess/tree/import.js | 4 +-- lib/mess/tree/javascript.js | 2 +- lib/mess/tree/mixin.js | 10 +++---- lib/mess/tree/rule.js | 30 +++++++++++++++---- lib/mess/tree/ruleset.js | 4 +-- lib/mess/tree/url.js | 2 +- lib/mess/tree/value.js | 2 +- 21 files changed, 106 insertions(+), 90 deletions(-) diff --git a/bin/messc b/bin/messc index f53c830..e512d86 100755 --- a/bin/messc +++ b/bin/messc @@ -103,7 +103,7 @@ fs.readFile(input, 'utf-8', function (e, data) { }); }); } else if (options.json) { - new(mess.Renderer)({ + new mess.Renderer({ paths: [path.dirname(input)], optimization: options.optimization, filename: input @@ -116,7 +116,7 @@ fs.readFile(input, 'utf-8', function (e, data) { } }); } else { - new(mess.Parser)({ + new mess.Parser({ paths: [path.dirname(input)], optimization: options.optimization, filename: input diff --git a/lib/mess/browser.js b/lib/mess/browser.js index b042dc9..ffa3c0e 100644 --- a/lib/mess/browser.js +++ b/lib/mess/browser.js @@ -74,7 +74,7 @@ for (var i = 0; i < links.length; i++) { less.refresh = function (reload) { - var startTime = endTime = new(Date); + var startTime = endTime = new Date; loadStyleSheets(function (root, sheet, env) { if (env.local) { @@ -83,9 +83,9 @@ less.refresh = function (reload) { log("parsed " + sheet.href + " successfully."); createCSS(root.toCSS(), sheet, env.lastModified); } - log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms'); - (env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms'); - endTime = new(Date); + log("css for " + sheet.href + " generated in " + (new Date - endTime) + 'ms'); + (env.remaining === 0) && log("css generated in " + (new Date - startTime) + 'ms'); + endTime = new Date; }, reload); loadStyles(); @@ -98,7 +98,7 @@ function loadStyles() { var styles = document.getElementsByTagName('style'); for (var i = 0; i < styles.length; i++) { 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].innerHTML = tree.toCSS(); }); @@ -126,15 +126,15 @@ function loadStyleSheet(sheet, callback, reload, remaining) { xhr(sheet.href, sheet.type, function (data, lastModified) { if (!reload && styles && lastModified && - (new(Date)(lastModified).valueOf() === - new(Date)(styles.timestamp).valueOf())) { + (new Date(lastModified).valueOf() === + new Date(styles.timestamp).valueOf())) { // Use local copy createCSS(styles.css, sheet); callback(null, sheet, { local: true, remaining: remaining }); } else { // Use remote copy (re-parse) try { - new(less.Parser)({ + new less.Parser({ optimization: less.optimization, paths: [href.replace(/[\w\.-]+$/, '')], mime: sheet.type @@ -152,7 +152,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) { } } }, 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 { css.styleSheet.cssText = styles; } catch (e) { - throw new(Error)("Couldn't reassign styleSheet.cssText."); + throw new Error("Couldn't reassign styleSheet.cssText."); } } else { (function (node) { @@ -248,10 +248,10 @@ function xhr(url, type, callback, errback) { function getXMLHttpRequest() { if (window.XMLHttpRequest) { - return new(XMLHttpRequest); + return new XMLHttpRequest; } else { try { - return new(ActiveXObject)("MSXML2.XMLHTTP.3.0"); + return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch (e) { log("browser doesn't support AJAX."); return null; diff --git a/lib/mess/functions.js b/lib/mess/functions.js index 172fab5..95d7526 100644 --- a/lib/mess/functions.js +++ b/lib/mess/functions.js @@ -7,7 +7,7 @@ tree.functions = { rgba: function (r, g, b, a) { var rgb = [r, g, b].map(function (c) { return number(c) }), a = number(a); - return new(tree.Color)(rgb, a); + return new tree.Color(rgb, a); }, hsl: function (h, s, l) { return this.hsla(h, s, l, 1.0); @@ -33,16 +33,16 @@ tree.functions = { } }, hue: function (color) { - return new(tree.Dimension)(Math.round(color.toHSL().h)); + return new tree.Dimension(Math.round(color.toHSL().h)); }, 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) { - return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%'); + return new tree.Dimension(Math.round(color.toHSL().l * 100), '%'); }, alpha: function (color) { - return new(tree.Dimension)(color.toHSL().a); + return new tree.Dimension(color.toHSL().a); }, saturate: function (color, amount) { var hsl = color.toHSL(); @@ -112,13 +112,13 @@ tree.functions = { var alpha = color1.alpha * p + color2.alpha * (1 - p); - return new(tree.Color)(rgb, alpha); + return new tree.Color(rgb, alpha); }, greyscale: function (color) { - return this.desaturate(color, new(tree.Dimension)(100)); + return this.desaturate(color, new tree.Dimension(100)); }, 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, ...*/) { var args = Array.prototype.slice.call(arguments, 1), @@ -129,7 +129,7 @@ tree.functions = { .replace(/%[da]/, args[i].toCSS()); } str = str.replace(/%%/g, '%'); - return new(tree.Quoted)('"' + str + '"', str); + return new tree.Quoted('"' + str + '"', str); } }; diff --git a/lib/mess/index.js b/lib/mess/index.js index 765b2b6..5fbb7b1 100644 --- a/lib/mess/index.js +++ b/lib/mess/index.js @@ -17,7 +17,7 @@ var mess = { callback = options, options = {}; } - var parser = new(this.Parser)(options), + var parser = new this.Parser(options), ee; if (callback) { @@ -25,7 +25,7 @@ var mess = { callback(e, root.toCSS()); }); } else { - ee = new(require('events').EventEmitter); + ee = new require('events'.EventEmitter); process.nextTick(function() { 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) { if (e) sys.error(e); - new(mess.Parser)({ + new mess.Parser({ paths: [path.dirname(pathname)], filename: pathname }).parse(data, function(e, root) { diff --git a/lib/mess/parser.js b/lib/mess/parser.js index dea33b0..ba39f6b 100644 --- a/lib/mess/parser.js +++ b/lib/mess/parser.js @@ -272,7 +272,7 @@ mess.Parser = function Parser(env) { // The whole syntax tree is held under a Ruleset node, // with the `root` property set to true, so no `{}` are // 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.toCSS = (function(evaluate) { @@ -474,9 +474,9 @@ mess.Parser = function Parser(env) { if (input.charAt(i) !== '/') return; if (input.charAt(i + 1) === '/') { - return new(tree.Comment)($(/^\/\/.*/), true); + return new tree.Comment($(/^\/\/.*/), true); } 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 (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; // todo: <= if (str = $(/^=|!=|<=|>=|<|>/)) { - return new(tree.Comparison)(str); + return new tree.Comparison(str); } }, @@ -513,7 +513,7 @@ mess.Parser = function Parser(env) { // keyword: function() { 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 (name) { return new(tree.Call)(name, args) } + if (name) { return new tree.Call(name, args) } }, arguments: function() { var args = [], arg; @@ -567,10 +567,10 @@ mess.Parser = function Parser(env) { if (input.charAt(i) !== 'u' || !$(/^url\(/)) return; value = $(this.entities.quoted) || $(this.entities.variable) || $(/^[-\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) - ? value : new(tree.Anonymous)(value), imports.paths); + return new tree.URL((value.value || value.data || value instanceof tree.Variable) + ? value : new tree.Anonymous(value), imports.paths); }, // @@ -585,7 +585,7 @@ mess.Parser = function Parser(env) { var name, index = i; 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; 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 (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 (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 } 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 = $('>'); } $('(') && (args = $(this.entities.arguments)) && $(')'); if (elements.length > 0 && ($(';') || peek('}'))) { 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)) { params.push({ name: param.name, value: value }); } else { - throw new(Error)('Expected value'); + throw new Error('Expected value'); } } else { params.push({ name: param.name }); @@ -723,13 +723,13 @@ mess.Parser = function Parser(env) { } if (! $(',')) { break } } - if (! $(')')) throw new(Error)('Expected )'); + if (! $(')')) throw new Error('Expected )'); ruleset = $(this.block); if (ruleset) { 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-]+/))) { if (! $(']')) return; if (key == 'zoom') { - return new(tree.ZoomFilter)(op, val, memo); + return new tree.ZoomFilter(op, val, memo); } 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 && selectors[0].elements.length && selectors[0].elements[0].value === 'Map') { - var rs = new(tree.Ruleset)(selectors, rules); + var rs = new tree.Ruleset(selectors, rules); rs.is_map = true; return rs; } - return new(tree.Ruleset)(selectors, rules); + return new tree.Ruleset(selectors, rules); } else { // Backtrack restore(); @@ -893,7 +893,7 @@ mess.Parser = function Parser(env) { important = $(this.important); if (value && $(this.end)) { - return new(tree.Rule)(name, value, important, memo); + return new tree.Rule(name, value, important, memo); } else { furthest = i; restore(); @@ -907,7 +907,7 @@ mess.Parser = function Parser(env) { while (e = $(this.shorthand) || $(this.entity)) { expression.push(e); } - value.push(new(tree.Expression)(expression)); + value.push(new tree.Expression(expression)); if ($(',')) { while (e = $(this.expression)) { @@ -915,7 +915,7 @@ mess.Parser = function Parser(env) { 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) { - return new(tree.Value)(expressions); + return new tree.Value(expressions); } }, important: function() { @@ -954,7 +954,7 @@ mess.Parser = function Parser(env) { var m, a, op, operation; if (m = $(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; } @@ -964,7 +964,7 @@ mess.Parser = function Parser(env) { if (m = $(this.multiplication)) { while ((op = $(/^[-+]\s+/) || (input.charAt(i - 1) != ' ' && ($('+') || $('-')))) && (a = $(this.multiplication))) { - operation = new(tree.Operation)(op, [operation || m, a]); + operation = new tree.Operation(op, [operation || m, a]); } return operation || m; } @@ -994,7 +994,7 @@ mess.Parser = function Parser(env) { entities.push(e); } if (entities.length > 0) { - return new(tree.Expression)(entities); + return new tree.Expression(entities); } }, property: function() { diff --git a/lib/mess/renderer.js b/lib/mess/renderer.js index a825ada..5741f5b 100644 --- a/lib/mess/renderer.js +++ b/lib/mess/renderer.js @@ -48,7 +48,7 @@ mess.Renderer = function Renderer(env) { * @param {Function} 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 = {}, group = this.group(); for (var i = 0, l = results.length; i < l; i++) { - new(mess.Parser)(_.extend(_.extend({ + new mess.Parser(_.extend(_.extend({ filename: s }, that.env), this.env)).parse(results[i][1], function(err, tree) { @@ -361,7 +361,7 @@ mess.Renderer = function Renderer(env) { for (sym in by_symbolizer) { // Create styles out of chains of one-symbolizer rules, // and assign those styles to layers - var new_style = new(mess.tree.Style)( + var new_style = new mess.tree.Style( l.id, sym, that.process_chain(by_symbolizer[sym])); @@ -369,7 +369,7 @@ mess.Renderer = function Renderer(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()); }); diff --git a/lib/mess/tree/call.js b/lib/mess/tree/call.js index 8d00c77..989daa7 100644 --- a/lib/mess/tree/call.js +++ b/lib/mess/tree/call.js @@ -26,7 +26,7 @@ tree.Call.prototype = { if (this.name in tree.functions) { // 1. return tree.functions[this.name].apply(tree.functions, args); } else { // 2. - return new(tree.Anonymous)(this.name + + return new tree.Anonymous(this.name + '(' + args.map(function(a) { return a.toCSS() }).join(', ') + ')'); } }, diff --git a/lib/mess/tree/color.js b/lib/mess/tree/color.js index 80cf322..9791bf0 100644 --- a/lib/mess/tree/color.js +++ b/lib/mess/tree/color.js @@ -62,7 +62,7 @@ tree.Color.prototype = { for (var c = 0; c < 3; c++) { result[c] = tree.operate(op, this.rgb[c], other.rgb[c]); } - return new(tree.Color)(result); + return new tree.Color(result); }, toHSL: function() { diff --git a/lib/mess/tree/comparison.js b/lib/mess/tree/comparison.js index 21d7f51..c189a2d 100644 --- a/lib/mess/tree/comparison.js +++ b/lib/mess/tree/comparison.js @@ -15,7 +15,7 @@ tree.Comparison.prototype = { '>=': '>='}[this.value]; }, negate: function() { - return new(tree.Comparison)({ + return new tree.Comparison({ '<': '>=', '<=': '>', '>': '<=', diff --git a/lib/mess/tree/definition.js b/lib/mess/tree/definition.js index dfa51b6..6968d6e 100644 --- a/lib/mess/tree/definition.js +++ b/lib/mess/tree/definition.js @@ -20,7 +20,7 @@ tree.Definition.prototype.clone = function() { * NOTE: does not clone objects besides creating a new Ruleset. */ tree.Definition.prototype.filter_symbolizer = function(symbolizer) { - return new(tree.Definition)(this.selector, + return new tree.Definition(this.selector, this.rules.filter(function(rule) { return rule.symbolizer == symbolizer; }) diff --git a/lib/mess/tree/dimension.js b/lib/mess/tree/dimension.js index 5d3d6c9..652ad6f 100644 --- a/lib/mess/tree/dimension.js +++ b/lib/mess/tree/dimension.js @@ -12,7 +12,7 @@ tree.Dimension = function(value, unit) { tree.Dimension.prototype = { eval: function() { return this }, toColor: function() { - return new(tree.Color)([this.value, this.value, this.value]); + return new tree.Color([this.value, this.value, this.value]); }, toCSS: function() { return this.value; @@ -25,7 +25,7 @@ tree.Dimension.prototype = { // conversions such that `100cm + 10mm` would yield // `101cm`. operate: function(op, other) { - return new(tree.Dimension); + return new tree.Dimension; (tree.operate(op, this.value, other.value), this.unit || other.unit); } diff --git a/lib/mess/tree/directive.js b/lib/mess/tree/directive.js index 2d4ef52..25ebae1 100644 --- a/lib/mess/tree/directive.js +++ b/lib/mess/tree/directive.js @@ -3,7 +3,7 @@ tree.Directive = function(name, value) { this.name = name; if (Array.isArray(value)) { - this.ruleset = new(tree.Ruleset)([], value); + this.ruleset = new tree.Ruleset([], value); } else { this.value = value; } diff --git a/lib/mess/tree/expression.js b/lib/mess/tree/expression.js index 9bc1086..a229143 100644 --- a/lib/mess/tree/expression.js +++ b/lib/mess/tree/expression.js @@ -1,12 +1,10 @@ (function(tree) { -tree.Expression = function(value) { - this.value = value; -}; +tree.Expression = function(value) { this.value = value }; tree.Expression.prototype = { eval: function(env) { 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); })); } else { diff --git a/lib/mess/tree/filter.js b/lib/mess/tree/filter.js index c8e3c4c..b119a3f 100644 --- a/lib/mess/tree/filter.js +++ b/lib/mess/tree/filter.js @@ -24,7 +24,7 @@ tree.Filter.prototype.toXML = function(env) { * TODO: should this have an index? */ 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')); diff --git a/lib/mess/tree/import.js b/lib/mess/tree/import.js index e724b7a..ad6842a 100644 --- a/lib/mess/tree/import.js +++ b/lib/mess/tree/import.js @@ -29,7 +29,7 @@ tree.Import = function(path, imports) { if (! this.css) { imports.push(this.path, function(root) { if (! root) { - throw new(Error)('Error parsing ' + that.path); + throw new Error('Error parsing ' + that.path); } that.root = root; }); @@ -59,7 +59,7 @@ tree.Import.prototype = { if (this.css) { return this; } 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++) { if (ruleset.rules[i] instanceof tree.Import) { diff --git a/lib/mess/tree/javascript.js b/lib/mess/tree/javascript.js index 945be2f..5ea9752 100644 --- a/lib/mess/tree/javascript.js +++ b/lib/mess/tree/javascript.js @@ -10,7 +10,7 @@ tree.JavaScript.prototype = { }, eval: function(env) { var result, - expression = new(Function)('return (' + this.expression + ')'), + expression = new Function('return (' + this.expression + ')'), context = {}; for (var k in env.frames[0].variables()) { diff --git a/lib/mess/tree/mixin.js b/lib/mess/tree/mixin.js index 01e4d9e..ce6156e 100644 --- a/lib/mess/tree/mixin.js +++ b/lib/mess/tree/mixin.js @@ -2,7 +2,7 @@ tree.mixin = {}; tree.mixin.Call = function(elements, args, index) { - this.selector = new(tree.Selector)(elements); + this.selector = new tree.Selector(elements); this.arguments = args; this.index = index; }; @@ -42,7 +42,7 @@ tree.mixin.Call.prototype = { tree.mixin.Definition = function(name, params, rules) { 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.arity = params.length; this.rules = rules; @@ -62,19 +62,19 @@ tree.mixin.Definition.prototype = { rulesets: function() { return this.parent.rulesets.apply(this) }, 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++) { if (this.params[i].name) { 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 { throw { message: 'wrong number of arguments for ' + this.name + ' (' + 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) }); }, diff --git a/lib/mess/tree/rule.js b/lib/mess/tree/rule.js index a7e1b0d..d7a8ead 100644 --- a/lib/mess/tree/rule.js +++ b/lib/mess/tree/rule.js @@ -2,11 +2,14 @@ tree.Rule = function(name, value, important, index) { this.name = name; this.value = (value instanceof tree.Value) ? - value : new(tree.Value)([value]); + value : new tree.Value([value]); this.important = important ? ' ' + important.trim() : ''; this.index = index; 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) { @@ -34,9 +37,12 @@ tree.Rule.prototype.toCSS = function(env) { }; } - if (this.variable) { - return '' - } else { + if (!this.value) { + console.log(this); + } + + if (this.variable) { return '' } + else { return tree.Reference.selectorName(this.name) + '="' + this.value.toCSS(env, this.name) + @@ -45,10 +51,22 @@ tree.Rule.prototype.toCSS = function(env) { }; tree.Rule.prototype.eval = function(context) { - return new(tree.Rule)(this.name, + return new tree.Rule(this.name, this.value.eval(context), this.important, 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')); diff --git a/lib/mess/tree/ruleset.js b/lib/mess/tree/ruleset.js index 3f44fa8..819199f 100644 --- a/lib/mess/tree/ruleset.js +++ b/lib/mess/tree/ruleset.js @@ -8,7 +8,7 @@ tree.Ruleset = function(selectors, rules) { }; tree.Ruleset.prototype = { 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; @@ -101,7 +101,7 @@ tree.Ruleset.prototype = { if (match = selector.match(rule.selectors[j])) { if (selector.elements.length > 1) { Array.prototype.push.apply(rules, rule.find( - new(tree.Selector)(selector.elements.slice(1)), self)); + new tree.Selector(selector.elements.slice(1)), self)); } else { rules.push(rule); } diff --git a/lib/mess/tree/url.js b/lib/mess/tree/url.js index b2b83f3..feaa00b 100644 --- a/lib/mess/tree/url.js +++ b/lib/mess/tree/url.js @@ -18,7 +18,7 @@ tree.URL.prototype = { return this.value.toCSS(); }, 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); } }; diff --git a/lib/mess/tree/value.js b/lib/mess/tree/value.js index a84b605..1f0aa65 100644 --- a/lib/mess/tree/value.js +++ b/lib/mess/tree/value.js @@ -9,7 +9,7 @@ tree.Value.prototype = { if (this.value.length === 1) { return this.value[0].eval(env); } else { - return new(tree.Value)(this.value.map(function(v) { + return new tree.Value(this.value.map(function(v) { return v.eval(env); })); }