From 14fd78fd85b3dd230742eaaeab65f75226f37167 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 29 Mar 2017 16:14:51 -0700 Subject: [PATCH] fix(core): fix inheritance in JIT mode for TS 2.1 (#15599) Fixes #15502 --- .../src/reflection/reflection_capabilities.ts | 3 +-- .../core/test/reflection/reflector_spec.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/core/src/reflection/reflection_capabilities.ts b/packages/core/src/reflection/reflection_capabilities.ts index dc9be8dee3..b7aa346ebf 100644 --- a/packages/core/src/reflection/reflection_capabilities.ts +++ b/packages/core/src/reflection/reflection_capabilities.ts @@ -14,8 +14,7 @@ import {GetterFn, MethodFn, SetterFn} from './types'; /** * Attention: This regex has to hold even if the code is minified! */ -export const DELEGATE_CTOR = - /^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?(\S+\s+!==\s+null\s+&&\s+)?\S+\.apply\(this,\s*arguments\)/; +export const DELEGATE_CTOR = /^function\s+\S+\(\)\s*{[\s\S]+\.apply\(this,\s*arguments\)/; export class ReflectionCapabilities implements PlatformReflectionCapabilities { private _reflect: any; diff --git a/packages/core/test/reflection/reflector_spec.ts b/packages/core/test/reflection/reflector_spec.ts index 8571570896..9ec32d4e44 100644 --- a/packages/core/test/reflection/reflector_spec.ts +++ b/packages/core/test/reflection/reflector_spec.ts @@ -8,6 +8,7 @@ import {Reflector} from '@angular/core/src/reflection/reflection'; import {DELEGATE_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; +import {global} from '@angular/core/src/util'; import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators'; interface ClassDecoratorFactory { @@ -171,8 +172,12 @@ export function main() { class ChildWithCtor extends Parent { constructor() { super(); } } + class ChildNoCtorPrivateProps extends Parent { + private x = 10; + } expect(DELEGATE_CTOR.exec(ChildNoCtor.toString())).toBeTruthy(); + expect(DELEGATE_CTOR.exec(ChildNoCtorPrivateProps.toString())).toBeTruthy(); expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy(); }); }); @@ -222,6 +227,15 @@ export function main() { class Child extends Parent {} + @ClassDecorator({value: 'child'}) + class ChildWithDecorator extends Parent { + } + + @ClassDecorator({value: 'child'}) + class ChildWithDecoratorAndProps extends Parent { + private x = 10; + } + // Note: We need the class decorator as well, // as otherwise TS won't capture the ctor arguments! @ClassDecorator({value: 'child'}) @@ -244,6 +258,14 @@ export function main() { [A, new ParamDecorator('a')], [B, new ParamDecorator('b')] ]); + expect(reflector.parameters(ChildWithDecorator)).toEqual([ + [A, new ParamDecorator('a')], [B, new ParamDecorator('b')] + ]); + + expect(reflector.parameters(ChildWithDecoratorAndProps)).toEqual([ + [A, new ParamDecorator('a')], [B, new ParamDecorator('b')] + ]); + expect(reflector.parameters(ChildWithCtor)).toEqual([[C, new ParamDecorator('c')]]); // If we have no decorator, we don't get metadata about the ctor params.