bin/r.js in requirejs-rails-0.5.2 vs bin/r.js in requirejs-rails-0.5.3

- old
+ new

@@ -1,7 +1,7 @@ /** - * @license r.js 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. + * @license r.js 1.0.4 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/requirejs for details */ /* @@ -18,11 +18,11 @@ var requirejs, require, define; (function (console, args, readFileFunc) { var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire, nodeDefine, exists, reqMain, loadedOptimizedLib, - version = '1.0.3', + version = '1.0.4', jsSuffixRegExp = /\.js$/, commandOption = '', //Used by jslib/rhino/args.js rhinoArgs = args, readFile = typeof readFileFunc !== 'undefined' ? readFileFunc : null; @@ -99,11 +99,11 @@ fileName = process.argv[3]; } } /** vim: et:ts=4:sw=4:sts=4 - * @license RequireJS 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. + * @license RequireJS 1.0.4 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/requirejs for details */ /*jslint strict: false, plusplus: false, sub: true */ /*global window: false, navigator: false, document: false, importScripts: false, @@ -111,11 +111,11 @@ setTimeout: false, opera: false */ (function () { //Change this version number for each release. - var version = "1.0.3", + var version = "1.0.4", commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g, currDirRegExp = /^\.\//, jsSuffixRegExp = /\.js$/, ostring = Object.prototype.toString, @@ -423,11 +423,19 @@ normalizedName = normalize(name, parentName); url = urlMap[normalizedName]; if (!url) { //Calculate url for the module, if it has a name. - url = context.nameToUrl(normalizedName, null, parentModuleMap); + //Use name here since nameToUrl also calls normalize, + //and for relative names that are outside the baseUrl + //this causes havoc. Was thinking of just removing + //parentModuleMap to avoid extra normalization, but + //normalize() still does a dot removal because of + //issue #142, so just pass in name here and redo + //the normalization. Paths outside baseUrl are just + //messy to support. + url = context.nameToUrl(name, null, parentModuleMap); //Store the URL mapping for later. urlMap[normalizedName] = url; } } @@ -728,11 +736,11 @@ function getManager(map, shouldQueue) { var fullName = map.fullName, prefix = map.prefix, plugin = prefix ? plugins[prefix] || (plugins[prefix] = defined[prefix]) : null, - manager, created, pluginManager; + manager, created, pluginManager, prefixMap; if (fullName) { manager = managerCallbacks[fullName]; } @@ -766,11 +774,22 @@ } //If there is a plugin needed, but it is not loaded, //first load the plugin, then continue on. if (prefix && !plugin) { - pluginManager = getManager(makeModuleMap(prefix), true); + prefixMap = makeModuleMap(prefix); + + //Clear out defined and urlFetched if the plugin was previously + //loaded/defined, but not as full module (as in a build + //situation). However, only do this work if the plugin is in + //defined but does not have a module export value. + if (prefix in defined && !defined[prefix]) { + delete defined[prefix]; + delete urlFetched[prefixMap.url]; + } + + pluginManager = getManager(prefixMap, true); pluginManager.add(function (plugin) { //Create a new manager for the normalized //resource ID and have it call this manager when //done. var newMap = makeModuleMap(map.originalName, map.parentMap), @@ -1837,11 +1856,12 @@ //In the browser so use a script tag callback = callback || req.onScriptLoad; node = context && context.config && context.config.xhtml ? document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") : document.createElement("script"); - node.type = type || "text/javascript"; + node.type = type || (context && context.config.scriptType) || + "text/javascript"; node.charset = "utf-8"; //Use async so Gecko does not block on executing the script if something //like a long-polling comet tag is being run first. Gecko likes //to evaluate scripts in DOM order, even for dynamic scripts. //It will fetch them async, but only evaluate the contents in DOM @@ -7667,11 +7687,11 @@ config = config || {}; logger.trace("Uglifying file: " + fileName); try { - ast = parser.parse(fileContents, config); + ast = parser.parse(fileContents, config.strict_semicolons); ast = processor.ast_mangle(ast, config); ast = processor.ast_squeeze(ast, config); fileContents = processor.gen_code(ast, config); } catch (e) { @@ -7850,12 +7870,17 @@ //Find out if the file contains a require() definition. Need to know //this so we can inject plugins right after it, but before they are needed, //and to make sure this file is first, so that define calls work. //This situation mainly occurs when the build is done on top of the output //of another build, where the first build may include require somewhere in it. - if (!layer.existingRequireUrl && parse.definesRequire(url, contents)) { - layer.existingRequireUrl = url; + try { + if (!layer.existingRequireUrl && parse.definesRequire(url, contents)) { + layer.existingRequireUrl = url; + } + } catch (e1) { + throw new Error('Parse error using UglifyJS ' + + 'for file: ' + url + '\n' + e1); } if (moduleName in context.plugins) { //This is a loader plugin, check to see if it has a build extension, //otherwise the plugin will act as the plugin builder too. @@ -7868,16 +7893,21 @@ } //Parse out the require and define calls. //Do this even for plugins in case they have their own //dependencies that may be separate to how the pluginBuilder works. - if (!context.needFullExec[moduleName]) { - contents = parse(moduleName, url, contents, { - insertNeedsDefine: true, - has: context.config.has, - findNestedDependencies: context.config.findNestedDependencies - }); + try { + if (!context.needFullExec[moduleName]) { + contents = parse(moduleName, url, contents, { + insertNeedsDefine: true, + has: context.config.has, + findNestedDependencies: context.config.findNestedDependencies + }); + } + } catch (e2) { + throw new Error('Parse error using UglifyJS ' + + 'for file: ' + url + '\n' + e2); } require._cachedFileContents[url] = contents; } @@ -7937,12 +7967,12 @@ layer.pathAdded[fullName] = true; } } else if (map.url && require._isSupportedBuildUrl(map.url)) { //If the url has not been added to the layer yet, and it //is from an actual file that was loaded, add it now. + url = normalizeUrlWithBase(context, map.fullName, map.url); if (!layer.pathAdded[url] && layer.buildPathMap[fullName]) { - url = normalizeUrlWithBase(context, map.fullName, map.url); //Remember the list of dependencies for this layer. layer.buildFilePaths.push(url); layer.pathAdded[url] = true; } } @@ -8693,9 +8723,13 @@ } } if (!config.cssIn && !config.baseUrl) { throw new Error("ERROR: 'baseUrl' option missing."); + } + + if (!config.out && !config.dir) { + throw new Error('Missing either an "out" or "dir" config value.'); } if (config.out && !config.cssIn) { //Just one file to optimize.