terser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 756cc27e5aae90c30bfde06fddd7b21ac958b83fd03566e196b8134ba3fe9763
4
+ data.tar.gz: 03b10dead50a434af48ed4c11676bcd0ccf24ccce7b4c8f129836fee3abae491
5
+ SHA512:
6
+ metadata.gz: 7d0997164194491cf31a0dbef18e0421ca4c728844d48ae2e2fb5d09d02769454f6148c3692673c706c552b9f7695d0421fdb736384d7fb6896cd17c0ded7d5c
7
+ data.tar.gz: fdae9057fa77d5d0485e61fd836dd65a45a406a897bf542e73bff44c5b39be73c896a97e3cd3145bff10cb6a36b2875c02b6e95442a5bd107e53f721c788144e
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,44 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+ Gemfile.lock
14
+ gemfiles/*.lock
15
+
16
+ # jeweler generated
17
+ pkg
18
+
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ #.DS_Store
33
+ #
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+ #
38
+ # For emacs:
39
+ #*~
40
+ #\#*
41
+ #.\#*
42
+ #
43
+ # For vim:
44
+ #*.swp
@@ -0,0 +1,9 @@
1
+ [submodule "vendor/source-map"]
2
+ path = vendor/source-map
3
+ url = https://github.com/mozilla/source-map.git
4
+ [submodule "vendor/split"]
5
+ path = vendor/split
6
+ url = https://gist.github.com/2048056.git
7
+ [submodule "vendor/terser"]
8
+ path = vendor/terser
9
+ url = https://github.com/terser/terser.git
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,72 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.3
4
+ Exclude:
5
+ - uglifier.gemspec
6
+ - lib/uglifier/version.rb
7
+ - "vendor/**/*"
8
+ - "benchmark/*"
9
+ - "gemfiles/vendor/**/*"
10
+
11
+ Metrics/AbcSize:
12
+ Max: 20
13
+
14
+ Metrics/BlockLength:
15
+ Enabled: true
16
+ Exclude:
17
+ - "spec/**/*_spec.rb"
18
+
19
+ Metrics/ClassLength:
20
+ Enabled: false
21
+
22
+ Layout/LineLength:
23
+ Max: 150
24
+
25
+ Metrics/MethodLength:
26
+ Max: 20
27
+
28
+ Style/Encoding:
29
+ Enabled: false
30
+
31
+ Style/HashSyntax:
32
+ EnforcedStyle: hash_rockets
33
+
34
+ Style/PercentLiteralDelimiters:
35
+ Enabled: false
36
+
37
+ Style/PreferredHashMethods:
38
+ Enabled: false
39
+
40
+ Style/SignalException:
41
+ Enabled: false
42
+
43
+ Style/StringLiterals:
44
+ Enabled: false
45
+
46
+ Style/SymbolArray:
47
+ Enabled: false
48
+
49
+ Style/Alias:
50
+ Enabled: false
51
+
52
+ Style/MutableConstant:
53
+ Enabled: false
54
+
55
+ Style/ExpandPathArguments:
56
+ Enabled: false
57
+
58
+ Lint/RaiseException:
59
+ Enabled: true
60
+
61
+ Lint/StructNewOverride:
62
+ Enabled: true
63
+
64
+ Style/HashEachMethods:
65
+ Enabled: true
66
+
67
+ Style/HashTransformKeys:
68
+ Enabled: true
69
+
70
+ Style/HashTransformValues:
71
+ Enabled: true
72
+
@@ -0,0 +1,26 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3
6
+ - 2.5
7
+ - 2.7
8
+ - ruby-head
9
+ - jruby-head
10
+ - jruby-9.2.12.0
11
+ - truffleruby
12
+ before_install:
13
+ - gem install bundler -v 1.17.3
14
+ git:
15
+ submodules: false
16
+ gemfile:
17
+ - Gemfile
18
+ matrix:
19
+ include:
20
+ - rvm: 2.5
21
+ gemfile: gemfiles/miniracer
22
+ allow_failures:
23
+ - rvm: ruby-head
24
+ - rvm: truffleruby
25
+ - rvm: jruby-head
26
+ fast_finish: true
@@ -0,0 +1,4 @@
1
+ --title "Uglifier"
2
+ -
3
+ CHANGELOG.md
4
+ LICENSE.txt
@@ -0,0 +1,13 @@
1
+ ## Unreleased
2
+
3
+ ## 1.0.0 (13 July 2020)
4
+ - add sprockets wrapper
5
+ - drop Ruby < 2.3.0 support
6
+ - drop ES5 mode
7
+ - drop IE8 mode
8
+ - drop unsupported runtimes (therubyracer, therubyrhino) because they don't support ECMA6
9
+ - update tests and new options
10
+ - update SourceMap to [0.6.1](https://github.com/mozilla/source-map/compare/0.5.7...0.6.1)
11
+ - update TerserJS to [4.8.0]
12
+ - switch from UglifyJS to TerserJS (https://github.com/terser/terser)
13
+ - fork from Uglifier (https://github.com/lautis/uglifier/releases/tag/v4.2.0)
@@ -0,0 +1,47 @@
1
+ # Contributing to Terser
2
+
3
+ Any contributions to Terser are welcome, whether they are feedback, bug reports, or - even better - pull requests.
4
+
5
+ ## Development
6
+
7
+ To start working on Terser, fork the repo to your own account. [Ruby](https://www.ruby-lang.org), [bundler](http://bundler.io) and [Node.js](http://nodejs.org) are required as dependencies.
8
+
9
+ Ensure that your local copy is up-to-date before you start working on a feature or a bug fix. You should write any new code in a topic branch.
10
+
11
+ ### Tests
12
+
13
+ Try to write a test case that reproduces the problem you're trying to fix or describes a feature that you want to build. Tests are located in `spec/` directory.
14
+
15
+ Tests as a pull request are appreciated even without a fix to highlight or reproduce a problem.
16
+
17
+ To run tests, first install all project dependencies:
18
+
19
+ bundle install
20
+
21
+ Then run tests using rake:
22
+
23
+ bundle exec rake
24
+
25
+ ### Updating TerserJS and source-map
26
+
27
+ [TerserJS](https://github.com/terser/terser) and [source-map](https://github.com/mozilla/source-map/) are included in the project as Git submodules. To install submodules, run in your terminal
28
+
29
+ git submodule update --init
30
+
31
+ After that, Terser can be updated to a specific version with rake task.
32
+
33
+ rake terser:update VERSION=3.3.4
34
+
35
+ To compile JS with dependencies, run
36
+
37
+ rake terser:build
38
+
39
+ You can even write custom patches to TerserJS in `vendor/terser` directory and compile the bundles JS using the command above. However, for the changes to be releasable, they should be in TerserJS repository.
40
+
41
+ To automatically update TerserJS version and commit changes
42
+
43
+ rake terser VERSION=3.3.4
44
+
45
+ ## Reporting issues
46
+
47
+ Terser uses the [GitHub issue tracker](https://github.com/ahorek/terser-ruby/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. When submitting a bug report, please include a Gist that includes a stack trace and any details that may be necessary to reproduce the bug, including your gem version, Ruby version, and **ExecJS runtime**. Ideally, a bug report should include a pull request with failing specs.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem 'rubocop', '~> 0.81.0', :group => [:development]
@@ -0,0 +1,93 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Pavel Rosick�
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+
25
+ https://github.com/lautis/uglifier
26
+ /***********************************************************************
27
+ Copyright (c) 2011 Ville Lautanala
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining
30
+ a copy of this software and associated documentation files (the
31
+ "Software"), to deal in the Software without restriction, including
32
+ without limitation the rights to use, copy, modify, merge, publish,
33
+ distribute, sublicense, and/or sell copies of the Software, and to
34
+ permit persons to whom the Software is furnished to do so, subject to
35
+ the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be
38
+ included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
43
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
44
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
45
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
46
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47
+ ***********************************************************************/
48
+
49
+
50
+
51
+ https://github.com/mishoo/UglifyJS
52
+ /***********************************************************************
53
+
54
+ A JavaScript tokenizer / parser / beautifier / compressor.
55
+ https://github.com/mishoo/UglifyJS2
56
+
57
+ -------------------------------- (C) ---------------------------------
58
+
59
+ Author: Mihai Bazon
60
+ <mihai.bazon@gmail.com>
61
+ http://mihai.bazon.net/blog
62
+
63
+ Distributed under the BSD license:
64
+
65
+ Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
66
+
67
+ Redistribution and use in source and binary forms, with or without
68
+ modification, are permitted provided that the following conditions
69
+ are met:
70
+
71
+ * Redistributions of source code must retain the above
72
+ copyright notice, this list of conditions and the following
73
+ disclaimer.
74
+
75
+ * Redistributions in binary form must reproduce the above
76
+ copyright notice, this list of conditions and the following
77
+ disclaimer in the documentation and/or other materials
78
+ provided with the distribution.
79
+
80
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER �AS IS� AND ANY
81
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
83
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
84
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
85
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
86
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
87
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
88
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
89
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
90
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91
+ SUCH DAMAGE.
92
+
93
+ ***********************************************************************/
@@ -0,0 +1,177 @@
1
+ # Terser
2
+
3
+ Ruby wrapper for [Terser](https://github.com/terser/terser) JavaScript
4
+ compressor.
5
+
6
+ a fork based on https://github.com/lautis/uglifier and https://github.com/mishoo/UglifyJS2
7
+
8
+ ES6 support
9
+
10
+ [![Build Status](https://travis-ci.org/ahorek/terser-ruby.svg?branch=master)](https://travis-ci.org/ahorek/terser-ruby)
11
+
12
+ ### Rails
13
+
14
+ When used in Rails, replace
15
+
16
+ ```ruby
17
+ Sprockets.register_compressor 'application/javascript', :terser, Terser::Compressor
18
+ Rails.application.configure do
19
+ config.assets.js_compressor = :terser
20
+ end
21
+ ```
22
+ in `config/environments/production.rb`.
23
+
24
+ ## Installation
25
+
26
+ Terser is available as a ruby gem.
27
+
28
+ $ gem install terser
29
+
30
+ Ensure that your environment has a JavaScript interpreter supported by
31
+ [ExecJS](https://github.com/sstephenson/execjs). Using `miniracer` gem or NodeJS
32
+ is recommended.
33
+
34
+ ## Usage
35
+
36
+ ```ruby
37
+ require 'terser'
38
+
39
+ Terser.new.compile(File.read("source.js"))
40
+ # => js file minified
41
+
42
+ # Or alternatively
43
+ Terser.compile(File.read("source.js"))
44
+ ```
45
+
46
+ Terser also supports generating source maps:
47
+
48
+ ```ruby
49
+ uglified, source_map = Terser.new.compile_with_map(source)
50
+ ```
51
+
52
+ When initializing Terser, you can tune the behavior of Terser by passing options. For example, if you want disable variable name mangling:
53
+
54
+ ```ruby
55
+ Terser.new(:mangle => false).compile(source)
56
+
57
+ # Or
58
+ Terser.compile(source, :mangle => false)
59
+ ```
60
+
61
+ Available options and their defaults are
62
+
63
+ ```ruby
64
+ {
65
+ :output => {
66
+ :ascii_only => true, # Escape non-ASCII characters
67
+ :comments => :copyright, # Preserve comments (:all, :jsdoc, :copyright, :none, Regexp (see below))
68
+ :inline_script => false, # Escape occurrences of </script in strings
69
+ :quote_keys => false, # Quote keys in object literals
70
+ :max_line_len => 32 * 1024, # Maximum line length in minified code
71
+ :bracketize => false, # Bracketize if, for, do, while or with statements, even if their body is a single statement
72
+ :semicolons => true, # Separate statements with semicolons
73
+ :preserve_line => false, # Preserve line numbers in outputs
74
+ :beautify => false, # Beautify output
75
+ :indent_level => 4, # Indent level in spaces
76
+ :indent_start => 0, # Starting indent level
77
+ :width => 80, # Specify line width when beautifier is used (only with beautifier)
78
+ :preamble => nil, # Preamble for the generated JS file. Can be used to insert any code or comment.
79
+ :wrap_iife => false # Wrap IIFEs in parenthesis. Note: this disables the negate_iife compression option.
80
+ :shebang => true # Preserve shebang (#!) in preamble (shell scripts)
81
+ :quote_style => 0, # Quote style, possible values :auto (default), :single, :double, :original
82
+ :keep_quoted_props => false # Keep quotes property names
83
+ },
84
+ :mangle => {
85
+ :eval => false, # Mangle names when eval of when is used in scope
86
+ :reserved => ["$super"], # Argument names to be excluded from mangling
87
+ :sort => false, # Assign shorter names to most frequently used variables. Often results in bigger output after gzip.
88
+ :toplevel => false, # Mangle names declared in the toplevel scope
89
+ :properties => false, # Mangle property names
90
+ :keep_fnames => false # Do not modify function names
91
+ }, # Mangle variable and function names, set to false to skip mangling
92
+ :mangle_properties => {
93
+ :regex => nil, # A regular expression to filter property names to be mangled
94
+ :ignore_quoted => false, # Only mangle unquoted property names
95
+ :debug => false, # Mangle names with the original name still present
96
+ } # Mangle property names, disabled by default
97
+ :compress => {
98
+ :sequences => true, # Allow statements to be joined by commas
99
+ :properties => true, # Rewrite property access using the dot notation
100
+ :dead_code => true, # Remove unreachable code
101
+ :drop_debugger => true, # Remove debugger; statements
102
+ :unsafe => false, # Apply "unsafe" transformations
103
+ :unsafe_comps => false, # Reverse < and <= to > and >= to allow improved compression. This might be unsafe when an at least one of two operands is an object with computed values due the use of methods like get, or valueOf. This could cause change in execution order after operands in the comparison are switching. Compression only works if both comparisons and unsafe_comps are both set to true.
104
+ :unsafe_math => false, # Optimize numerical expressions like 2 * x * 3 into 6 * x, which may give imprecise floating point results.
105
+ :unsafe_proto => false, # Optimize expressions like Array.prototype.slice.call(a) into [].slice.call(a)
106
+ :conditionals => true, # Optimize for if-s and conditional expressions
107
+ :comparisons => true, # Apply binary node optimizations for comparisons
108
+ :evaluate => true, # Attempt to evaluate constant expressions
109
+ :booleans => true, # Various optimizations to boolean contexts
110
+ :loops => true, # Optimize loops when condition can be statically determined
111
+ :unused => true, # Drop unreferenced functions and variables
112
+ :toplevel => false, # Drop unreferenced top-level functions and variables
113
+ :top_retain => [], # prevent specific toplevel functions and variables from `unused` removal
114
+ :hoist_funs => true, # Hoist function declarations
115
+ :hoist_vars => false, # Hoist var declarations
116
+ :if_return => true, # Optimizations for if/return and if/continue
117
+ :join_vars => true, # Join consecutive var statements
118
+ :collapse_vars => false, # Collapse single-use var and const definitions when possible.
119
+ :reduce_funcs => false, # Inline single-use functions as function expressions. Depends on reduce_vars.
120
+ :reduce_vars => false, # Collapse variables assigned with and used as constant values.
121
+ :negate_iife => true, # Negate immediately invoked function expressions to avoid extra parens
122
+ :pure_getters => false, # Assume that object property access does not have any side-effects
123
+ :pure_funcs => nil, # List of functions without side-effects. Can safely discard function calls when the result value is not used
124
+ :drop_console => false, # Drop calls to console.* functions
125
+ :keep_fargs => false, # Preserve unused function arguments
126
+ :keep_fnames => false, # Do not drop names in function definitions
127
+ :passes => 1, # Number of times to run compress. Raising the number of passes will increase compress time, but can produce slightly smaller code.
128
+ :keep_infinity => false, # Prevent compression of Infinity to 1/0
129
+ :side_effects => true, # Pass false to disable potentially dropping functions marked as "pure" using pure comment annotation. See UglifyJS documentation for details.
130
+ :switches => true, # de-duplicate and remove unreachable switch branches
131
+ }, # Apply transformations to code, set to false to skip
132
+ :parse => {
133
+ :bare_returns => false, # Allow top-level return statements.
134
+ :expression => false, # Parse a single expression, rather than a program (for parsing JSON).
135
+ :html5_comments => true, # Ignore HTML5 comments in input
136
+ :shebang => true, # support #!command as the first line
137
+ :strict => false
138
+ },
139
+ :define => {}, # Define values for symbol replacement
140
+ :enclose => false, # Enclose in output function wrapper, define replacements as key-value pairs
141
+ :keep_fnames => false, # Generate code safe for the poor souls relying on Function.prototype.name at run-time. Sets both compress and mangle keep_fanems to true.
142
+ :source_map => {
143
+ :map_url => false, # Url for source mapping to be appended in minified source
144
+ :url => false, # Url for original source to be appended in minified source
145
+ :sources_content => false, # Include original source content in map
146
+ :filename => nil, # The filename of the input file
147
+ :root => nil, # The URL of the directory which contains :filename
148
+ :output_filename => nil, # The filename or URL where the minified output can be found
149
+ :input_source_map => nil # The contents of the source map describing the input
150
+ },
151
+ :error_context_lines => 8, # How many context lines surrounding the error line. Env var ERROR_CONTEXT_LINES overrides this option
152
+ }
153
+ ```
154
+
155
+ When passing a regular expression to the output => comments option, be sure to pass a valid Ruby Regexp.
156
+ The beginning and ending of comments are removed and cannot be matched (/*, */, //). For example:
157
+ When matching
158
+
159
+ ```
160
+ /*!
161
+ * comment
162
+ */
163
+ ```
164
+
165
+ use `Terser.new(output: {comments: /^!/})`.
166
+
167
+ ## Development
168
+
169
+ Tests are run using
170
+
171
+ bundle exec rake
172
+
173
+ See [CONTRIBUTING](https://github.com/ahorek/terser-ruby/blob/master/CONTRIBUTING.md) for details about working on and contributing to Terser.
174
+
175
+ ## Copyright
176
+
177
+ Released under MIT license, see [LICENSE](https://github.com/ahorek/terser-ruby/blob/master/LICENSE.txt) for details.