|
1197 | 1197 | var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)=]+)\s*\)?(?:\s*=>)/;
|
1198 | 1198 | var FN_ARG_SPLIT = /,/;
|
1199 | 1199 | var FN_ARG = /(=.+)?(\s*)$/;
|
1200 |
| - var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; |
| 1200 | + |
| 1201 | + function stripComments(string) { |
| 1202 | + let stripped = ''; |
| 1203 | + let index = 0; |
| 1204 | + let endBlockComment = string.indexOf('*/'); |
| 1205 | + while (index < string.length) { |
| 1206 | + if (string[index] === '/' && string[index+1] === '/') { |
| 1207 | + // inline comment |
| 1208 | + let endIndex = string.indexOf('\n', index); |
| 1209 | + index = (endIndex === -1) ? string.length : endIndex; |
| 1210 | + } else if ((endBlockComment !== -1) && (string[index] === '/') && (string[index+1] === '*')) { |
| 1211 | + // block comment |
| 1212 | + let endIndex = string.indexOf('*/', index); |
| 1213 | + if (endIndex !== -1) { |
| 1214 | + index = endIndex + 2; |
| 1215 | + endBlockComment = string.indexOf('*/', index); |
| 1216 | + } else { |
| 1217 | + stripped += string[index]; |
| 1218 | + index++; |
| 1219 | + } |
| 1220 | + } else { |
| 1221 | + stripped += string[index]; |
| 1222 | + index++; |
| 1223 | + } |
| 1224 | + } |
| 1225 | + return stripped; |
| 1226 | + } |
1201 | 1227 |
|
1202 | 1228 | function parseParams(func) {
|
1203 |
| - const src = func.toString().replace(STRIP_COMMENTS, ''); |
| 1229 | + const src = stripComments(func.toString()); |
1204 | 1230 | let match = src.match(FN_ARGS);
|
1205 | 1231 | if (!match) {
|
1206 | 1232 | match = src.match(ARROW_FN_ARGS);
|
|
1957 | 1983 | * app.get('/cats', function(request, response) {
|
1958 | 1984 | * var User = request.models.User;
|
1959 | 1985 | * async.seq(
|
1960 |
| - * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data)) |
| 1986 | + * User.get.bind(User), // 'User.get' has signature (id, callback(err, data)) |
1961 | 1987 | * function(user, fn) {
|
1962 | 1988 | * user.getCats(fn); // 'getCats' has signature (callback(err, data))
|
1963 | 1989 | * }
|
|
3591 | 3617 | return memoized;
|
3592 | 3618 | }
|
3593 | 3619 |
|
| 3620 | + /* istanbul ignore file */ |
| 3621 | + |
3594 | 3622 | /**
|
3595 | 3623 | * Calls `callback` on a later loop around the event loop. In Node.js this just
|
3596 | 3624 | * calls `process.nextTick`. In the browser it will use `setImmediate` if
|
|
0 commit comments