change new(name) to new name
This commit is contained in:
parent
90ac51a804
commit
81f8a7b298
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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() {
|
||||
|
@ -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());
|
||||
});
|
||||
|
||||
|
@ -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(', ') + ')');
|
||||
}
|
||||
},
|
||||
|
@ -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() {
|
||||
|
@ -15,7 +15,7 @@ tree.Comparison.prototype = {
|
||||
'>=': '>='}[this.value];
|
||||
},
|
||||
negate: function() {
|
||||
return new(tree.Comparison)({
|
||||
return new tree.Comparison({
|
||||
'<': '>=',
|
||||
'<=': '>',
|
||||
'>': '<=',
|
||||
|
@ -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;
|
||||
})
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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'));
|
||||
|
@ -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) {
|
||||
|
@ -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()) {
|
||||
|
@ -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)
|
||||
});
|
||||
},
|
||||
|
@ -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'));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user