fix(core): fix inheritance in JIT mode for TS 2.1 (#15599)

Fixes #15502
This commit is contained in:
Tobias Bosch 2017-03-29 16:14:51 -07:00 committed by Victor Berchet
parent a9321b1387
commit 14fd78fd85
2 changed files with 23 additions and 2 deletions

View File

@ -14,8 +14,7 @@ import {GetterFn, MethodFn, SetterFn} from './types';
/** /**
* Attention: This regex has to hold even if the code is minified! * Attention: This regex has to hold even if the code is minified!
*/ */
export const DELEGATE_CTOR = export const DELEGATE_CTOR = /^function\s+\S+\(\)\s*{[\s\S]+\.apply\(this,\s*arguments\)/;
/^function\s+\S+\(\)\s*{\s*("use strict";)?\s*(return\s+)?(\S+\s+!==\s+null\s+&&\s+)?\S+\.apply\(this,\s*arguments\)/;
export class ReflectionCapabilities implements PlatformReflectionCapabilities { export class ReflectionCapabilities implements PlatformReflectionCapabilities {
private _reflect: any; private _reflect: any;

View File

@ -8,6 +8,7 @@
import {Reflector} from '@angular/core/src/reflection/reflection'; import {Reflector} from '@angular/core/src/reflection/reflection';
import {DELEGATE_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; 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'; import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
interface ClassDecoratorFactory { interface ClassDecoratorFactory {
@ -171,8 +172,12 @@ export function main() {
class ChildWithCtor extends Parent { class ChildWithCtor extends Parent {
constructor() { super(); } constructor() { super(); }
} }
class ChildNoCtorPrivateProps extends Parent {
private x = 10;
}
expect(DELEGATE_CTOR.exec(ChildNoCtor.toString())).toBeTruthy(); expect(DELEGATE_CTOR.exec(ChildNoCtor.toString())).toBeTruthy();
expect(DELEGATE_CTOR.exec(ChildNoCtorPrivateProps.toString())).toBeTruthy();
expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy(); expect(DELEGATE_CTOR.exec(ChildWithCtor.toString())).toBeFalsy();
}); });
}); });
@ -222,6 +227,15 @@ export function main() {
class Child extends Parent {} 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, // Note: We need the class decorator as well,
// as otherwise TS won't capture the ctor arguments! // as otherwise TS won't capture the ctor arguments!
@ClassDecorator({value: 'child'}) @ClassDecorator({value: 'child'})
@ -244,6 +258,14 @@ export function main() {
[A, new ParamDecorator('a')], [B, new ParamDecorator('b')] [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')]]); expect(reflector.parameters(ChildWithCtor)).toEqual([[C, new ParamDecorator('c')]]);
// If we have no decorator, we don't get metadata about the ctor params. // If we have no decorator, we don't get metadata about the ctor params.