|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import {Reflector} from '@angular/core/src/reflection/reflection';
|
10 |
| -import {DELEGATE_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; |
| 10 | +import {DELEGATE_CTOR, INHERITED_CLASS, INHERITED_CLASS_WITH_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; |
11 | 11 | import {global} from '@angular/core/src/util';
|
12 | 12 | import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
|
13 | 13 |
|
@@ -188,6 +188,41 @@ class TestObj {
|
188 | 188 | Object.defineProperty(dummyArrowFn, 'prototype', {value: undefined});
|
189 | 189 | expect(() => reflector.annotations(dummyArrowFn as any)).not.toThrow();
|
190 | 190 | });
|
| 191 | + |
| 192 | + it('should support native class', () => { |
| 193 | + const ChildNoCtor = `class ChildNoCtor extends Parent {}\n`; |
| 194 | + const ChildWithCtor = `class ChildWithCtor extends Parent {\n` + |
| 195 | + ` constructor() { super(); }` + |
| 196 | + `}\n`; |
| 197 | + const ChildNoCtorPrivateProps = `class ChildNoCtorPrivateProps extends Parent {\n` + |
| 198 | + ` private x = 10;\n` + |
| 199 | + `}\n`; |
| 200 | + |
| 201 | + const checkNoOwnMetadata = (str: string) => |
| 202 | + INHERITED_CLASS.exec(str) && !INHERITED_CLASS_WITH_CTOR.exec(str); |
| 203 | + |
| 204 | + expect(checkNoOwnMetadata(ChildNoCtor)).toBeTruthy(); |
| 205 | + expect(checkNoOwnMetadata(ChildNoCtorPrivateProps)).toBeTruthy(); |
| 206 | + expect(checkNoOwnMetadata(ChildWithCtor)).toBeFalsy(); |
| 207 | + }); |
| 208 | + |
| 209 | + it('should properly handle all class forms', () => { |
| 210 | + const ctor = (str: string) => expect(INHERITED_CLASS.exec(str)).toBeTruthy() && |
| 211 | + expect(INHERITED_CLASS_WITH_CTOR.exec(str)).toBeTruthy(); |
| 212 | + const noCtor = (str: string) => expect(INHERITED_CLASS.exec(str)).toBeTruthy() && |
| 213 | + expect(INHERITED_CLASS_WITH_CTOR.exec(str)).toBeFalsy(); |
| 214 | + |
| 215 | + ctor(`class Bar extends Foo {constructor(){}}`); |
| 216 | + ctor(`class Bar extends Foo { constructor ( ) {} }`); |
| 217 | + ctor(`class Bar extends Foo { other(){}; constructor(){} }`); |
| 218 | + |
| 219 | + noCtor(`class extends Foo{}`); |
| 220 | + noCtor(`class extends Foo {}`); |
| 221 | + noCtor(`class Bar extends Foo {}`); |
| 222 | + noCtor(`class $Bar1_ extends $Fo0_ {}`); |
| 223 | + noCtor(`class Bar extends Foo { other(){} }`); |
| 224 | + }); |
| 225 | + |
191 | 226 | });
|
192 | 227 |
|
193 | 228 | describe('inheritance with decorators', () => {
|
|
0 commit comments