Skip to content

Commit 9936e34

Browse files
committed
chore(build): Remove circular dependency in Angular 2 ES5 output.
Remove couple of circular dependency between modules in Angular 2 ES5 output caused by exception_handler.ts and router_providers.ts. Fix the build/checkCircularDependency gulp task to call madge properly to detect the circular deps. Closes angular#7287
1 parent 7d44b82 commit 9936e34

7 files changed

Lines changed: 48 additions & 15 deletions

File tree

gulpfile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,8 @@ gulp.task('lint', ['build.tools'], function() {
344344
gulp.task('build/checkCircularDependencies', function(done) {
345345
var madge = require('madge');
346346

347-
var dependencyObject = madge(CONFIG.dest.js.dev.es5, {
347+
var dependencyObject = madge([CONFIG.dest.js.dev.es5], {
348348
format: 'cjs',
349-
paths: [CONFIG.dest.js.dev.es5],
350349
extensions: ['.js'],
351350
onParseFile: function(data) { data.src = data.src.replace(/\/\* circular \*\//g, "//"); }
352351
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
library angular.core.facade.base_wrapped_exception;
2+
3+
/**
4+
* A base class for the WrappedException that can be used to identify
5+
* a WrappedException from ExceptionHandler without adding circular
6+
* dependency.
7+
*/
8+
class BaseWrappedException extends Error {
9+
BaseWrappedException();
10+
11+
get originalException => null;
12+
get originalStack => null;
13+
14+
String get message => '';
15+
String get wrapperMessage => '';
16+
dynamic get context => null;
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* A base class for the WrappedException that can be used to identify
3+
* a WrappedException from ExceptionHandler without adding circular
4+
* dependency.
5+
*/
6+
export class BaseWrappedException extends Error {
7+
constructor(message: string) { super(message); }
8+
9+
get wrapperMessage(): string { return ''; }
10+
get wrapperStack(): any { return null; }
11+
get originalException(): any { return null; }
12+
get originalStack(): any { return null; }
13+
get context(): any { return null; }
14+
get message(): string { return ''; }
15+
}

modules/angular2/src/facade/exception_handler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isPresent, isBlank, print} from 'angular2/src/facade/lang';
2-
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
2+
import {BaseWrappedException} from 'angular2/src/facade/base_wrapped_exception';
33
import {ListWrapper, isListLikeIterable} from 'angular2/src/facade/collection';
44

55
class _ArrayLogger {
@@ -80,7 +80,8 @@ export class ExceptionHandler {
8080

8181
/** @internal */
8282
_extractMessage(exception: any): string {
83-
return exception instanceof WrappedException ? exception.wrapperMessage : exception.toString();
83+
return exception instanceof BaseWrappedException ? exception.wrapperMessage :
84+
exception.toString();
8485
}
8586

8687
/** @internal */
@@ -92,7 +93,7 @@ export class ExceptionHandler {
9293
/** @internal */
9394
_findContext(exception: any): any {
9495
try {
95-
if (!(exception instanceof WrappedException)) return null;
96+
if (!(exception instanceof BaseWrappedException)) return null;
9697
return isPresent(exception.context) ? exception.context :
9798
this._findContext(exception.originalException);
9899
} catch (e) {
@@ -103,10 +104,10 @@ export class ExceptionHandler {
103104

104105
/** @internal */
105106
_findOriginalException(exception: any): any {
106-
if (!(exception instanceof WrappedException)) return null;
107+
if (!(exception instanceof BaseWrappedException)) return null;
107108

108109
var e = exception.originalException;
109-
while (e instanceof WrappedException && isPresent(e.originalException)) {
110+
while (e instanceof BaseWrappedException && isPresent(e.originalException)) {
110111
e = e.originalException;
111112
}
112113

@@ -115,13 +116,13 @@ export class ExceptionHandler {
115116

116117
/** @internal */
117118
_findOriginalStack(exception: any): any {
118-
if (!(exception instanceof WrappedException)) return null;
119+
if (!(exception instanceof BaseWrappedException)) return null;
119120

120121
var e = exception;
121122
var stack = exception.originalStack;
122-
while (e instanceof WrappedException && isPresent(e.originalException)) {
123+
while (e instanceof BaseWrappedException && isPresent(e.originalException)) {
123124
e = e.originalException;
124-
if (e instanceof WrappedException && isPresent(e.originalException)) {
125+
if (e instanceof BaseWrappedException && isPresent(e.originalException)) {
125126
stack = e.originalStack;
126127
}
127128
}

modules/angular2/src/facade/exceptions.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library angular.core.facade.exceptions;
22

3+
import 'base_wrapped_exception.dart';
34
import 'exception_handler.dart';
45
export 'exception_handler.dart';
56

@@ -15,7 +16,7 @@ class BaseException extends Error {
1516
}
1617
}
1718

18-
class WrappedException extends Error {
19+
class WrappedException extends BaseWrappedException {
1920
final dynamic _context;
2021
final String _wrapperMessage;
2122
final originalException;
@@ -27,7 +28,7 @@ class WrappedException extends Error {
2728
this.originalStack,
2829
this._context]);
2930

30-
get message {
31+
String get message {
3132
return ExceptionHandler.exceptionToString(this);
3233
}
3334

modules/angular2/src/facade/exceptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {BaseWrappedException} from './base_wrapped_exception';
12
import {ExceptionHandler} from './exception_handler';
23

34
export {ExceptionHandler} from './exception_handler';
@@ -15,7 +16,7 @@ export class BaseException extends Error {
1516
/**
1617
* Wraps an exception and provides additional context or information.
1718
*/
18-
export class WrappedException extends Error {
19+
export class WrappedException extends BaseWrappedException {
1920
private _wrapperStack: any;
2021

2122
constructor(private _wrapperMessage: string, private _originalException, private _originalStack?,

modules/angular2/src/router/router_providers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
2-
import {ROUTER_PROVIDERS_COMMON} from 'angular2/router';
1+
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
32
import {Provider} from 'angular2/core';
43
import {CONST_EXPR} from 'angular2/src/facade/lang';
54
import {BrowserPlatformLocation} from './location/browser_platform_location';

0 commit comments

Comments
 (0)