mirror of
https://github.com/facebook/react.git
synced 2026-02-27 03:07:57 +00:00
This is a follow up to https://github.com/facebook/react/pull/26546 This is strictly a perf optimization since we know that switches over strings aren't optimally implemented in current engines. Basically they're a sequence of ifs. As a result, we're better off putting the unusual cases in a Map and the very common cases in the beginning of the switch. We might be better off putting very common cases in explicit ifs - just in case the engine does optimize switches to a hash table which is potentially worse. --------- Co-authored-by: Sophie Alpert <git@sophiebits.com>
97 lines
3.4 KiB
JavaScript
97 lines
3.4 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
const aliases = new Map([
|
|
['acceptCharset', 'accept-charset'],
|
|
['htmlFor', 'for'],
|
|
['httpEquiv', 'http-equiv'],
|
|
// HTML and SVG attributes, but the SVG attribute is case sensitive.],
|
|
['crossOrigin', 'crossorigin'],
|
|
// This is a list of all SVG attributes that need special casing.
|
|
// Regular attributes that just accept strings.],
|
|
['accentHeight', 'accent-height'],
|
|
['alignmentBaseline', 'alignment-baseline'],
|
|
['arabicForm', 'arabic-form'],
|
|
['baselineShift', 'baseline-shift'],
|
|
['capHeight', 'cap-height'],
|
|
['clipPath', 'clip-path'],
|
|
['clipRule', 'clip-rule'],
|
|
['colorInterpolation', 'color-interpolation'],
|
|
['colorInterpolationFilters', 'color-interpolation-filters'],
|
|
['colorProfile', 'color-profile'],
|
|
['colorRendering', 'color-rendering'],
|
|
['dominantBaseline', 'dominant-baseline'],
|
|
['enableBackground', 'enable-background'],
|
|
['fillOpacity', 'fill-opacity'],
|
|
['fillRule', 'fill-rule'],
|
|
['floodColor', 'flood-color'],
|
|
['floodOpacity', 'flood-opacity'],
|
|
['fontFamily', 'font-family'],
|
|
['fontSize', 'font-size'],
|
|
['fontSizeAdjust', 'font-size-adjust'],
|
|
['fontStretch', 'font-stretch'],
|
|
['fontStyle', 'font-style'],
|
|
['fontVariant', 'font-variant'],
|
|
['fontWeight', 'font-weight'],
|
|
['glyphName', 'glyph-name'],
|
|
['glyphOrientationHorizontal', 'glyph-orientation-horizontal'],
|
|
['glyphOrientationVertical', 'glyph-orientation-vertical'],
|
|
['horizAdvX', 'horiz-adv-x'],
|
|
['horizOriginX', 'horiz-origin-x'],
|
|
['imageRendering', 'image-rendering'],
|
|
['letterSpacing', 'letter-spacing'],
|
|
['lightingColor', 'lighting-color'],
|
|
['markerEnd', 'marker-end'],
|
|
['markerMid', 'marker-mid'],
|
|
['markerStart', 'marker-start'],
|
|
['overlinePosition', 'overline-position'],
|
|
['overlineThickness', 'overline-thickness'],
|
|
['paintOrder', 'paint-order'],
|
|
['panose-1', 'panose-1'],
|
|
['pointerEvents', 'pointer-events'],
|
|
['renderingIntent', 'rendering-intent'],
|
|
['shapeRendering', 'shape-rendering'],
|
|
['stopColor', 'stop-color'],
|
|
['stopOpacity', 'stop-opacity'],
|
|
['strikethroughPosition', 'strikethrough-position'],
|
|
['strikethroughThickness', 'strikethrough-thickness'],
|
|
['strokeDasharray', 'stroke-dasharray'],
|
|
['strokeDashoffset', 'stroke-dashoffset'],
|
|
['strokeLinecap', 'stroke-linecap'],
|
|
['strokeLinejoin', 'stroke-linejoin'],
|
|
['strokeMiterlimit', 'stroke-miterlimit'],
|
|
['strokeOpacity', 'stroke-opacity'],
|
|
['strokeWidth', 'stroke-width'],
|
|
['textAnchor', 'text-anchor'],
|
|
['textDecoration', 'text-decoration'],
|
|
['textRendering', 'text-rendering'],
|
|
['transformOrigin', 'transform-origin'],
|
|
['underlinePosition', 'underline-position'],
|
|
['underlineThickness', 'underline-thickness'],
|
|
['unicodeBidi', 'unicode-bidi'],
|
|
['unicodeRange', 'unicode-range'],
|
|
['unitsPerEm', 'units-per-em'],
|
|
['vAlphabetic', 'v-alphabetic'],
|
|
['vHanging', 'v-hanging'],
|
|
['vIdeographic', 'v-ideographic'],
|
|
['vMathematical', 'v-mathematical'],
|
|
['vectorEffect', 'vector-effect'],
|
|
['vertAdvY', 'vert-adv-y'],
|
|
['vertOriginX', 'vert-origin-x'],
|
|
['vertOriginY', 'vert-origin-y'],
|
|
['wordSpacing', 'word-spacing'],
|
|
['writingMode', 'writing-mode'],
|
|
['xmlnsXlink', 'xmlns:xlink'],
|
|
['xHeight', 'x-height'],
|
|
]);
|
|
|
|
export default function (name: string): string {
|
|
return aliases.get(name) || name;
|
|
}
|