Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Commit

Permalink
Fix keyframe renaming when keyframe names are subsets of others
Browse files Browse the repository at this point in the history
Fixes #148
  • Loading branch information
dfreedm committed Jan 11, 2018
1 parent ccfa2ec commit 55cc040
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scoping-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scoping-shim.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/style-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ class StyleProperties {
* @param {string} scopeId
*/
_scopeKeyframes(rule, scopeId) {
rule.keyframesNameRx = new RegExp(rule['keyframesName'], 'g');
// Animation names are of the form [\w-], so ensure that the name regex does not partially apply
// to similarly named keyframe names by checking for a word boundary at the beginning and
// a non-word boundary or `-` at the end.
rule.keyframesNameRx = new RegExp(`\\b${rule['keyframesName']}(?!\\B|-)`, 'g');
rule.transformedKeyframesName = rule['keyframesName'] + '-' + scopeId;
rule.transformedSelector = rule.transformedSelector || rule['selector'];
rule['selector'] = rule.transformedSelector.replace(
Expand Down
35 changes: 35 additions & 0 deletions tests/scoping.html
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,29 @@
<unscoped-apply-user></unscoped-apply-user>
</template>

<template id="scoped-keyframes">
<style>
:host {
--time: 1s;
}

div {
animation-name: slide-back;
animation-duration: var(--time);
animation-fill-mode: forwards;
}

@keyframes slide {}
@keyframes slide-back {
to {
transform: translateX(-100px);
}
}
</style>

<div id="target">Hello world</div>
</template>

<script>
(function() {
function assertComputed(element, value, property, pseudo) {
Expand Down Expand Up @@ -696,6 +719,18 @@
assertComputed(xKeyframes, '0px', 'left');
});

test('keyframe names are transformed correctly', function(done) {
makeElement('scoped-keyframes');
var e = document.createElement('scoped-keyframes');
document.body.appendChild(e);
flush();
setTimeout(function() {
var transform = getComputedStyle(e.shadowRoot.querySelector('#target')).getPropertyValue('transform');
assert.notEqual(transform, 'none');
done();
}, 1000);
});

test('attribute inclusive selector and general sibling selectors', function() {
var x = document.createElement('x-attr-selector');
x.id = 'x';
Expand Down

0 comments on commit 55cc040

Please sign in to comment.