Sanitize proxy component name to minimize exceptions.#58
Sanitize proxy component name to minimize exceptions.#58leidegre wants to merge 1 commit intogaearon:nextfrom
Conversation
| function sanitizeFunctionName(fn) { | ||
| if (SIMPLE_IDENT_PATTERN.test(fn)) { | ||
| return isNaN(parseInt(fn)) ? fn : '_' + fn; | ||
| } |
There was a problem hiding this comment.
Nitpick: too many spaces before return.
|
Thanks! Can you please add some tests? I think displayName tests are in consistency.js. |
|
I'll fix that together with the spaces later today. |
|
I took a look at the things you mentioned.
I'd much rather like to provide the function as a utility and tests that in isolation. Just to ensure that its behavior is as it should. I'm not overly familiar with the source code but from what I can tell though, the component name is overshadowed anyway. Unless I'm missing something. This is only really necessary if we can't create a dynamic constructor and Please correct me if I'm off here. |
We have a test for this. Let’s just give that function a weird name. |
Sanitize the display name to be able to act as a component name without causing issues if display name is not a valid identifier. This happens all the time with Redux components.
It's a very simple test that is more aggressive than the JavaScript identifier rules but it is also very simple.
Here's a Fiddle with some tests https://jsfiddle.net/rzyfr1hz/
J