Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 637817e

Browse files
committed
fix(Rakefile): move 'use strict'; flag into the angular closure
closure compiler is stubborn and puts the flag to the top of the file, so we have to post-process the minified file to move the flag into the angular closure.
1 parent 86182a9 commit 637817e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Rakefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,22 @@ end
305305

306306
def closure_compile(filename)
307307
puts "Compiling #{filename} ..."
308+
309+
min_path = path_to(filename.gsub(/\.js$/, '.min.js'))
310+
308311
%x(java -jar lib/closure-compiler/compiler.jar \
309312
--compilation_level SIMPLE_OPTIMIZATIONS \
310313
--language_in ECMASCRIPT5_STRICT \
311314
--js #{path_to(filename)} \
312-
--js_output_file #{path_to(filename.gsub(/\.js$/, '.min.js'))})
315+
--js_output_file #{min_path})
316+
317+
File.open(min_path, File::RDWR) do |f|
318+
text = f.read
319+
f.truncate 0
320+
f.rewind
321+
f.write text.sub("'use strict';", "").
322+
sub(/\(function\([^)]*\)\{/, "\\0'use strict';")
323+
end
313324
end
314325

315326
def concat_file(filename, deps, footer='')
@@ -324,7 +335,7 @@ def concat_file(filename, deps, footer='')
324335
gsub('"NG_VERSION_DOT"', NG_VERSION.dot).
325336
gsub('"NG_VERSION_CODENAME"', NG_VERSION.codename).
326337
gsub(/^\s*['"]use strict['"];?\s*$/, ''). # remove all file-specific strict mode flags
327-
gsub(/'USE STRICT'/, "'use strict'") # rename the placeholder in angular.prefix
338+
sub(/\(function\([^)]*\)\s*\{/, "\\0\n'use strict';") # add single strict mode flag
328339

329340
f.write(content)
330341
f.write(footer)

src/angular.prefix

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
* (c) 2010-2012 AngularJS http://angularjs.org
44
* License: MIT
55
*/
6-
'USE STRICT';
7-
(function(window, document, undefined){
6+
(function(window, document, undefined) {

0 commit comments

Comments
 (0)