Skip to content

Commit ce78ebb

Browse files
committed
Merge pull request #64 from ChadKillingsworth/closure-compiler
Type annotations for closure-compiler advanced optimizations.
2 parents 08bf818 + 6fb6f30 commit ce78ebb

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

index.js

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ var PATH_REGEXP = new RegExp([
3030
/**
3131
* Parse a string for the raw tokens.
3232
*
33-
* @param {String} str
34-
* @return {Array}
33+
* @param {string} str
34+
* @return {!Array}
3535
*/
3636
function parse (str) {
3737
var tokens = []
@@ -97,8 +97,8 @@ function parse (str) {
9797
/**
9898
* Compile a string to a template function for the path.
9999
*
100-
* @param {String} str
101-
* @return {Function}
100+
* @param {string} str
101+
* @return {!function(Object=)}
102102
*/
103103
function compile (str) {
104104
return tokensToFunction(parse(str))
@@ -184,8 +184,8 @@ function tokensToFunction (tokens) {
184184
/**
185185
* Escape a regular expression string.
186186
*
187-
* @param {String} str
188-
* @return {String}
187+
* @param {string} str
188+
* @return {string}
189189
*/
190190
function escapeString (str) {
191191
return str.replace(/([.+*?=^!:${}()[\]|\/])/g, '\\$1')
@@ -194,8 +194,8 @@ function escapeString (str) {
194194
/**
195195
* Escape the capturing group by escaping special characters and meaning.
196196
*
197-
* @param {String} group
198-
* @return {String}
197+
* @param {string} group
198+
* @return {string}
199199
*/
200200
function escapeGroup (group) {
201201
return group.replace(/([=!:$\/()])/g, '\\$1')
@@ -204,9 +204,9 @@ function escapeGroup (group) {
204204
/**
205205
* Attach the keys as a property of the regexp.
206206
*
207-
* @param {RegExp} re
208-
* @param {Array} keys
209-
* @return {RegExp}
207+
* @param {!RegExp} re
208+
* @param {Array} keys
209+
* @return {!RegExp}
210210
*/
211211
function attachKeys (re, keys) {
212212
re.keys = keys
@@ -217,7 +217,7 @@ function attachKeys (re, keys) {
217217
* Get the flags for a regexp from the options.
218218
*
219219
* @param {Object} options
220-
* @return {String}
220+
* @return {string}
221221
*/
222222
function flags (options) {
223223
return options.sensitive ? '' : 'i'
@@ -226,9 +226,9 @@ function flags (options) {
226226
/**
227227
* Pull out keys from a regexp.
228228
*
229-
* @param {RegExp} path
230-
* @param {Array} keys
231-
* @return {RegExp}
229+
* @param {!RegExp} path
230+
* @param {!Array} keys
231+
* @return {!RegExp}
232232
*/
233233
function regexpToRegexp (path, keys) {
234234
// Use a negative lookahead to match only capturing groups.
@@ -253,10 +253,10 @@ function regexpToRegexp (path, keys) {
253253
/**
254254
* Transform an array into a regexp.
255255
*
256-
* @param {Array} path
257-
* @param {Array} keys
258-
* @param {Object} options
259-
* @return {RegExp}
256+
* @param {!Array} path
257+
* @param {Array} keys
258+
* @param {!Object} options
259+
* @return {!RegExp}
260260
*/
261261
function arrayToRegexp (path, keys, options) {
262262
var parts = []
@@ -273,10 +273,10 @@ function arrayToRegexp (path, keys, options) {
273273
/**
274274
* Create a path regexp from string input.
275275
*
276-
* @param {String} path
277-
* @param {Array} keys
278-
* @param {Object} options
279-
* @return {RegExp}
276+
* @param {string} path
277+
* @param {!Array} keys
278+
* @param {!Object} options
279+
* @return {!RegExp}
280280
*/
281281
function stringToRegexp (path, keys, options) {
282282
var tokens = parse(path)
@@ -295,10 +295,9 @@ function stringToRegexp (path, keys, options) {
295295
/**
296296
* Expose a function for taking tokens and returning a RegExp.
297297
*
298-
* @param {Array} tokens
299-
* @param {Array} keys
300-
* @param {Object} options
301-
* @return {RegExp}
298+
* @param {!Array} tokens
299+
* @param {Object=} options
300+
* @return {!RegExp}
302301
*/
303302
function tokensToRegExp (tokens, options) {
304303
options = options || {}
@@ -363,28 +362,28 @@ function tokensToRegExp (tokens, options) {
363362
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
364363
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
365364
*
366-
* @param {(String|RegExp|Array)} path
367-
* @param {Array} [keys]
368-
* @param {Object} [options]
369-
* @return {RegExp}
365+
* @param {(string|RegExp|Array)} path
366+
* @param {(Array|Object)=} keys
367+
* @param {Object=} options
368+
* @return {!RegExp}
370369
*/
371370
function pathToRegexp (path, keys, options) {
372371
keys = keys || []
373372

374373
if (!isarray(keys)) {
375-
options = keys
374+
options = /** @type {!Object} */ (keys)
376375
keys = []
377376
} else if (!options) {
378377
options = {}
379378
}
380379

381380
if (path instanceof RegExp) {
382-
return regexpToRegexp(path, keys, options)
381+
return regexpToRegexp(path, /** @type {!Array} */ (keys))
383382
}
384383

385384
if (isarray(path)) {
386-
return arrayToRegexp(path, keys, options)
385+
return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
387386
}
388387

389-
return stringToRegexp(path, keys, options)
388+
return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
390389
}

0 commit comments

Comments
 (0)