1
1
/**
2
- * @license r.js 2.1.13+ Wed, 28 May 2014 22:10:41 GMT Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
2
+ * @license r.js 2.1.13+ Sun, 01 Jun 2014 23:04:13 GMT Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
3
3
* Available via the MIT or new BSD license.
4
4
* see: http://github.com/jrburke/requirejs for details
5
5
*/
@@ -20,7 +20,7 @@ var requirejs, require, define, xpcUtil;
20
20
(function (console, args, readFileFunc) {
21
21
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
22
22
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode, Cc, Ci,
23
- version = '2.1.13+ Wed, 28 May 2014 22:10:41 GMT',
23
+ version = '2.1.13+ Sun, 01 Jun 2014 23:04:13 GMT',
24
24
jsSuffixRegExp = /\.js$/,
25
25
commandOption = '',
26
26
useLibLoaded = {},
@@ -22763,7 +22763,11 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22763
22763
22764
22764
//This string is saved off because JSLint complains
22765
22765
//about obj.arguments use, as 'reserved word'
22766
- var argPropName = 'arguments';
22766
+ var argPropName = 'arguments',
22767
+ //Default object to use for "scope" checking for UMD identifiers.
22768
+ emptyScope = {},
22769
+ mixin = lang.mixin,
22770
+ hasProp = lang.hasProp;
22767
22771
22768
22772
//From an esprima example for traversing its ast.
22769
22773
function traverse(object, visitor) {
@@ -22865,7 +22869,7 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22865
22869
needsDefine = true,
22866
22870
astRoot = esprima.parse(fileContents);
22867
22871
22868
- parse.recurse(astRoot, function (callName, config, name, deps, node, factoryIdentifier) {
22872
+ parse.recurse(astRoot, function (callName, config, name, deps, node, factoryIdentifier, fnExpScope ) {
22869
22873
if (!deps) {
22870
22874
deps = [];
22871
22875
}
@@ -22885,7 +22889,7 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22885
22889
});
22886
22890
}
22887
22891
22888
- if (factoryIdentifier) {
22892
+ if (callName === 'define' && factoryIdentifier && hasProp(fnExpScope, factoryIdentifier) ) {
22889
22893
return factoryIdentifier;
22890
22894
}
22891
22895
@@ -22938,14 +22942,18 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22938
22942
* @param {Function} onMatch function to call on a parse match.
22939
22943
* @param {Object} [options] This is normally the build config options if
22940
22944
* it is passed.
22945
+ * @param {Object} [fnExpScope] holds list of function expresssion
22946
+ * argument identifiers, set up internally, not passed in
22941
22947
*/
22942
- parse.recurse = function (object, onMatch, options) {
22948
+ parse.recurse = function (object, onMatch, options, fnExpScope ) {
22943
22949
//Like traverse, but skips if branches that would not be processed
22944
22950
//after has application that results in tests of true or false boolean
22945
22951
//literal values.
22946
- var key, child, result,
22952
+ var key, child, result, i, params, param,
22947
22953
hasHas = options && options.has;
22948
22954
22955
+ fnExpScope = fnExpScope || emptyScope;
22956
+
22949
22957
if (!object) {
22950
22958
return;
22951
22959
}
@@ -22956,24 +22964,44 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22956
22964
object.test.type === 'Literal') {
22957
22965
if (object.test.value) {
22958
22966
//Take the if branch
22959
- this.recurse(object.consequent, onMatch, options);
22967
+ this.recurse(object.consequent, onMatch, options, fnExpScope );
22960
22968
} else {
22961
22969
//Take the else branch
22962
- this.recurse(object.alternate, onMatch, options);
22970
+ this.recurse(object.alternate, onMatch, options, fnExpScope );
22963
22971
}
22964
22972
} else {
22965
- result = this.parseNode(object, onMatch);
22973
+ result = this.parseNode(object, onMatch, fnExpScope );
22966
22974
if (result === false) {
22967
22975
return;
22968
22976
} else if (typeof result === 'string') {
22969
22977
return result;
22970
22978
}
22971
22979
22980
+ //Build up a "scope" object that informs nested recurse calls if
22981
+ //the define call references an identifier that is likely a UMD
22982
+ //wrapped function expresion argument.
22983
+ if (object.type === 'ExpressionStatement' && object.expression &&
22984
+ object.expression.type === 'CallExpression' && object.expression.callee &&
22985
+ object.expression.callee.type === 'FunctionExpression') {
22986
+ object = object.expression.callee;
22987
+
22988
+ if (object.params && object.params.length) {
22989
+ params = object.params;
22990
+ fnExpScope = mixin({}, fnExpScope, true);
22991
+ for (i = 0; i < params.length; i++) {
22992
+ param = params[i];
22993
+ if (param.type === 'Identifier') {
22994
+ fnExpScope[param.name] = true;
22995
+ }
22996
+ }
22997
+ }
22998
+ }
22999
+
22972
23000
for (key in object) {
22973
23001
if (object.hasOwnProperty(key)) {
22974
23002
child = object[key];
22975
23003
if (typeof child === 'object' && child !== null) {
22976
- result = this.recurse(child, onMatch, options);
23004
+ result = this.recurse(child, onMatch, options, fnExpScope );
22977
23005
if (typeof result === 'string') {
22978
23006
break;
22979
23007
}
@@ -22985,23 +23013,10 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
22985
23013
//passed in as a function expression, indicating a UMD-type of
22986
23014
//wrapping.
22987
23015
if (typeof result === 'string') {
22988
- if (object.type === 'ExpressionStatement' && object.expression &&
22989
- object.expression.type === 'CallExpression' && object.expression.callee &&
22990
- object.expression.callee.type === 'FunctionExpression') {
22991
- object = object.expression.callee;
22992
-
22993
- if (object.params && object.params.length) {
22994
- if (object.params.some(function(param) {
22995
- //Found an identifier match, so stop parsing from this
22996
- //level down.
22997
- return param.type === 'Identifier' &&
22998
- param.name === result;
22999
- })) {
23000
- //Just a plain return, parsing can continue past this
23001
- //point.
23002
- return;
23003
- }
23004
- }
23016
+ if (hasProp(fnExpScope, result)) {
23017
+ //Just a plain return, parsing can continue past this
23018
+ //point.
23019
+ return;
23005
23020
}
23006
23021
23007
23022
return result;
@@ -23479,11 +23494,14 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
23479
23494
* @param {Function} onMatch a function to call when a match is found.
23480
23495
* It is passed the match name, and the config, name, deps possible args.
23481
23496
* The config, name and deps args are not normalized.
23497
+ * @param {Object} fnExpScope an object whose keys are all function
23498
+ * expression identifiers that should be in scope. Useful for UMD wrapper
23499
+ * detection to avoid parsing more into the wrapped UMD code.
23482
23500
*
23483
23501
* @returns {String} a JS source string with the valid require/define call.
23484
23502
* Otherwise null.
23485
23503
*/
23486
- parse.parseNode = function (node, onMatch) {
23504
+ parse.parseNode = function (node, onMatch, fnExpScope ) {
23487
23505
var name, deps, cjsDeps, arg, factory, exp, refsDefine, bodyNode,
23488
23506
args = node && node[argPropName],
23489
23507
callName = parse.hasRequire(node);
@@ -23557,7 +23575,8 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
23557
23575
}
23558
23576
23559
23577
return onMatch("define", null, name, deps, node,
23560
- (factory && factory.type === 'Identifier' ? factory.name : undefined));
23578
+ (factory && factory.type === 'Identifier' ? factory.name : undefined),
23579
+ fnExpScope);
23561
23580
} else if (node.type === 'CallExpression' && node.callee &&
23562
23581
node.callee.type === 'FunctionExpression' &&
23563
23582
node.callee.body && node.callee.body.body &&
@@ -23585,7 +23604,7 @@ define('parse', ['./esprimaAdapter', 'lang'], function (esprima, lang) {
23585
23604
23586
23605
if (refsDefine) {
23587
23606
return onMatch("define", null, null, null, exp.expression,
23588
- exp.expression.arguments[0].name);
23607
+ exp.expression.arguments[0].name, fnExpScope );
23589
23608
}
23590
23609
}
23591
23610
}
0 commit comments