1
1
/**
2
- * @license r.js 2.1.1+ Sat, 17 Nov 2012 23:32:03 GMT Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
2
+ * @license r.js 2.1.1+ Sun, 18 Nov 2012 19:55:34 GMT Copyright (c) 2010-2012, 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
*/
@@ -21,7 +21,7 @@ var requirejs, require, define;
21
21
22
22
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
23
23
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode,
24
- version = '2.1.1+ Sat, 17 Nov 2012 23:32:03 GMT',
24
+ version = '2.1.1+ Sun, 18 Nov 2012 19:55:34 GMT',
25
25
jsSuffixRegExp = /\.js$/,
26
26
commandOption = '',
27
27
useLibLoaded = {},
@@ -13523,7 +13523,7 @@ if(env === 'rhino') {
13523
13523
/*jslint strict: false, plusplus: false */
13524
13524
/*global define: false, java: false, Packages: false */
13525
13525
13526
- define('rhino/optimize', ['logger'], function (logger) {
13526
+ define('rhino/optimize', ['logger', 'env!env/file' ], function (logger, file ) {
13527
13527
13528
13528
//Add .reduce to Rhino so UglifyJS can run in Rhino,
13529
13529
//inspired by https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
@@ -13579,10 +13579,12 @@ define('rhino/optimize', ['logger'], function (logger) {
13579
13579
jsSourceFile = closurefromCode(String(fileName), String(fileContents)),
13580
13580
options, option, FLAG_compilation_level, compiler,
13581
13581
Compiler = Packages.com.google.javascript.jscomp.Compiler,
13582
- result;
13582
+ result, mappings, baseName ;
13583
13583
13584
13584
logger.trace("Minifying file: " + fileName);
13585
13585
13586
+ baseName = (new java.io.File(fileName)).getName();
13587
+
13586
13588
//Set up options
13587
13589
options = new jscomp.CompilerOptions();
13588
13590
for (option in config.CompilerOptions) {
@@ -13597,15 +13599,25 @@ define('rhino/optimize', ['logger'], function (logger) {
13597
13599
FLAG_compilation_level = jscomp.CompilationLevel[config.CompilationLevel || 'SIMPLE_OPTIMIZATIONS'];
13598
13600
FLAG_compilation_level.setOptionsForCompilationLevel(options);
13599
13601
13602
+ if (config.generateSourceMaps) {
13603
+ mappings = new java.util.ArrayList();
13604
+
13605
+ mappings.add(new com.google.javascript.jscomp.SourceMap.LocationMapping(fileName, baseName + ".src"));
13606
+ options.setSourceMapLocationMappings(mappings);
13607
+ options.setSourceMapOutputPath(fileName + ".map");
13608
+ }
13609
+
13600
13610
//Trigger the compiler
13601
13611
Compiler.setLoggingLevel(Packages.java.util.logging.Level[config.loggingLevel || 'WARNING']);
13602
13612
compiler = new Compiler();
13603
13613
13604
13614
result = compiler.compile(externSourceFile, jsSourceFile, options);
13605
- if (!result.success) {
13606
- logger.error('Cannot closure compile file: ' + fileName + '. Skipping it.');
13615
+ if (result.success) {
13616
+ fileContents = String(compiler.toSource());
13617
+
13618
+ return config.generateSourceMaps ? {sourceMap: result.sourceMap, toSource: function() { return fileContents; }} : fileContents;
13607
13619
} else {
13608
- fileContents = compiler.toSource( );
13620
+ logger.error('Cannot closure compile file: ' + fileName + '. Skipping it.' );
13609
13621
}
13610
13622
13611
13623
return fileContents;
@@ -13778,6 +13790,25 @@ function (lang, logger, envOptimize, file, parse,
13778
13790
};
13779
13791
}
13780
13792
13793
+ function getFileWriter(fileName, encoding) {
13794
+ var outFile = new java.io.File(fileName), outWriter, parentDir;
13795
+
13796
+ parentDir = outFile.getAbsoluteFile().getParentFile();
13797
+ if (!parentDir.exists()) {
13798
+ if (!parentDir.mkdirs()) {
13799
+ throw "Could not create directory: " + parentDir.getAbsolutePath();
13800
+ }
13801
+ }
13802
+
13803
+ if (encoding) {
13804
+ outWriter = new java.io.OutputStreamWriter(new java.io.FileOutputStream(outFile), encoding);
13805
+ } else {
13806
+ outWriter = new java.io.OutputStreamWriter(new java.io.FileOutputStream(outFile));
13807
+ }
13808
+
13809
+ return new java.io.BufferedWriter(outWriter);
13810
+ }
13811
+
13781
13812
optimize = {
13782
13813
/**
13783
13814
* Optimizes a file that contains JavaScript content. Optionally collects
@@ -13794,13 +13825,29 @@ function (lang, logger, envOptimize, file, parse,
13794
13825
* found.
13795
13826
*/
13796
13827
jsFile: function (fileName, fileContents, outFileName, config, pluginCollector) {
13828
+ var optimized, compressed, baseName, writer;
13829
+
13797
13830
if (!fileContents) {
13798
13831
fileContents = file.readFile(fileName);
13799
13832
}
13800
13833
13801
- fileContents = optimize.js(fileName, fileContents, config, pluginCollector);
13834
+ optimized = optimize.js(fileName, fileContents, config, pluginCollector);
13802
13835
13803
- file.saveUtf8File(outFileName, fileContents);
13836
+ compressed = typeof optimized =='string' ? optimized : optimized.toSource();
13837
+
13838
+ if (config.generateSourceMaps && optimized.sourceMap) {
13839
+ baseName = (new java.io.File(outFileName)).getName();
13840
+
13841
+ file.saveUtf8File(outFileName + ".src", fileContents);
13842
+
13843
+ writer = getFileWriter(outFileName + ".map", "utf-8");
13844
+ optimized.sourceMap.appendTo(writer, outFileName);
13845
+ writer.close();
13846
+
13847
+ compressed += "\n//@ sourceMappingURL=" + baseName + ".map";
13848
+ }
13849
+
13850
+ file.saveUtf8File(outFileName, compressed);
13804
13851
},
13805
13852
13806
13853
/**
@@ -13820,7 +13867,7 @@ function (lang, logger, envOptimize, file, parse,
13820
13867
optimizerName = parts[0],
13821
13868
keepLines = parts[1] === 'keepLines',
13822
13869
licenseContents = '',
13823
- optFunc;
13870
+ optFunc, optResult ;
13824
13871
13825
13872
config = config || {};
13826
13873
@@ -13845,8 +13892,13 @@ function (lang, logger, envOptimize, file, parse,
13845
13892
}
13846
13893
}
13847
13894
13848
- fileContents = licenseContents + optFunc(fileName, fileContents, keepLines,
13849
- config[optimizerName]);
13895
+ config[optimizerName] = config[optimizerName] || {};
13896
+
13897
+ config[optimizerName].generateSourceMaps = !!config.generateSourceMaps;
13898
+
13899
+ optResult = optFunc(fileName, fileContents, keepLines, config[optimizerName]);
13900
+
13901
+ return config.generateSourceMaps ? optResult : licenseContents + (typeof optResult == 'string' ? optResult : optResult.toSource());
13850
13902
}
13851
13903
13852
13904
return fileContents;
@@ -15584,6 +15636,23 @@ define('build', function (require) {
15584
15636
' to insert in to a require([]) call.');
15585
15637
}
15586
15638
15639
+ if (config.generateSourceMaps) {
15640
+ if (config.preserveLicenseComments) {
15641
+ throw new Error('Cannot use preserveLicenseComments and ' +
15642
+ 'generateSourceMaps together. Either explcitly set ' +
15643
+ 'preserveLicenseComments to false (default is true) or ' +
15644
+ 'turn off generateSourceMaps. If you want source maps with ' +
15645
+ 'license comments, see: ' +
15646
+ 'http://requirejs.org/docs/errors.html#sourcemapcomments');
15647
+ } else if (config.optimize !== 'none' && config.optimize !== 'closure') {
15648
+ //Allow optimize: none to pass, since it is useful when toggling
15649
+ //minification on and off to debug something, and it implicitly
15650
+ //works, since it does not need a source map.
15651
+ throw new Error('optimize: "' + config.optimize +
15652
+ '" does not support generateSourceMaps.');
15653
+ }
15654
+ }
15655
+
15587
15656
if ((config.name || config.include) && !config.modules) {
15588
15657
//Just need to build one file, but may be part of a whole appDir/
15589
15658
//baseUrl copy, but specified on the command line, so cannot do
0 commit comments