diff --git a/lib/carto/renderer.js b/lib/carto/renderer.js
index 2297c19..ce14af1 100644
--- a/lib/carto/renderer.js
+++ b/lib/carto/renderer.js
@@ -228,7 +228,8 @@ carto.Renderer.prototype.render = function render(m, callback) {
//
// @param {Array} the current list of rules
// @param {Object} definition a Definition object to add to the rules
-// @param {Object} byFilter an object/dictionary of existing filters
+// @param {Object} byFilter an object/dictionary of existing filters. This is
+// actually keyed `attachment->filter`
// @param {Object} env the current environment
function addRules(current, definition, byFilter, env) {
var newFilters = definition.filters,
@@ -296,7 +297,8 @@ function inheritDefinitions(definitions, env) {
var inheritTime = +new Date();
// definitions are ordered by specificity,
// high (index 0) to low
- var byAttachment = {}, byFilter = {};
+ var byAttachment = {},
+ byFilter = {};
var result = [];
var current, previous, attachment;
@@ -307,19 +309,22 @@ function inheritDefinitions(definitions, env) {
});
for (var i = 0; i < definitions.length; i++) {
+
attachment = definitions[i].attachment;
current = [definitions[i]];
+
if (!byAttachment[attachment]) {
byAttachment[attachment] = [];
byAttachment[attachment].attachment = attachment;
byFilter[attachment] = {};
result.push(byAttachment[attachment]);
}
+
// Iterate over all subsequent rules.
for (var j = i + 1; j < definitions.length; j++) {
if (definitions[j].attachment === attachment) {
// Only inherit rules from the same attachment.
- current = addRules(current, definitions[j], byFilter, env);
+ current = addRules(current, definitions[j], byFilter[attachment], env);
}
}
diff --git a/test/rendering-mss/issue_284.mss b/test/rendering-mss/issue_284.mss
index 05ed06b..e53218f 100644
--- a/test/rendering-mss/issue_284.mss
+++ b/test/rendering-mss/issue_284.mss
@@ -2,7 +2,7 @@
[type='primary'] {
line-color: red;
}
- [foo='bar'] {
+ [foo='bar'] {
line-width: 10;
}
}
@@ -14,4 +14,4 @@
[foo='bar'] {
line-width: 10;
}
-}
\ No newline at end of file
+}
diff --git a/test/rendering-mss/issue_284.xml b/test/rendering-mss/issue_284.xml
index 0680115..8603ecc 100644
--- a/test/rendering-mss/issue_284.xml
+++ b/test/rendering-mss/issue_284.xml
@@ -1,4 +1,4 @@
-
-