Skip to content

Commit 21cdb5a

Browse files
vicbleo6104
authored andcommitted
Revert "feat(core): support metadata reflection for native class types (angular#22356)"
This reverts commit 5c89d6b.
1 parent 01cb44b commit 21cdb5a

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

packages/core/src/reflection/reflection_capabilities.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ import {GetterFn, MethodFn, SetterFn} from './types';
1515

1616

1717
/**
18-
* Attention: These regex has to hold even if the code is minified!
18+
* Attention: This regex has to hold even if the code is minified!
1919
*/
2020
export const DELEGATE_CTOR = /^function\s+\S+\(\)\s*{[\s\S]+\.apply\(this,\s*arguments\)/;
21-
export const INHERITED_CLASS = /^class\s+[A-Za-z\d$_]*\s*extends\s+[A-Za-z\d$_]+\s*{/;
22-
export const INHERITED_CLASS_WITH_CTOR =
23-
/^class\s+[A-Za-z\d$_]*\s*extends\s+[A-Za-z\d$_]+\s*{[\s\S]*constructor\s*\(/;
2421

2522
export class ReflectionCapabilities implements PlatformReflectionCapabilities {
2623
private _reflect: any;
@@ -60,16 +57,14 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
6057
}
6158

6259
private _ownParameters(type: Type<any>, parentCtor: any): any[][]|null {
63-
const typeStr = type.toString();
6460
// If we have no decorators, we only have function.length as metadata.
6561
// In that case, to detect whether a child class declared an own constructor or not,
6662
// we need to look inside of that constructor to check whether it is
6763
// just calling the parent.
6864
// This also helps to work around for https://github.com/Microsoft/TypeScript/issues/12439
6965
// that sets 'design:paramtypes' to []
7066
// if a class inherits from another class but has no ctor declared itself.
71-
if (DELEGATE_CTOR.exec(typeStr) ||
72-
(INHERITED_CLASS.exec(typeStr) && !INHERITED_CLASS_WITH_CTOR.exec(typeStr))) {
67+
if (DELEGATE_CTOR.exec(type.toString())) {
7368
return null;
7469
}
7570

packages/core/test/reflection/reflector_spec.ts

+1-36
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Reflector} from '@angular/core/src/reflection/reflection';
10-
import {DELEGATE_CTOR, INHERITED_CLASS, INHERITED_CLASS_WITH_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
10+
import {DELEGATE_CTOR, ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
1111
import {global} from '@angular/core/src/util';
1212
import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
1313

@@ -188,41 +188,6 @@ class TestObj {
188188
Object.defineProperty(dummyArrowFn, 'prototype', {value: undefined});
189189
expect(() => reflector.annotations(dummyArrowFn as any)).not.toThrow();
190190
});
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-
226191
});
227192

228193
describe('inheritance with decorators', () => {

0 commit comments

Comments
 (0)