Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d28ec11

Browse files
committed
chore(*): silence ng-closure-runner warnings during grunt minall
1 parent 9399d68 commit d28ec11

10 files changed

+53
-7
lines changed

src/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115

116116
/* minErr.js */
117117
"minErr": false,
118+
"noMinErr": false,
118119

119120
/* loader.js */
120121
"setupModuleLoader": false,

src/auto/injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ function createInjector(modulesToLoad, strictDi) {
824824
if (cache[serviceName] === INSTANTIATING) {
825825
delete cache[serviceName];
826826
}
827-
throw err;
827+
throw noMinErr('', '', err);
828828
} finally {
829829
path.shift();
830830
}

src/minErr.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* error from returned function, for cases when a particular type of error is useful.
3030
* @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
3131
*/
32-
3332
function minErr(module, ErrorConstructor) {
3433
ErrorConstructor = ErrorConstructor || Error;
3534
return function() {
@@ -63,3 +62,38 @@ function minErr(module, ErrorConstructor) {
6362
return new ErrorConstructor(message);
6463
};
6564
}
65+
66+
/**
67+
* @description
68+
*
69+
* In certain case (e.g. when catching and rethrowing an error), it is neither desirable nor
70+
* necessary to pass the error through `minErr()`. You can use this function to avoid warnings
71+
* produced by `ng-closire-runner` during `grunt minall`.
72+
*
73+
* Due to what arguments `ng-closure-runner` expects, the first two arguments must be static
74+
* strings. Therefore, you have to pass the actual error as 3rd argument (see example below).
75+
*
76+
* **WARNING**
77+
* Only use this function when you are certain that the thrown error should NOT be a `minErr`
78+
* instance;
79+
*
80+
* Example usage:
81+
*
82+
* ```js
83+
* try {
84+
* tryAndFail();
85+
* } catch (err) {
86+
* doSomeThing(err);
87+
* throw noMinErr('', '', err); // Functionally equivalent to `throw err`,
88+
* // but avoids `ng-closuer-runner` warnings.
89+
* }
90+
* ```
91+
*
92+
* @param {string} ignoredCode - Ignored, but necessary for `ng-closure-runner`.
93+
* @param {string} ignoredTemplate - Ignored, but necessary for `ng-closure-runner`.
94+
* @param {*} error - The error object that will be returned.
95+
* @returns {*} - The passed in error.
96+
*/
97+
function noMinErr(ignoredCode, ignoredTemplate, err) {
98+
return err;
99+
}

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15251525
// Reset the queue to trigger a new schedule next time there is a change
15261526
onChangesQueue = undefined;
15271527
if (errors.length) {
1528-
throw errors;
1528+
throw noMinErr('', '', errors);
15291529
}
15301530
});
15311531
} finally {

src/ng/directive/ngModelOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ModelOptions.prototype = {
4141
options = extend({}, options);
4242

4343
// Inherit options from the parent if specified by the value `"$inherit"`
44-
forEach(options, /* @this */ function(option, key) {
44+
forEach(options, /** @this */ function(option, key) {
4545
if (option === '$inherit') {
4646
if (key === '*') {
4747
inheritAll = true;

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
136136
// The json response type can be ignored if not supported, because JSON payloads are
137137
// parsed on the client-side regardless.
138138
if (responseType !== 'json') {
139-
throw e;
139+
throw noMinErr('', '', e);
140140
}
141141
}
142142
}

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ function $LocationProvider() {
871871
$location.url(oldUrl);
872872
$location.$$state = oldState;
873873

874-
throw e;
874+
throw noMinErr('', '', e);
875875
}
876876
}
877877

src/ng/rootScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ function $RootScopeProvider() {
10821082
} catch (e) {
10831083
$exceptionHandler(e);
10841084
// eslint-disable-next-line no-unsafe-finally
1085-
throw e;
1085+
throw noMinErr('', '', e);
10861086
}
10871087
}
10881088
},

test/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113

114114
/* minerr.js */
115115
"minErr": false,
116+
"noMinErr": false,
116117

117118
/* loader.js */
118119
"setupModuleLoader": false,

test/minErrSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ describe('minErr', function() {
105105
.toMatch(/^[\s\S]*\?p0=a&p1=b&p2=value%20with%20space$/);
106106
});
107107
});
108+
109+
describe('noMinErr', function() {
110+
it('should return the 3rd argument', function() {
111+
expect(noMinErr('foo', 'bar', 'baz')).toBe('baz');
112+
expect(noMinErr('foo', 'bar', null)).toBe(null);
113+
expect(noMinErr('foo', 'bar')).toBeUndefined();
114+
expect(noMinErr('foo')).toBeUndefined();
115+
expect(noMinErr()).toBeUndefined();
116+
});
117+
});

0 commit comments

Comments
 (0)