Skip to content

Commit 404335b

Browse files
author
Chris Joel
committed
Non-destructive @keyframes rule transformation.
Previously, the transformer did not disambiguate selectors in `@media` blocks and keyframes in `@keyframes` blocks. Now, the transformer can safely transform `@keyframes` blocks. Before a selector is transformed, if the selector has a parent, it is checked. If the checked parent is a `@keyframes` rule, the selector transformation is skipped.
1 parent 090e9d6 commit 404335b

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/lib/style-transformer.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@
147147

148148
// transforms a css rule to a scoped rule.
149149
_transformRule: function(rule, transformer, scope, hostScope) {
150+
var selectorCanTransform =
151+
!rule.parent ||
152+
rule.parent.ruleType !== Polymer.StyleUtil.ruleTypes.KEYFRAMES_RULE;
150153
var p$ = rule.selector.split(COMPLEX_SELECTOR_SEP);
151-
for (var i=0, l=p$.length, p; (i<l) && (p=p$[i]); i++) {
152-
p$[i] = transformer.call(this, p, scope, hostScope);
154+
if (selectorCanTransform) {
155+
for (var i=0, l=p$.length, p; (i<l) && (p=p$[i]); i++) {
156+
p$[i] = transformer.call(this, p, scope, hostScope);
157+
}
153158
}
154159
// NOTE: save transformedSelector for subsequent matching of elements
155160
// against selectors (e.g. when calculating style properties)

src/lib/style-util.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
var skipRules = false;
5252
if (node.type === this.ruleTypes.STYLE_RULE) {
5353
callback(node);
54-
} else if (node.type === this.ruleTypes.KEYFRAMES_RULE ||
55-
node.type === this.ruleTypes.MIXIN_RULE) {
54+
} else if (node.type === this.ruleTypes.MIXIN_RULE) {
5655
skipRules = true;
5756
}
5857
var r$ = node.rules;

test/unit/css-parse.html

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
assert.equal(tree.rules.length, 4, 'unexpected number of rules');
117117
assert.equal(tree.rules[2].rules.length, 8, 'unexpected number of rules in keyframes');
118118
assert.equal(tree.rules[3].rules.length, 1, 'unexpected number of rules in @media');
119-
console.log('test');
120119
});
121120

122121
test('rule selectors parse', function() {

0 commit comments

Comments
 (0)