Skip to content

Commit 39c6fea

Browse files
committed
break out js optimization of a string to a separate function.
1 parent c319938 commit 39c6fea

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

build/jslib/optimize.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* see: http://github.com/jrburke/requirejs for details
55
*/
66

7-
/*jslint plusplus: false, nomen: false, regexp: false, strict: false */
7+
/*jslint plusplus: false, nomen: false, regexp: false */
88
/*global define: false */
99

1010
define([ 'lang', 'logger', 'env!env/optimize', 'env!env/file', 'parse',
@@ -148,11 +148,37 @@ function (lang, logger, envOptimize, file, parse,
148148
var parts = (config.optimize + "").split('.'),
149149
optimizerName = parts[0],
150150
keepLines = parts[1] === 'keepLines',
151-
licenseContents = '',
152-
fileContents, optFunc, match, comment;
151+
fileContents;
153152

154153
fileContents = file.readFile(fileName);
155154

155+
fileContents = optimize.js(fileName, fileContents, optimizerName,
156+
keepLines, config, pluginCollector);
157+
158+
file.saveUtf8File(outFileName, fileContents);
159+
},
160+
161+
/**
162+
* Optimizes a file that contains JavaScript content. Optionally collects
163+
* plugin resources mentioned in a file, and then passes the content
164+
* through an minifier if one is specified via config.optimize.
165+
*
166+
* @param {String} fileName the name of the file that matches the
167+
* fileContents.
168+
* @param {String} fileContents the string of JS to optimize.
169+
* @param {String} [optimizerName] optional name of the optimizer to
170+
* use. 'uglify' is default.
171+
* @param {Boolean} [keepLines] whether to keep line returns in the optimization.
172+
* @param {Object} [config] the build config object.
173+
* @param {Array} [pluginCollector] storage for any plugin resources
174+
* found.
175+
*/
176+
js: function (fileName, fileContents, optimizerName, keepLines, config, pluginCollector) {
177+
var licenseContents = '',
178+
optFunc, match, comment;
179+
180+
config = config || {};
181+
156182
//Apply pragmas/namespace renaming
157183
fileContents = pragma.process(fileName, fileContents, config, 'OnSave', pluginCollector);
158184

@@ -182,7 +208,7 @@ function (lang, logger, envOptimize, file, parse,
182208
config[optimizerName]);
183209
}
184210

185-
file.saveUtf8File(outFileName, fileContents);
211+
return fileContents;
186212
},
187213

188214
/**

0 commit comments

Comments
 (0)