uglifier 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of uglifier might be problematic. Click here for more details.

data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
+ - 1.9.3
4
5
  - jruby
5
6
  before_script: "git submodule update --init --recursive"
6
7
  env:
@@ -13,6 +14,8 @@ matrix:
13
14
  env: EXECJS_RUNTIME=RubyRhino
14
15
  - rvm: 1.9.2
15
16
  env: EXECJS_RUNTIME=RubyRhino
17
+ - rvm: 1.9.3
18
+ env: EXECJS_RUNTIME=RubyRhino
16
19
  - rvm: jruby
17
20
  env: EXECJS_RUNTIME=RubyRacer
18
21
  - rvm: jruby
data/Gemfile CHANGED
@@ -18,8 +18,9 @@ end
18
18
  gem ENV["MULTI_JSON_ENGINE"], :group => :development if ENV["MULTI_JSON_ENGINE"]
19
19
 
20
20
  group :development do
21
- gem "rspec", "~> 2.6.0"
21
+ gem "rspec", "~> 2.7"
22
22
  gem "bundler", "~> 1.0.0"
23
23
  gem "jeweler", "~> 1.6.0"
24
24
  gem "rcov", ">= 0"
25
+ gem "rdoc", "~> 3.11"
25
26
  end
data/README.rdoc CHANGED
@@ -38,15 +38,17 @@ Available options and their defaults are
38
38
  :squeeze => true, # Squeeze code resulting in smaller, but less-readable code
39
39
  :seqs => true, # Reduce consecutive statements in blocks into single statement
40
40
  :dead_code => true, # Remove dead code (e.g. after return)
41
+ :lift_vars => false, # Lift all var declarations at the start of the scope
41
42
  :unsafe => false, # Optimizations known to be unsafe in some situations
42
43
  :copyright => true, # Show copyright message
44
+ :ascii_only => false, # Encode non-ASCII characters as Unicode code points
45
+ :inline_script => false, # Escape </script
46
+ :quote_keys => false, # Quote keys in object literals
43
47
  :beautify => false, # Ouput indented code
44
48
  :beautify_options => {
45
49
  :indent_level => 4,
46
50
  :indent_start => 0,
47
- :quote_keys => false,
48
- :space_colon => 0,
49
- :ascii_only => false
51
+ :space_colon => false
50
52
  }
51
53
  }
52
54
 
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  task :default => :spec
35
35
 
36
- require 'rake/rdoctask'
36
+ require 'rdoc/task'
37
37
  Rake::RDocTask.new do |rdoc|
38
38
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
39
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.1.0
data/lib/es5.js CHANGED
@@ -150,4 +150,38 @@ if (!Array.prototype.reduce)
150
150
 
151
151
  return accumulator;
152
152
  };
153
- }
153
+ }
154
+
155
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
156
+ if (!Array.prototype.indexOf) {
157
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
158
+ "use strict";
159
+ if (this === void 0 || this === null) {
160
+ throw new TypeError();
161
+ }
162
+ var t = Object(this);
163
+ var len = t.length >>> 0;
164
+ if (len === 0) {
165
+ return -1;
166
+ }
167
+ var n = 0;
168
+ if (arguments.length > 0) {
169
+ n = Number(arguments[1]);
170
+ if (n !== n) { // shortcut for verifying if it's NaN
171
+ n = 0;
172
+ } else if (n !== 0 && n !== Infinity && n !== -Infinity) {
173
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
174
+ }
175
+ }
176
+ if (n >= len) {
177
+ return -1;
178
+ }
179
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
180
+ for (; k < len; k++) {
181
+ if (k in t && t[k] === searchElement) {
182
+ return k;
183
+ }
184
+ }
185
+ return -1;
186
+ }
187
+ }
data/lib/uglifier.rb CHANGED
@@ -16,15 +16,17 @@ class Uglifier
16
16
  :squeeze => true, # Squeeze code resulting in smaller, but less-readable code
17
17
  :seqs => true, # Reduce consecutive statements in blocks into single statement
18
18
  :dead_code => true, # Remove dead code (e.g. after return)
19
+ :lift_vars => false, # Lift all var declarations at the start of the scope
19
20
  :unsafe => false, # Optimizations known to be unsafe in some situations
20
21
  :copyright => true, # Show copyright message
22
+ :ascii_only => false, # Encode non-ASCII characters as Unicode code points
23
+ :inline_script => false, # Escape </script
24
+ :quote_keys => false, # Quote keys in object literals
21
25
  :beautify => false, # Ouput indented code
22
26
  :beautify_options => {
23
27
  :indent_level => 4,
24
28
  :indent_start => 0,
25
- :quote_keys => false,
26
- :space_colon => 0,
27
- :ascii_only => false
29
+ :space_colon => false
28
30
  }
29
31
  }
30
32
 
@@ -62,6 +64,10 @@ class Uglifier
62
64
  js << "var source = #{MultiJson.encode(source)};"
63
65
  js << "var ast = UglifyJS.parser.parse(source);"
64
66
 
67
+ if @options[:lift_vars]
68
+ js << "ast = UglifyJS.uglify.ast_lift_variables(ast);"
69
+ end
70
+
65
71
  if @options[:copyright]
66
72
  js << <<-JS
67
73
  var comments = UglifyJS.parser.tokenizer(source)().comments_before;
@@ -115,7 +121,16 @@ class Uglifier
115
121
  end
116
122
 
117
123
  def gen_code_options
