diff --git a/README.md b/README.md index 842cfd3a..11f09b7f 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ a double dash to prevent input files being used as option arguments: --keep-classnames Do not mangle/drop class names. --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name. + --module Input is an ES6 module --name-cache File to hold mangled name mappings. --safari10 Support non-standard Safari 10/11. Equivalent to setting `safari10: true` in `minify()` diff --git a/bin/uglifyjs b/bin/uglifyjs index 21635bcb..41bdef2b 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -44,6 +44,7 @@ program.option("--ecma ", "Specify ECMAScript release: 5, 6, 7 or 8."); program.option("--ie8", "Support non-standard Internet Explorer 8."); program.option("--keep-classnames", "Do not mangle/drop class names."); program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name."); +program.option("--module", "Input is an ES6 module"); program.option("--name-cache ", "File to hold mangled name mappings."); program.option("--rename", "Force symbol expansion."); program.option("--no-rename", "Disable symbol expansion."); @@ -66,6 +67,7 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") { "compress", "ie8", "mangle", + "module", "safari10", "sourceMap", "toplevel", diff --git a/lib/compress.js b/lib/compress.js index 886a4b5b..37de2b43 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -73,6 +73,7 @@ function Compressor(options, false_by_default) { keep_fnames : false, keep_infinity : false, loops : !false_by_default, + module : false, negate_iife : !false_by_default, passes : 1, properties : !false_by_default, @@ -138,6 +139,9 @@ function Compressor(options, false_by_default) { funcs: toplevel, vars: toplevel }; + if (this.options['module']) { + this.directives['use strict'] = true; + } var sequences = this.options["sequences"]; this.sequences_limit = sequences == 1 ? 800 : sequences | 0; this.warnings_produced = {}; diff --git a/lib/minify.js b/lib/minify.js index ee1d478b..fdc48961 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -52,6 +52,7 @@ function minify(files, options) { keep_classnames: undefined, keep_fnames: false, mangle: {}, + module: false, nameCache: null, output: {}, parse: {}, @@ -76,6 +77,7 @@ function minify(files, options) { set_shorthand("ie8", options, [ "compress", "mangle", "output" ]); set_shorthand("keep_classnames", options, [ "compress", "mangle" ]); set_shorthand("keep_fnames", options, [ "compress", "mangle" ]); + set_shorthand("module", options, [ "compress" ]); set_shorthand("safari10", options, [ "mangle", "output" ]); set_shorthand("toplevel", options, [ "compress", "mangle" ]); set_shorthand("warnings", options, [ "compress" ]); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index b85214ec..7d2fdb93 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -1601,3 +1601,19 @@ issue_2874_3: { ] node_version: ">=6" } + +module_enables_strict_mode: { + options = { + module: true, + } + input: { + if (1) { + function xyz() {} + } + } + expect: { + if (1) { + function xyz() {} + } + } +}