diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 7d90d58944..bb2cde62d7 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -840,17 +840,23 @@ export function generatePropertyAliases( /** * Mapping between attributes names that don't correspond to their element property names. + * + * Performance note: this function is written as a series of if checks (instead of, say, a property + * object lookup) for performance reasons - the series of `if` checks seems to be the fastest way of + * mapping property names. Do NOT change without benchmarking. + * * Note: this mapping has to be kept in sync with the equally named mapping in the template * type-checking machinery of ngtsc. */ -const ATTR_TO_PROP: {[name: string]: string} = { - 'class': 'className', - 'for': 'htmlFor', - 'formaction': 'formAction', - 'innerHtml': 'innerHTML', - 'readonly': 'readOnly', - 'tabindex': 'tabIndex', -}; +function mapPropName(name: string): string { + if (name === 'class') return 'className'; + if (name === 'for') return 'htmlFor'; + if (name === 'formaction') return 'formAction'; + if (name === 'innerHtml') return 'innerHTML'; + if (name === 'readonly') return 'readOnly'; + if (name === 'tabindex') return 'tabIndex'; + return name; +} export function elementPropertyInternal( index: number, propName: string, value: T, sanitizer?: SanitizerFn | null, nativeOnly?: boolean, @@ -883,7 +889,7 @@ export function elementPropertyInternal( } } } else if (tNode.type === TNodeType.Element) { - propName = ATTR_TO_PROP[propName] || propName; + propName = mapPropName(propName); if (ngDevMode) { validateAgainstEventProperties(propName); diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index aa8573af09..202c55550b 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -5,9 +5,6 @@ { "name": "ANIMATION_PROP_PREFIX" }, - { - "name": "ATTR_TO_PROP" - }, { "name": "BINDING_INDEX" }, @@ -1085,6 +1082,9 @@ { "name": "makeParamDecorator" }, + { + "name": "mapPropName" + }, { "name": "markAsComponentHost" },