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

Commit

Permalink
Add support for deprecated camelCase'd SVG props. Fixes #222.
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Oct 5, 2016
1 parent 7402873 commit e0bc12c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const AUTOBIND_BLACKLIST = {
};


const CAMEL_PROPS = /^(accent|alignment|arabic|baseline|cap|clip|color|fill|flood|font|glyph|horiz|marker|overline|paint|stop|strikethrough|stroke|text|underline|unicode|units|v|vert|word|writing|x)[A-Z]/g;

This comment has been minimized.

Copy link
@billneff79

billneff79 Oct 6, 2016

Contributor

For one character more, your regex match can be twice as fast. you don't need the global flag, and you should use a non-capturing group:
CAMEL_PROPS = /^(?:accent.../;

https://esbench.com/bench/57f6475a330ab09900a1a218

This comment has been minimized.

Copy link
@developit

developit Oct 6, 2016

Author Member

Looks like using RegExp#test() with the non-capturing group is fastest by quite a bit:

screen shot 2016-10-06 at 10 16 38 am

https://esbench.com/bench/57f6579f330ab09900a1a250

This comment has been minimized.

Copy link
@developit

developit Oct 6, 2016

Author Member

Doubled performance! 598de5c



const BYPASS_HOOK = {};

/*global process*/
Expand Down Expand Up @@ -96,6 +99,15 @@ function handleVNode(vnode) {

if (vnode.children) a.children = vnode.children;
}
else if (a) {
for (let i in a) {
if (a.hasOwnProperty(i) && i.match(CAMEL_PROPS)) {

This comment has been minimized.

Copy link
@billneff79

billneff79 Oct 6, 2016

Contributor

IF you want, you can squeek out a tiny bit more performance by using i.search(CAMEL_PROPS)>-1 instead of i.match(CAMEL_PROPS)

a[i.replace(/([A-Z0-9])/g, '-$1').toLowerCase()] = a[i];
delete a[i];
}
}
}
}



Expand Down
10 changes: 10 additions & 0 deletions test/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ describe('svg', () => {

expect(scratch.innerHTML).to.equal('<svg viewBox="0 0 360 360"><path stroke="white" fill="black" d="M347.1 357.9L183.3 256.5 13 357.9V1.7h334.1v356.2zM58.5 47.2v231.4l124.8-74.1 118.3 72.8V47.2H58.5z"></path></svg>');
});

it('should render SVG to DOM', () => {
React.render((
<svg viewBox="0 0 100 100">
<text textAnchor="mid">foo</text>
</svg>
), scratch);

expect(scratch.innerHTML).to.equal('<svg viewBox="0 0 100 100"><text text-anchor="mid">foo</text></svg>');
});
});

0 comments on commit e0bc12c

Please sign in to comment.