Skip to content
Permalink
Browse files

fix(ivy): inheritance in JIT mode not working correctly on IE10 (#34305)

Fixes the metadata and lifecycle hook inheritance not working properly in IE10, because we weren't accessing things correctly.

PR Close #34305
  • Loading branch information
crisbeto authored and kara committed Dec 11, 2019
1 parent 08ce026 commit 65fb2fd765bcecb29f3d232d204ee107c8229ce1
Showing with 8 additions and 10 deletions.
  1. +8 −10 packages/core/src/render3/jit/directive.ts
@@ -189,7 +189,8 @@ export function extendsDirectlyFromObject(type: Type<any>): boolean {
*/
export function directiveMetadata(type: Type<any>, metadata: Directive): R3DirectiveMetadataFacade {
// Reflect inputs and outputs.
const propMetadata = getReflect().ownPropMetadata(type);
const reflect = getReflect();
const propMetadata = reflect.ownPropMetadata(type);

return {
name: type.name,
@@ -202,7 +203,7 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
inputs: metadata.inputs || EMPTY_ARRAY,
outputs: metadata.outputs || EMPTY_ARRAY,
queries: extractQueriesMetadata(type, propMetadata, isContentQuery),
lifecycle: {usesOnChanges: usesLifecycleHook(type, 'ngOnChanges')},
lifecycle: {usesOnChanges: reflect.hasLifecycleHook(type, 'ngOnChanges')},
typeSourceSpan: null !,
usesInheritance: !extendsDirectlyFromObject(type),
exportAs: extractExportAs(metadata.exportAs),
@@ -216,7 +217,7 @@ export function directiveMetadata(type: Type<any>, metadata: Directive): R3Direc
*/
function addDirectiveDefToUndecoratedParents(type: Type<any>) {
const objPrototype = Object.prototype;
let parent = Object.getPrototypeOf(type);
let parent = Object.getPrototypeOf(type.prototype).constructor;

// Go up the prototype until we hit `Object`.
while (parent && parent !== objPrototype) {
@@ -291,22 +292,19 @@ function splitByComma(value: string): string[] {
return value.split(',').map(piece => piece.trim());
}

function usesLifecycleHook(type: Type<any>, name: string): boolean {
const prototype = type.prototype;
return prototype && prototype.hasOwnProperty(name);
}

const LIFECYCLE_HOOKS = [
'ngOnChanges', 'ngOnInit', 'ngOnDestroy', 'ngDoCheck', 'ngAfterViewInit', 'ngAfterViewChecked',
'ngAfterContentInit', 'ngAfterContentChecked'
];

function shouldAddAbstractDirective(type: Type<any>): boolean {
if (LIFECYCLE_HOOKS.some(hookName => usesLifecycleHook(type, hookName))) {
const reflect = getReflect();

if (LIFECYCLE_HOOKS.some(hookName => reflect.hasLifecycleHook(type, hookName))) {
return true;
}

const propMetadata = getReflect().ownPropMetadata(type);
const propMetadata = reflect.propMetadata(type);

for (const field in propMetadata) {
const annotations = propMetadata[field];

0 comments on commit 65fb2fd

Please sign in to comment.
You can’t perform that action at this time.