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

Commit

Permalink
fix(Rakefile): move 'use strict'; flag into the angular closure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IgorMinar committed Apr 5, 2012
1 parent 86182a9 commit 637817e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 13 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,22 @@ end

def closure_compile(filename)
puts "Compiling #{filename} ..."

min_path = path_to(filename.gsub(/\.js$/, '.min.js'))

%x(java -jar lib/closure-compiler/compiler.jar \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--js #{path_to(filename)} \
--js_output_file #{path_to(filename.gsub(/\.js$/, '.min.js'))})
--js_output_file #{min_path})

File.open(min_path, File::RDWR) do |f|
text = f.read
f.truncate 0
f.rewind
f.write text.sub("'use strict';", "").
sub(/\(function\([^)]*\)\{/, "\\0'use strict';")
end
end

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

f.write(content)
f.write(footer)
Expand Down
3 changes: 1 addition & 2 deletions src/angular.prefix
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
* (c) 2010-2012 AngularJS http://angularjs.org
* License: MIT
*/
'USE STRICT';
(function(window, document, undefined){
(function(window, document, undefined) {

0 comments on commit 637817e

Please sign in to comment.