Skip to content

Commit b183b98

Browse files
committed
Merge pull request #419 from ericwilligers/deprecate-hyphens
Use of hyphens in property names is deprecated
2 parents c109fa9 + 0e705ca commit b183b98

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/property-interpolation.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
(function(scope, testing) {
15+
(function(shared, scope, testing) {
1616

1717
var propertyHandlers = {};
1818

19+
function toCamelCase(property) {
20+
return property.replace(/-(.)/g, function(_, c) {
21+
return c.toUpperCase();
22+
});
23+
}
24+
1925
function addPropertyHandler(parser, merger, property) {
2026
propertyHandlers[property] = propertyHandlers[property] || [];
2127
propertyHandlers[property].push([parser, merger]);
@@ -24,13 +30,7 @@
2430
for (var i = 0; i < properties.length; i++) {
2531
var property = properties[i];
2632
WEB_ANIMATIONS_TESTING && console.assert(property.toLowerCase() === property);
27-
addPropertyHandler(parser, merger, property);
28-
if (/-/.test(property)) {
29-
// Add camel cased variant.
30-
addPropertyHandler(parser, merger, property.replace(/-(.)/g, function(_, c) {
31-
return c.toUpperCase();
32-
}));
33-
}
33+
addPropertyHandler(parser, merger, toCamelCase(property));
3434
}
3535
}
3636
scope.addPropertiesHandler = addPropertiesHandler;
@@ -90,16 +90,17 @@
9090
};
9191

9292
function propertyInterpolation(property, left, right) {
93+
var ucProperty = property;
94+
if (/-/.test(property) && !shared.isDeprecated('Hyphenated property names', '2016-03-22', 'Use camelCase instead.', true)) {
95+
ucProperty = toCamelCase(property);
96+
}
9397
if (left == 'initial' || right == 'initial') {
94-
var ucProperty = property.replace(/-(.)/g, function(_, c) {
95-
return c.toUpperCase();
96-
});
9798
if (left == 'initial')
9899
left = initialValues[ucProperty];
99100
if (right == 'initial')
100101
right = initialValues[ucProperty];
101102
}
102-
var handlers = left == right ? [] : propertyHandlers[property];
103+
var handlers = left == right ? [] : propertyHandlers[ucProperty];
103104
for (var i = 0; handlers && i < handlers.length; i++) {
104105
var parsedLeft = handlers[i][0](left);
105106
var parsedRight = handlers[i][0](right);
@@ -121,5 +122,5 @@
121122
}
122123
scope.propertyInterpolation = propertyInterpolation;
123124

124-
})(webAnimations1, webAnimationsTesting);
125+
})(webAnimationsShared, webAnimations1, webAnimationsTesting);
125126

test/js/color-handler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ suite('color-handler', function() {
2121
assert.equal(webAnimations1.propertyInterpolation('color', 'red', 'green')(-1), 'rgba(255,0,0,1)');
2222
});
2323
test('interpolation to/from initial', function() {
24-
assert.equal(webAnimations1.propertyInterpolation('background-color', 'initial', 'red')(0.5), 'rgba(255,0,0,0.500)');
2524
assert.equal(webAnimations1.propertyInterpolation('backgroundColor', 'initial', 'red')(0.5), 'rgba(255,0,0,0.500)');
2625
});
2726
});

test/js/property-interpolation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ suite('property-interpolation', function() {
2424
return [a, b, function(x) { return a + b; }];
2525
};
2626
webAnimations1.addPropertiesHandler(Number, merge, ['dummy-property']);
27-
assert.equal(webAnimations1.propertyInterpolation('dummy-property', 1, 2)(0.5), 3);
2827
assert.equal(webAnimations1.propertyInterpolation('dummyProperty', 5, 3)(0.5), 8);
2928
});
3029
});

0 commit comments

Comments
 (0)