Skip to content

Commit 77a108b

Browse files
refactor(attributes-to-props): remove string type check in cssToJs
Since it does not provide any value as style is either undefined, null, or string.
1 parent 0c27987 commit 77a108b

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

lib/attributes-to-props.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,24 @@ function attributesToProps(attributes) {
6868
}
6969

7070
/**
71-
* Converts CSS style string to JS style object.
71+
* Converts inline CSS style to POJO (Plain Old JavaScript Object).
7272
*
73-
* @param {String} style - The CSS style.
74-
* @return {Object} - The JS style object.
73+
* @param {String} style - The inline CSS style.
74+
* @return {Object} - The style object.
7575
*/
7676
function cssToJs(style) {
77-
if (typeof style !== 'string') {
78-
throw new TypeError('First argument must be a string.');
77+
var styleObject = {};
78+
79+
if (style) {
80+
styleToObject(style, function(property, value) {
81+
// skip CSS comment
82+
if (property && value) {
83+
styleObject[camelCase(property)] = value;
84+
}
85+
});
7986
}
8087

81-
var styleObj = {};
82-
83-
styleToObject(style, function(property, value) {
84-
// skip if it's a comment node
85-
if (property && value) {
86-
styleObj[camelCase(property)] = value;
87-
}
88-
});
89-
90-
return styleObj;
88+
return styleObject;
9189
}
9290

9391
module.exports = attributesToProps;

test/attributes-to-props.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,6 @@ describe('attributes-to-props', () => {
234234
}
235235
);
236236
});
237-
238-
[Object, Array, Number, Date, Function].forEach(type => {
239-
it(`throws an error when attributes.style=${type.name}`, () => {
240-
assert.throws(
241-
() => {
242-
attributesToProps({ style: type });
243-
},
244-
{
245-
name: 'TypeError',
246-
message: 'First argument must be a string.'
247-
}
248-
);
249-
});
250-
});
251237
});
252238

253239
describe('custom', () => {

0 commit comments

Comments
 (0)