118
-
119
- @options[:beautify] ? {:beautify => true}.merge(@options[:beautify_options]) : {}
124
+ options = {
125
+ :ascii_only => @options[:ascii_only],
126
+ :inline_script => @options[:inline_script],
127
+ :quote_keys => @options[:quote_keys]
128
+ }
129
+
130
+ if @options[:beautify]
131
+ options.merge(:beautify => true).merge(@options[:beautify_options])
132
+ else
133
+ options
134
+ end
120
135
  end
121
136
  end
@@ -87,6 +87,26 @@ describe "Uglifier" do
87
87
  Uglifier.compile(code, :max_line_length => 8).split("\n").length.should == 2
88
88
  end
89
89
 
90
+ it "lifts vars to top of the scope" do
91
+ code = "function something() { var foo = 123; foo = 1234; var bar = 123456; return foo + bar}"
92
+ Uglifier.compile(code, :lift_vars => true).should include("var a,b")
93
+ end
94
+
95
+ it "can be configured to output only ASCII" do
96
+ code = "function emoji() { return '\\ud83c\\ude01'; }"
97
+ Uglifier.compile(code, :ascii_only => true).should include("\\ud83c\\ude01")
98
+ end
99
+
100
+ it "escapes </script when asked to" do
101
+ code = "function test() { return '</script>';}"
102
+ Uglifier.compile(code, :inline_script => true).should_not include("</script>")
103
+ end
104
+
105
+ it "quotes keys" do
106
+ code = "var a = {foo: 1}"
107
+ Uglifier.compile(code, :quote_keys => true).should include('"foo"')
108
+ end
109
+
90
110
  describe "Input Formats" do
91
111
  it "handles strings" do
92
112
  lambda {
data/uglifier.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "uglifier"
8
- s.version = "1.0.4"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ville Lautanala"]
12
- s.date = "2011-10-18"
12
+ s.date = "2011-11-15"
13
13
  s.email = "lautis@gmail.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -44,25 +44,28 @@ Gem::Specification.new do |s|
44
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
45
  s.add_runtime_dependency(%q<execjs>, [">= 0.3.0"])
46
46
  s.add_runtime_dependency(%q<multi_json>, [">= 1.0.2"])
47
- s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.7"])
48
48
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
49
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
50
50
  s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.11"])
51
52
  else
52
53
  s.add_dependency(%q<execjs>, [">= 0.3.0"])
53
54
  s.add_dependency(%q<multi_json>, [">= 1.0.2"])
54
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.7"])
55
56
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
57
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
57
58
  s.add_dependency(%q<rcov>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, ["~> 3.11"])
58
60
  end
59
61
  else
60
62
  s.add_dependency(%q<execjs>, [">= 0.3.0"])
61
63
  s.add_dependency(%q<multi_json>, [">= 1.0.2"])
62
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.7"])
63
65
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
66
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
65
67
  s.add_dependency(%q<rcov>, [">= 0"])
68
+ s.add_dependency(%q<rdoc>, ["~> 3.11"])
66
69
  end
67
70
  end
68
71
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uglifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 1.0.4
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ville Lautanala
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-18 00:00:00 Z
18
+ date: 2011-11-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
22
23
  none: false
23
24
  requirements:
24
25
  - - ">="
@@ -29,12 +30,12 @@ dependencies:
29
30
  - 3
30
31
  - 0
31
32
  version: 0.3.0
32
- name: execjs
33
33
  prerelease: false
34
- type: :runtime
35
- requirement: *id001
34
+ name: execjs
35
+ version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ type: :runtime
38
+ requirement: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
40
41
  - - ">="
@@ -45,28 +46,27 @@ dependencies:
45
46
  - 0
46
47
  - 2
47
48
  version: 1.0.2
48
- name: multi_json
49
49
  prerelease: false
50
- type: :runtime
51
- requirement: *id002
50
+ name: multi_json
51
+ version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
56
57
  - - ~>
57
58
  - !ruby/object:Gem::Version
58
- hash: 23
59
+ hash: 13
59
60
  segments:
60
61
  - 2
61
- - 6
62
- - 0
63
- version: 2.6.0
64
- name: rspec
62
+ - 7
63
+ version: "2.7"
65
64
  prerelease: false
66
- type: :development
67
- requirement: *id003
65
+ name: rspec
66
+ version_requirements: *id003
68
67
  - !ruby/object:Gem::Dependency
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ type: :development
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
72
  - - ~>
@@ -77,12 +77,12 @@ dependencies:
77
77
  - 0
78
78
  - 0
79
79
  version: 1.0.0
80
- name: bundler
81
80
  prerelease: false
82
- type: :development
83
- requirement: *id004
81
+ name: bundler
82
+ version_requirements: *id004
84
83
  - !ruby/object:Gem::Dependency
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ type: :development
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -93,12 +93,12 @@ dependencies:
93
93
  - 6
94
94
  - 0
95
95
  version: 1.6.0
96
- name: jeweler
97
96
  prerelease: false
98
- type: :development
99
- requirement: *id005
97
+ name: jeweler
98
+ version_requirements: *id005
100
99
  - !ruby/object:Gem::Dependency
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ type: :development
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
104
104
  - - ">="
@@ -107,10 +107,24 @@ dependencies:
107
107
  segments:
108
108
  - 0
109
109
  version: "0"
110
- name: rcov
111
110
  prerelease: false
111
+ name: rcov
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
112
114
  type: :development
113
- requirement: *id006
115
+ requirement: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ hash: 17
121
+ segments:
122
+ - 3
123
+ - 11
124
+ version: "3.11"
125
+ prerelease: false
126
+ name: rdoc
127
+ version_requirements: *id007
114
128
  description:
115
129
  email: lautis@gmail.com
116
130
  executables: []