diff --git a/packages/react/src/ReactChildren.js b/packages/react/src/ReactChildren.js index efb9a2a84b36f..3f74696c6be5a 100644 --- a/packages/react/src/ReactChildren.js +++ b/packages/react/src/ReactChildren.js @@ -28,17 +28,37 @@ const SUBSEPARATOR = ':'; * @param {string} key to be escaped. * @return {string} the escaped key. */ -function escape(key) { - const escapeRegex = /[=:]/g; - const escaperLookup = { - '=': '=0', - ':': '=2', - }; - const escapedString = ('' + key).replace(escapeRegex, function(match) { - return escaperLookup[match]; - }); - - return '$' + escapedString; +const escapeRegex = /[=:]/g; +function escape(key: string): string { + const str = '' + key; + + let escapeChar; + let result = '$'; + let lastIndex = 0; + + for ( + let match = escapeRegex.exec(str); + match; + match = escapeRegex.exec(str) + ) { + switch (str.charCodeAt(match.index)) { + case 61: // = + escapeChar = '=0'; + break; + case 58: // : + escapeChar = '=2'; + break; + default: + continue; + } + + if (lastIndex !== match.index) { + result += str.substring(lastIndex, match.index); + } + lastIndex = match.index + 1; + result += escapeChar; + } + return result + str.substring(lastIndex); } /** diff --git a/packages/react/src/__tests__/ReactChildren-test.js b/packages/react/src/__tests__/ReactChildren-test.js index 952807851c9b4..4c3dfbe689742 100644 --- a/packages/react/src/__tests__/ReactChildren-test.js +++ b/packages/react/src/__tests__/ReactChildren-test.js @@ -911,10 +911,20 @@ describe('ReactChildren', () => { it('should escape keys', () => { const zero =
; const one =
; + const two =
; + const three =
; + const four =
; + const five =
; + const six =
; const instance = (
{zero} {one} + {two} + {three} + {four} + {five} + {six}
); const mappedChildren = React.Children.map( @@ -924,6 +934,11 @@ describe('ReactChildren', () => { expect(mappedChildren).toEqual([
,
, +
, +
, +
, +
, +
, ]); }); diff --git a/scripts/bench/yarn.lock b/scripts/bench/yarn.lock index 93e1624cf6304..d8a2fe199093b 100644 --- a/scripts/bench/yarn.lock +++ b/scripts/bench/yarn.lock @@ -1231,11 +1231,7 @@ semver-diff@^2.0.0: dependencies: semver "^5.0.3" -"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0: - version "5.4.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" - -semver@~5.3.0: +"semver@2 || 3 || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index eaded2bf89449..5a36a656e7270 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -1,52 +1,52 @@ { "bundleSizes": { "react.development.js (UMD_DEV)": { - "size": 54827, - "gzip": 14889 + "size": 55378, + "gzip": 15063 }, "react.production.min.js (UMD_PROD)": { - "size": 6638, - "gzip": 2814 + "size": 6795, + "gzip": 2908 }, "react.development.js (NODE_DEV)": { - "size": 45243, - "gzip": 12588 + "size": 45794, + "gzip": 12761 }, "react.production.min.js (NODE_PROD)": { - "size": 5433, - "gzip": 2366 + "size": 5581, + "gzip": 2454 }, "React-dev.js (FB_DEV)": { - "size": 44587, - "gzip": 12097 + "size": 45147, + "gzip": 12269 }, "React-prod.js (FB_PROD)": { - "size": 12883, - "gzip": 3454 + "size": 13555, + "gzip": 3606 }, "react-dom.development.js (UMD_DEV)": { - "size": 574228, - "gzip": 133513 + "size": 574390, + "gzip": 134564 }, "react-dom.production.min.js (UMD_PROD)": { - "size": 96421, - "gzip": 31352 + "size": 96372, + "gzip": 31334 }, "react-dom.development.js (NODE_DEV)": { - "size": 555649, - "gzip": 129174 + "size": 555811, + "gzip": 130187 }, "react-dom.production.min.js (NODE_PROD)": { - "size": 94318, - "gzip": 30178 + "size": 94275, + "gzip": 30285 }, "ReactDOM-dev.js (FB_DEV)": { - "size": 573653, - "gzip": 131283 + "size": 573827, + "gzip": 132455 }, "ReactDOM-prod.js (FB_PROD)": { - "size": 272535, - "gzip": 51556 + "size": 272443, + "gzip": 51717 }, "react-dom-test-utils.development.js (NODE_DEV)": { "size": 36193, @@ -117,64 +117,64 @@ "gzip": 5914 }, "react-art.development.js (UMD_DEV)": { - "size": 361747, - "gzip": 80408 + "size": 362006, + "gzip": 80510 }, "react-art.production.min.js (UMD_PROD)": { "size": 84292, "gzip": 26065 }, "react-art.development.js (NODE_DEV)": { - "size": 285834, - "gzip": 61333 + "size": 286093, + "gzip": 61430 }, "react-art.production.min.js (NODE_PROD)": { "size": 47976, "gzip": 15085 }, "ReactART-dev.js (FB_DEV)": { - "size": 290183, - "gzip": 61074 + "size": 290446, + "gzip": 61176 }, "ReactART-prod.js (FB_PROD)": { "size": 149114, "gzip": 25640 }, "ReactNativeRenderer-dev.js (RN_DEV)": { - "size": 415491, - "gzip": 91701 + "size": 415754, + "gzip": 91798 }, "ReactNativeRenderer-prod.js (RN_PROD)": { "size": 201086, "gzip": 34724 }, "ReactRTRenderer-dev.js (RN_DEV)": { - "size": 290573, - "gzip": 61998 + "size": 290836, + "gzip": 62091 }, "ReactRTRenderer-prod.js (RN_PROD)": { "size": 138274, "gzip": 23358 }, "ReactCSRenderer-dev.js (RN_DEV)": { - "size": 281173, - "gzip": 59079 + "size": 281436, + "gzip": 59177 }, "ReactCSRenderer-prod.js (RN_PROD)": { "size": 130921, "gzip": 22026 }, "react-test-renderer.development.js (NODE_DEV)": { - "size": 282399, - "gzip": 60134 + "size": 282658, + "gzip": 60233 }, "react-test-renderer.production.min.js (NODE_PROD)": { "size": 46329, "gzip": 14428 }, "ReactTestRenderer-dev.js (FB_DEV)": { - "size": 286844, - "gzip": 59878 + "size": 287107, + "gzip": 59981 }, "react-test-renderer-shallow.development.js (NODE_DEV)": { "size": 10233, @@ -193,8 +193,8 @@ "gzip": 5097 }, "react-reconciler.development.js (NODE_DEV)": { - "size": 264252, - "gzip": 55746 + "size": 264511, + "gzip": 55845 }, "react-reconciler.production.min.js (NODE_PROD)": { "size": 39641,