Skip to content

Commit 7455b90

Browse files
committed
Revert "feat(dart): Add a dev-mode check for undeclared lifecycle interfaces"
This reverts commit a3d7629. Needs co-ordination with google3 changes.
1 parent 579b890 commit 7455b90

2 files changed

Lines changed: 3 additions & 130 deletions

File tree

modules/angular2/src/core/reflection/reflection_capabilities.dart

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
library reflection.reflection_capabilities;
22

3-
import 'dart:mirrors';
4-
5-
import 'package:angular2/src/core/linker/interfaces.dart';
63
import 'package:angular2/src/facade/lang.dart';
7-
8-
import 'platform_reflection_capabilities.dart';
94
import 'types.dart';
5+
import 'dart:mirrors';
6+
import 'platform_reflection_capabilities.dart';
107

118
var DOT_REGEX = new RegExp('\\.');
129

@@ -275,9 +272,7 @@ class ReflectionCapabilities implements PlatformReflectionCapabilities {
275272
}
276273

277274
List interfaces(type) {
278-
final clazz = reflectType(type);
279-
_assertDeclaresLifecycleHooks(clazz);
280-
return _interfacesFromMirror(clazz);
275+
return _interfacesFromMirror(reflectType(type));
281276
}
282277

283278
List _interfacesFromMirror(classMirror) {
@@ -329,103 +324,3 @@ class ReflectionCapabilities implements PlatformReflectionCapabilities {
329324
return '${(reflectClass(type).owner as LibraryMirror).uri}';
330325
}
331326
}
332-
333-
final _lifecycleHookMirrors = <ClassMirror>[
334-
reflectType(AfterContentChecked),
335-
reflectType(AfterContentInit),
336-
reflectType(AfterViewChecked),
337-
reflectType(AfterViewInit),
338-
reflectType(DoCheck),
339-
reflectType(OnChanges),
340-
reflectType(OnDestroy),
341-
reflectType(OnInit),
342-
];
343-
344-
/// Checks whether [clazz] implements lifecycle ifaces without declaring them.
345-
///
346-
/// Due to Dart implementation details, lifecycle hooks are only called when a
347-
/// class explicitly declares that it implements the associated interface.
348-
/// See https://goo.gl/b07Kii for details.
349-
void _assertDeclaresLifecycleHooks(ClassMirror clazz) {
350-
final missingDeclarations = <ClassMirror>[];
351-
for (var iface in _lifecycleHookMirrors) {
352-
if (!_checkDeclares(clazz, iface: iface) &&
353-
_checkImplements(clazz, iface: iface)) {
354-
missingDeclarations.add(iface);
355-
}
356-
}
357-
if (missingDeclarations.isNotEmpty) {
358-
throw new MissingInterfaceError(clazz, missingDeclarations);
359-
}
360-
}
361-
362-
/// Returns whether [clazz] declares that it implements [iface].
363-
///
364-
/// Returns `false` if [clazz] implements [iface] but does not declare it.
365-
/// Returns `false` if [clazz]'s superclass declares that it
366-
/// implements [iface].
367-
bool _checkDeclares(ClassMirror clazz, {ClassMirror iface: null}) {
368-
if (iface == null) {
369-
throw new ArgumentError.notNull('iface');
370-
}
371-
return clazz.superinterfaces.contains(iface);
372-
}
373-
374-
/// Returns whether [clazz] implements [iface].
375-
///
376-
/// Returns `true` if [clazz] implements [iface] and does not declare it.
377-
/// Returns `true` if [clazz]'s superclass implements [iface].
378-
///
379-
/// This is an approximation of a JavaScript feature check:
380-
/// ```js
381-
/// var matches = true;
382-
/// for (var prop in iface) {
383-
/// if (iface.hasOwnProperty(prop)) {
384-
/// matches = matches && clazz.hasOwnProperty(prop);
385-
/// }
386-
/// }
387-
/// return matches;
388-
/// ```
389-
bool _checkImplements(ClassMirror clazz, {ClassMirror iface: null}) {
390-
if (iface == null) {
391-
throw new ArgumentError.notNull('iface');
392-
}
393-
394-
var matches = true;
395-
iface.declarations.forEach((symbol, declarationMirror) {
396-
if (!matches) return;
397-
if (declarationMirror.isConstructor || declarationMirror.isPrivate) return;
398-
matches = clazz.declarations.keys.contains(symbol);
399-
});
400-
if (!matches && clazz.superclass != null) {
401-
matches = _checkImplements(clazz.superclass, iface: iface);
402-
}
403-
if (!matches && clazz.mixin != clazz) {
404-
matches = _checkImplements(clazz.mixin, iface: iface);
405-
}
406-
407-
return matches;
408-
}
409-
410-
/// Error thrown when a class implements a lifecycle iface it does not declare.
411-
class MissingInterfaceError extends Error {
412-
final ClassMirror clazz;
413-
final List<ClassMirror> missingDeclarations;
414-
415-
MissingInterfaceError(this.clazz, this.missingDeclarations);
416-
417-
@override
418-
String toString() {
419-
final buf = new StringBuffer();
420-
buf.write('${clazz.simpleName} implements ');
421-
if (missingDeclarations.length == 1) {
422-
buf.write('an interface but does not declare it: ');
423-
} else {
424-
buf.write('interfaces but does not declare them: ');
425-
}
426-
buf.write(
427-
missingDeclarations.map((d) => d.simpleName.toString()).join(', '));
428-
buf.write('. See https://goo.gl/b07Kii for more info.');
429-
return buf.toString();
430-
}
431-
}

modules/angular2/test/core/reflection/reflector_spec.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
beforeEach,
88
browserDetection
99
} from 'angular2/testing_internal';
10-
import {OnInit} from 'angular2/core';
1110
import {Reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
1211
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
1312
import {
@@ -66,19 +65,6 @@ class SuperClassImplementingInterface implements Interface2 {}
6665

6766
class ClassImplementingInterface extends SuperClassImplementingInterface implements Interface {}
6867

69-
// Classes used to test our runtime check for classes that implement lifecycle interfaces but do not
70-
// declare them.
71-
// See https://github.com/angular/angular/pull/6879 and https://goo.gl/b07Kii for details.
72-
class ClassDoesNotDeclareOnInit {
73-
ngOnInit() {}
74-
}
75-
76-
class SuperClassImplementingOnInit implements OnInit {
77-
ngOnInit() {}
78-
}
79-
80-
class SubClassDoesNotDeclareOnInit extends SuperClassImplementingOnInit {}
81-
8268
export function main() {
8369
describe('Reflector', () => {
8470
var reflector;
@@ -228,14 +214,6 @@ export function main() {
228214
var p = reflector.interfaces(ClassWithDecorators);
229215
expect(p).toEqual([]);
230216
});
231-
232-
it("should throw for undeclared lifecycle interfaces",
233-
() => { expect(() => reflector.interfaces(ClassDoesNotDeclareOnInit)).toThrowError(); });
234-
235-
it("should throw for class inheriting a lifecycle impl and not declaring the interface",
236-
() => {
237-
expect(() => reflector.interfaces(SubClassDoesNotDeclareOnInit)).toThrowError();
238-
});
239217
});
240218
}
241219

0 commit comments

Comments
 (0)