refactor(ivy): access component def through tData (#22771)
PR Close #22771
This commit is contained in:
parent
3b167be069
commit
e55bf8fa79
|
@ -462,15 +462,16 @@ export function elementStart(
|
||||||
ngDevMode &&
|
ngDevMode &&
|
||||||
assertNull(currentView.bindingStartIndex, 'elements should be created before any bindings');
|
assertNull(currentView.bindingStartIndex, 'elements should be created before any bindings');
|
||||||
const isHostElement = typeof nameOrComponentType !== 'string';
|
const isHostElement = typeof nameOrComponentType !== 'string';
|
||||||
// MEGAMORPHIC: `ngComponentDef` is a megamorphic property access here.
|
|
||||||
// This is OK, since we will refactor this code and store the result in `TView.data`
|
let hostComponentDef: ComponentDef<any>|null = null;
|
||||||
// which means that we will be reading this value only once. We are trading clean/simple
|
let name = nameOrComponentType as string;
|
||||||
// template
|
if (isHostElement) {
|
||||||
// code for slight startup(first run) performance. (No impact on subsequent runs)
|
hostComponentDef = currentView.tView.firstTemplatePass ?
|
||||||
// TODO(misko): refactor this to store the `ComponentDef` in `TView.data`.
|
(nameOrComponentType as ComponentType<any>).ngComponentDef :
|
||||||
const hostComponentDef =
|
tData[index + 1] as ComponentDef<any>;
|
||||||
isHostElement ? (nameOrComponentType as ComponentType<any>).ngComponentDef : null;
|
name = hostComponentDef !.tag;
|
||||||
const name = isHostElement ? hostComponentDef !.tag : nameOrComponentType as string;
|
}
|
||||||
|
|
||||||
if (name === null) {
|
if (name === null) {
|
||||||
// TODO: future support for nameless components.
|
// TODO: future support for nameless components.
|
||||||
throw 'for now name is required';
|
throw 'for now name is required';
|
||||||
|
@ -541,16 +542,12 @@ function hack_declareDirectives(
|
||||||
// TODO(mhevery): This assumes that the directives come in correct order, which
|
// TODO(mhevery): This assumes that the directives come in correct order, which
|
||||||
// is not guaranteed. Must be refactored to take it into account.
|
// is not guaranteed. Must be refactored to take it into account.
|
||||||
for (let i = 0; i < directiveTypes.length; i++) {
|
for (let i = 0; i < directiveTypes.length; i++) {
|
||||||
// MEGAMORPHIC: `ngDirectiveDef` is a megamorphic property access here.
|
index++;
|
||||||
// This is OK, since we will refactor this code and store the result in `TView.data`
|
|
||||||
// which means that we will be reading this value only once. We are trading clean/simple
|
|
||||||
// template
|
|
||||||
// code for slight startup(first run) performance. (No impact on subsequent runs)
|
|
||||||
// TODO(misko): refactor this to store the `DirectiveDef` in `TView.data`.
|
|
||||||
const directiveType = directiveTypes[i];
|
const directiveType = directiveTypes[i];
|
||||||
const directiveDef = directiveType.ngDirectiveDef;
|
const directiveDef = currentView.tView.firstTemplatePass ? directiveType.ngDirectiveDef :
|
||||||
|
tData[index] as DirectiveDef<any>;
|
||||||
directiveCreate(
|
directiveCreate(
|
||||||
++index, directiveDef.n(), directiveDef, hack_findQueryName(directiveDef, localRefs));
|
index, directiveDef.n(), directiveDef, hack_findQueryName(directiveDef, localRefs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue