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

Improvements for Closure Compiler compilation #1710

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
94718cb
Replace reserved word int with atoi. Helpful for compiling with Closu…
benmccann Dec 16, 2012
f7f259f
Fix bad array type annotations
benmccann Dec 16, 2012
a488062
Fix jsdocs that refer to non-existing parameters
benmccann Dec 16, 2012
6aa6458
Add back accidentally removed @ngdoc function
benmccann Dec 16, 2012
1b8a961
Use correct capitalization for {Object} type in jsdocs
benmccann Dec 16, 2012
9dea94d
Remove accidentally added blank line
benmccann Dec 16, 2012
943c667
Try fixing var_args in a way that Closure Compiler likes
benmccann Dec 16, 2012
f86dcc8
Reference JSON via wondow object
benmccann Dec 16, 2012
565ff1d
Fix illegal return type
benmccann Dec 16, 2012
ba9ec6a
Fix type warning
benmccann Dec 16, 2012
9aa7324
Coerce to boolean. Return type is not currently what is expected
benmccann Dec 16, 2012
6c6e4b4
Fix shared type warnings
benmccann Dec 16, 2012
6010698
Optional arguments must be at the end
benmccann Dec 16, 2012
5e1f0c7
Add missing @constructor annotations
benmccann Dec 16, 2012
e28d086
Typecast to avoid compiler warning
benmccann Dec 16, 2012
4fdf37a
Fix capitalization of string type
benmccann Dec 16, 2012
d12a03d
Fix references to Element type
benmccann Dec 16, 2012
b9c3797
Fix missing closing parentheses
benmccann Dec 16, 2012
3fc2442
Add missing jsdocs
benmccann Dec 16, 2012
63b3b98
Fix headersGetter types
benmccann Dec 16, 2012
8bc454c
Revert optional function syntax change
benmccann Dec 16, 2012
f3c1f31
Revert add missing parens
benmccann Dec 16, 2012
62fa301
Fix regression in padNumber
benmccann Dec 16, 2012
21da8ae
Add back in missing parens
benmccann Dec 16, 2012
d7e27dd
Add jsdocs specifying some jsLite args as optional
benmccann Dec 16, 2012
378e7d2
More jsdocs for function types
benmccann Dec 16, 2012
4f0b138
Fix startPoller jsdoc
benmccann Dec 16, 2012
a1b8a4c
Fix type declaration
benmccann Dec 16, 2012
550274e
Specify types for HashMap input
benmccann Dec 16, 2012
c10c8b4
Change type declaration for extend
benmccann Dec 16, 2012
5916155
Fix Object capitalization
benmccann Dec 16, 2012
ea336b4
Fix invalid type declaration
benmccann Dec 16, 2012
e730c51
jsdoc was on wrong expression
benmccann Dec 16, 2012
7baae21
Fix a couple of warnings related to possible undefined values
benmccann Dec 16, 2012
8f87116
Fix parameter type
benmccann Dec 16, 2012
07d0f76
Remove unnecessary @returns statement
benmccann Dec 16, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/personalLog/personalLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ app.controller('LogCtrl', ['$cookieStore', '$scope', function LogCtrl($cookieSto

/**
* Persistently removes a log from logs.
* @param {object} log The log to remove.
* @param {Object} log The log to remove.
*/
$scope.rmLog = function(log) {
for ( var i = 0; i < logs.length; i++) {
Expand Down
61 changes: 35 additions & 26 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function fromCharCode(code) {return String.fromCharCode(code);}

var Error = window.Error,
/** holds major version number for IE or NaN for real browsers */
msie = int((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]),
msie = atoi((/msie (\d+)/.exec(lowercase(navigator.userAgent)) || [])[1]),
jqLite, // delay binding since jQuery could be loaded after us.
jQuery, // delay binding
slice = [].slice,
Expand Down Expand Up @@ -86,10 +86,10 @@ var Error = window.Error,
expect(log).toEqual(['name: misko', 'gender:male']);
</pre>
*
* @param {Object|Array} obj Object to iterate over.
* @param {Object|Array|undefined} obj Object to iterate over.
* @param {Function} iterator Iterator function.
* @param {Object=} context Object to become context (`this`) for the iterator function.
* @returns {Object|Array} Reference to `obj`.
* @returns {Object|Array|undefined} Reference to `obj`.
*/
function forEach(obj, iterator, context) {
var key;
Expand Down Expand Up @@ -184,9 +184,9 @@ function nextUid() {
* to `dst`. You can specify multiple `src` objects.
*
* @param {Object} dst Destination object.
* @param {...Object} src Source object(s).
* @param {...Object} var_args Source object(s).
*/
function extend(dst) {
function extend(dst, var_args) {
forEach(arguments, function(obj){
if (obj !== dst) {
forEach(obj, function(value, key){
Expand All @@ -197,7 +197,7 @@ function extend(dst) {
return dst;
}

function int(str) {
function atoi(str) {
return parseInt(str, 10);
}

Expand Down Expand Up @@ -330,7 +330,7 @@ function isNumber(value){return typeof value == 'number';}
* @returns {boolean} True if `value` is a `Date`.
*/
function isDate(value){
return toString.apply(value) == '[object Date]';
return toString.apply(/** @type {Object} */ (value)) == '[object Date]';
}


Expand All @@ -346,7 +346,7 @@ function isDate(value){
* @returns {boolean} True if `value` is an `Array`.
*/
function isArray(value) {
return toString.apply(value) == '[object Array]';
return toString.apply(/** @type {Object} */ (value)) == '[object Array]';
}


Expand All @@ -372,7 +372,7 @@ function isFunction(value){return typeof value == 'function';}
* @returns {boolean} True if `obj` is a window obj.
*/
function isWindow(obj) {
return obj && obj.document && obj.location && obj.alert && obj.setInterval;
return Boolean(obj && obj.document && obj.location && obj.alert && obj.setInterval);
}


Expand Down Expand Up @@ -403,18 +403,18 @@ function trim(value) {
* @description
* Determines if a reference is a DOM element (or wrapped jQuery element).
*
* @param {*} value Reference to check.
* @param {*} node Reference to check.
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
*/
function isElement(node) {
return node &&
return Boolean(node &&
(node.nodeName // we are a direct element
|| (node.bind && node.find)); // we have a bind and find method part of jQuery API
|| (node.bind && node.find))); // we have a bind and find method part of jQuery API
}

/**
* @param str 'key1,key2,...'
* @returns {object} in the form of {key1:true, key2:true, ...}
* @returns {Object} in the form of {key1:true, key2:true, ...}
*/
function makeMap(str){
var obj = {}, items = str.split(","), i;
Expand Down Expand Up @@ -530,16 +530,16 @@ function isLeafNode (node) {
function copy(source, destination){
if (isWindow(source) || isScope(source)) throw Error("Can't copy Window or Scope");
if (!destination) {
destination = source;
if (source) {
if (isArray(source)) {
destination = copy(source, []);
return copy(source, []);
} else if (isDate(source)) {
destination = new Date(source.getTime());
return new Date(source.getTime());
} else if (isObject(source)) {
destination = copy(source, {});
return copy(source, {});
}
}
return source;
} else {
if (source === destination) throw Error("Can't copy equivalent objects or arrays");
if (isArray(source)) {
Expand Down Expand Up @@ -653,15 +653,15 @@ function sliceArgs(args, startIndex) {
*
* @description
* Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
* `fn`). You can supply optional `args` that are are prebound to the function. This feature is also
* `fn`). You can supply optional `var_args` that are are prebound to the function. This feature is also
* known as [function currying](http://en.wikipedia.org/wiki/Currying).
*
* @param {Object} self Context which `fn` should be evaluated in.
* @param {function()} fn Function to be bound.
* @param {...*} args Optional arguments to be prebound to the `fn` function call.
* @param {...*} var_args Optional arguments to be prebound to the `fn` function call.
* @returns {function()} Function that wraps the `fn` with all the specified bindings.
*/
function bind(self, fn) {
function bind(self, fn, var_args) {
var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
if (isFunction(fn) && !(fn instanceof RegExp)) {
return curryArgs.length
Expand Down Expand Up @@ -712,7 +712,7 @@ function toJsonReplacer(key, value) {
* @returns {string} Jsonified string representing `obj`.
*/
function toJson(obj, pretty) {
return JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null);
return window.JSON.stringify(obj, toJsonReplacer, pretty ? ' ' : null);
}


Expand All @@ -729,7 +729,7 @@ function toJson(obj, pretty) {
*/
function fromJson(json) {
return isString(json)
? JSON.parse(json)
? window.JSON.parse(json)
: json;
}

Expand Down Expand Up @@ -767,7 +767,8 @@ function startingTag(element) {
* @returns Object.<(string|boolean)>
*/
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
var obj = {};
var key_value, key;
forEach((keyValue || "").split('&'), function(keyValue){
if (keyValue) {
key_value = keyValue.split('=');
Expand Down Expand Up @@ -832,7 +833,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
* @name ng.directive:ngApp
*
* @element ANY
* @param {angular.Module} ngApp an optional application
* @param {angular.Module} bootstrap an optional application
* {@link angular.module module} name to load.
*
* @description
Expand Down Expand Up @@ -908,7 +909,7 @@ function angularInit(element, bootstrap) {
* See: {@link guide/bootstrap Bootstrap}
*
* @param {Element} element DOM element which is the root of angular application.
* @param {Array<String|Function>=} modules an array of module declarations. See: {@link angular.module modules}
* @param {Array.<String|Function>=} modules an array of module declarations. See: {@link angular.module modules}
* @returns {AUTO.$injector} Returns the newly created injector for this app.
*/
function bootstrap(element, modules) {
Expand Down Expand Up @@ -961,6 +962,9 @@ function bindJQuery() {

/**
* throw error of the argument is falsy.
* @param {*} arg
* @param {string=} name
* @param {string=} reason
*/
function assertArg(arg, name, reason) {
if (!arg) {
Expand All @@ -969,7 +973,12 @@ function assertArg(arg, name, reason) {
return arg;
}

function assertArgFn(arg, name, acceptArrayAnnotation) {
/**
* @param {*} arg
* @param {string} name
* @param {boolean=} acceptArrayAnnotation
*/
function assertArgFn(arg, name, acceptArrayAnnotation) {
if (acceptArrayAnnotation && isArray(arg)) {
arg = arg[arg.length - 1];
}
Expand Down
3 changes: 3 additions & 0 deletions src/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function hashKey(obj) {

/**
* HashMap which can use objects as keys
* @param {(Object|Array)=} array
* @constructor
*/
function HashMap(array){
forEach(array, this.put, this);
Expand Down Expand Up @@ -69,6 +71,7 @@ HashMap.prototype = {
/**
* A map where multiple values can be added to the same key such that they form a queue.
* @returns {HashQueueMap}
* @constructor
*/
function HashQueueMap() {}
HashQueueMap.prototype = {
Expand Down
12 changes: 7 additions & 5 deletions src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function annotate(fn) {
* Create a new instance of JS type. The method takes a constructor function invokes the new operator and supplies
* all of the arguments to the constructor function as specified by the constructor annotation.
*
* @param {function} Type Annotated constructor function.
* @param {function()} Type Annotated constructor function.
* @param {Object=} locals Optional object. If preset then any argument names are read from this object first, before
* the `$injector` is consulted.
* @returns {Object} new instance of `Type`.
Expand Down Expand Up @@ -583,12 +583,14 @@ function createInjector(modulesToLoad) {
}

function instantiate(Type, locals) {
var Constructor = function() {},
instance, returnedValue;
/**
* @constructor
*/
var Constructor = function() {};

Constructor.prototype = (isArray(Type) ? Type[Type.length - 1] : Type).prototype;
instance = new Constructor();
returnedValue = invoke(Type, instance, locals);
var instance = new Constructor();
var returnedValue = invoke(Type, instance, locals);

return isObject(returnedValue) ? returnedValue : instance;
}
Expand Down
35 changes: 29 additions & 6 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
* - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
* parent element is reached.
*
* @param {string|DOMElement} element HTML string or DOMElement to be wrapped into jQuery.
* @param {string|Element} element HTML string or Element to be wrapped into jQuery.
* @returns {Object} jQuery object.
*/

var jqCache = JQLite.cache = {},
jqName = JQLite.expando = 'ng-' + new Date().getTime(),
jqId = 1,
addEventListenerFn = (window.document.addEventListener
var jqCache = JQLite.cache = {};
var jqName = JQLite.expando = 'ng-' + new Date().getTime();
var jqId = 1;
var addEventListenerFn = (window.document.addEventListener
? function(element, type, fn) {element.addEventListener(type, fn, false);}
: function(element, type, fn) {element.attachEvent('on' + type, fn);}),
removeEventListenerFn = (window.document.removeEventListener
Expand Down Expand Up @@ -112,6 +112,10 @@ function camelCase(name) {
//
/////////////////////////////////////////////

/**
* @param {string} name
* @param {boolean=} dispatchThis
*/
function JQLitePatchJQueryRemove(name, dispatchThis) {
var originalJqFn = jQuery.fn[name];
originalJqFn = originalJqFn.$original || originalJqFn;
Expand Down Expand Up @@ -146,6 +150,10 @@ function JQLitePatchJQueryRemove(name, dispatchThis) {
}

/////////////////////////////////////////////

/**
* @constructor
*/
function JQLite(element) {
if (element instanceof JQLite) {
return element;
Expand Down Expand Up @@ -181,6 +189,11 @@ function JQLiteDealoc(element){
}
}

/**
* @param {Object} element
* @param {string=} type
* @param {function()=} fn
*/
function JQLiteUnbind(element, type, fn) {
var events = JQLiteExpandoStore(element, 'events'),
handle = JQLiteExpandoStore(element, 'handle');
Expand Down Expand Up @@ -216,6 +229,11 @@ function JQLiteRemoveData(element) {
}
}

/**
* @param {Object} element
* @param {string} key
* @param {*=} value
*/
function JQLiteExpandoStore(element, key, value) {
var expandoId = element[jqName],
expandoStore = jqCache[expandoId || -1];
Expand Down Expand Up @@ -299,6 +317,11 @@ function JQLiteController(element, name) {
return JQLiteInheritedData(element, '$' + (name || 'ngController' ) + 'Controller');
}

/**
* @param {Object} element
* @param {string} name
* @param {*=} value
*/
function JQLiteInheritedData(element, name, value) {
element = jqLite(element);

Expand Down Expand Up @@ -329,7 +352,7 @@ var JQLitePrototype = JQLite.prototype = {

this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
JQLite(window).bind('load', trigger); // fallback to window.onload for others
new JQLite(window).bind('load', trigger); // fallback to window.onload for others
},
toString: function() {
var value = [];
Expand Down
6 changes: 3 additions & 3 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function setupModuleLoader(window) {
* {@link angular.bootstrap} to simplify this process for you.
*
* @param {!string} name The name of the module to create or retrieve.
* @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
* @param {Array.<string>} requires If specified then new module is being created. If unspecified then the
* the module is being retrieved for further configuration.
* @param {Function} configFn Optional configuration function for the module. Same as
* {@link angular.Module#config Module#config()}.
Expand Down Expand Up @@ -212,7 +212,7 @@ function setupModuleLoader(window) {
* @ngdoc method
* @name angular.Module#run
* @methodOf angular.Module
* @param {Function} initializationFn Execute this function after injector creation.
* @param {Function} block Execute this function after injector creation.
* Useful for application initialization.
* @description
* Use this method to register work which should be performed when the injector is done
Expand All @@ -233,7 +233,7 @@ function setupModuleLoader(window) {
/**
* @param {string} provider
* @param {string} method
* @param {String=} insertMethod
* @param {string=} insertMethod
* @returns {angular.Module}
*/
function invokeLater(provider, method, insertMethod) {
Expand Down
Loading