From ccd7ad0efd8959fb1753c78e8010f8e21cbab6c9 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 12 May 2017 19:56:33 +0800 Subject: [PATCH] Upgrade to uglify-js 3.0.4. (#472) Upgrade to uglify-js 3.0.4 --- Gruntfile.js | 122 ++++--- docs/uglify-examples.md | 32 +- docs/uglify-options.md | 71 ++-- package.json | 3 +- tasks/lib/uglify.js | 335 +++++------------- tasks/uglify.js | 58 ++- test/fixtures/expected/beautify.js | 8 +- test/fixtures/expected/compress_explicit.js | 2 +- test/fixtures/expected/compress_mangle.js | 2 +- .../expected/compress_mangle_banner.js | 2 +- .../expected/compress_mangle_beautify.js | 4 +- .../expected/compress_mangle_except.js | 2 +- test/fixtures/expected/enclose.js | 8 - test/fixtures/expected/exportAll.js | 1 - test/fixtures/expected/mangle.js | 2 +- test/fixtures/expected/mangleprops.js | 2 +- .../expected/mangleprops_withExcept.js | 2 +- ...angleprops_withExceptAndExceptionsFiles.js | 2 +- .../mangleprops_withExceptionsFiles.js | 2 +- .../mangleprops_withNameCacheFile1.js | 2 +- .../mangleprops_withNameCacheFile2.js | 2 +- test/fixtures/expected/maxLineLen.js | 6 +- test/fixtures/expected/sourcemap_basic.js | 2 +- test/fixtures/expected/sourcemap_customDir.js | 2 +- .../fixtures/expected/sourcemap_customName.js | 2 +- .../fixtures/expected/sourcemap_customRoot.js | 2 +- test/fixtures/expected/sourcemap_customUrl.js | 2 +- .../expected/sourcemap_customUrl.js.map | 1 + .../expected/sourcemap_functionName.js | 2 +- test/fixtures/expected/sourcemapin.js | 2 +- test/fixtures/expected/sourcemapin.js.map | 2 +- test/fixtures/expected/sourcemapin_sources.js | 2 +- .../expected/sourcemapin_sources.js.map | 2 +- .../fixtures/expected/sourcemaps_multiple1.js | 2 +- .../expected/sourcemaps_multiple1_fnName.js | 2 +- test/fixtures/expected/uglify_name_cache.json | 20 +- test/fixtures/expected/wrap.js | 2 +- test/uglify_test.js | 4 +- 38 files changed, 275 insertions(+), 446 deletions(-) delete mode 100644 test/fixtures/expected/enclose.js delete mode 100644 test/fixtures/expected/exportAll.js create mode 100644 test/fixtures/expected/sourcemap_customUrl.js.map diff --git a/Gruntfile.js b/Gruntfile.js index 08218565..4810896a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -70,7 +70,7 @@ module.exports = function(grunt) { }, options: { mangle: { - except: ['argumentC'] + reserved: ['argumentC'] } } }, @@ -83,20 +83,6 @@ module.exports = function(grunt) { footer: '\n// This is a footer.' } }, - enclose: { - files: { - 'tmp/enclose.js': ['test/fixtures/src/simple.js'] - }, - options: { - beautify: true, - compress: false, - enclose: { - 'window.argA': 'paramA', - 'window.argB': 'paramB' - }, - mangle: false - } - }, multifile: { files: { 'tmp/multifile.js': ['test/fixtures/src/simple.js', 'test/fixtures/src/comments.js'] @@ -110,7 +96,9 @@ module.exports = function(grunt) { dest: 'tmp/comments.js', options: { mangle: false, - preserveComments: 'some' + output: { + comments: 'some' + } } }, commentsWithImportant: { @@ -118,7 +106,9 @@ module.exports = function(grunt) { dest: 'tmp/commentsWithImportant.js', options: { mangle: false, - preserveComments: /^!|@preserve|@license|@cc_on/i + output: { + comments: /^!|@preserve|@license|@cc_on/i + } } }, wrap: { @@ -134,7 +124,9 @@ module.exports = function(grunt) { dest: 'tmp/maxLineLen.js', options: { mangle: false, - maxLineLen: 100 + output: { + max_line_len: 100 + } } }, ASCIIOnly: { @@ -142,23 +134,16 @@ module.exports = function(grunt) { dest: 'tmp/asciionly.js', options: { mangle: false, - ASCIIOnly: true + output: { + ascii_only: true + } } }, screwIE8: { src: 'test/fixtures/src/screwIE8.js', dest: 'tmp/screwIE8.js', options: { - screwIE8: false - } - }, - exportAll: { - src: 'test/fixtures/src/simple.js', - dest: 'tmp/exportAll.js', - options: { - mangle: false, - wrap: 'testExport', - exportAll: true + ie8: true } }, sourcemap_basic: { @@ -188,16 +173,18 @@ module.exports = function(grunt) { src: 'test/fixtures/src/simple.js', dest: 'tmp/sourcemap_customRoot.js', options: { - sourceMap: true, - sourceMapRoot: 'https://github.com/RReverser/grunt-contrib-uglify/tree/master/tmp' + sourceMap: { + root: 'https://github.com/RReverser/grunt-contrib-uglify/tree/master/tmp' + } } }, sourcemap_customUrl: { src: 'test/fixtures/src/simple.js', dest: 'tmp/sourcemap_customUrl.js', options: { - sourceMap: true, - sourceMapUrl: 'http://www.test.com/test/sourcemap_customUrl.js.map' + sourceMap: { + url: 'http://www.test.com/test/sourcemap_customUrl.js.map' + } } }, sourcemap_functionName: { @@ -227,7 +214,7 @@ module.exports = function(grunt) { options: { sourceMap: true, sourceMapName: function(dest) { - return dest+'.fn.map'; + return dest + '.fn.map'; } } }, @@ -238,11 +225,12 @@ module.exports = function(grunt) { options: { mangle: false, banner: '// Hello World\n', - sourceMap: true, + sourceMap: { + includeSources: false + }, sourceMapIn: function() { return 'test/fixtures/src/simple2.map'; - }, - sourceMapIncludeSources: false + } } }, sourcemap_sources: { @@ -250,8 +238,9 @@ module.exports = function(grunt) { 'tmp/sourcemap_sources.js': ['test/fixtures/src/simple.js'] }, options: { - sourceMap: true, - sourceMapIncludeSources: true + sourceMap: { + includeSources: true + } } }, sourcemapin_sources: { @@ -259,11 +248,12 @@ module.exports = function(grunt) { 'tmp/sourcemapin_sources.js': ['test/fixtures/src/simple2.js'] }, options: { - sourceMap: true, + sourceMap: { + includeSources: true + }, sourceMapIn: function() { return 'test/fixtures/src/simple2.map'; - }, - sourceMapIncludeSources: true + } } }, expression_json: { @@ -271,7 +261,9 @@ module.exports = function(grunt) { 'tmp/expression.json': ['test/fixtures/src/simple.json'] }, options: { - expression: true, + parse: { + expression: true + }, mangle: false, compress: false } @@ -281,7 +273,9 @@ module.exports = function(grunt) { 'tmp/expression.js': ['test/fixtures/src/expression.js'] }, options: { - expression: true, + parse: { + expression: true + }, mangle: false, compress: false } @@ -291,7 +285,9 @@ module.exports = function(grunt) { 'tmp/mangleprops.js': ['test/fixtures/src/mangleprops.js'] }, options: { - mangleProperties: true + mangle: { + properties: true + } } }, mangleprops_withExcept: { @@ -300,9 +296,9 @@ module.exports = function(grunt) { }, options: { mangle: { - except: ['dontMangleMeVariable'] - }, - mangleProperties: true + reserved: ['dontMangleMeVariable'], + properties: true + } } }, mangleprops_withExceptionsFiles: { @@ -311,9 +307,9 @@ module.exports = function(grunt) { }, options: { mangle: { - toplevel: true + toplevel: true, + properties: true }, - mangleProperties: true, exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json'] } }, @@ -324,9 +320,9 @@ module.exports = function(grunt) { options: { mangle: { toplevel: true, - except: ['dontMangleMeVariable'] + reserved: ['dontMangleMeVariable'], + properties: true }, - mangleProperties: true, exceptionsFiles: ['test/fixtures/src/exceptionsfile1.json', 'test/fixtures/src/exceptionsfile2.json'] } }, @@ -337,9 +333,9 @@ module.exports = function(grunt) { }, options: { mangle: { - toplevel: true + toplevel: true, + properties: true }, - mangleProperties: true, nameCache: 'tmp/uglify_name_cache.json' } }, @@ -348,8 +344,10 @@ module.exports = function(grunt) { 'tmp/mangleprops_withRegex.js': ['test/fixtures/src/mangleprops_withRegex.js'] }, options: { - mangleProperties: { - regex: /^[^#].*/ + mangle: { + properties: { + regex: /^[^#].*/ + } } } }, @@ -358,7 +356,9 @@ module.exports = function(grunt) { 'tmp/quotes_single.js': ['test/fixtures/src/quotes.js'] }, options: { - quoteStyle: 1 + output: { + quote_style: 1 + } } }, quotes_double: { @@ -366,7 +366,9 @@ module.exports = function(grunt) { 'tmp/quotes_double.js': ['test/fixtures/src/quotes.js'] }, options: { - quoteStyle: 2 + output: { + quote_style: 2 + } } }, quotes_original: { @@ -374,7 +376,9 @@ module.exports = function(grunt) { 'tmp/quotes_original.js': ['test/fixtures/src/quotes.js'] }, options: { - quoteStyle: 3 + output: { + quote_style: 3 + } } }, mangle_isNotObject: { diff --git a/docs/uglify-examples.md b/docs/uglify-examples.md index 1aef3ad1..a1c9d2a5 100644 --- a/docs/uglify-examples.md +++ b/docs/uglify-examples.md @@ -39,7 +39,7 @@ grunt.initConfig({ ## Reserved identifiers -You can specify identifiers to leave untouched with an `except` array in the `mangle` options. +You can specify identifiers to leave untouched with an `reserved` array in the `mangle` options. ```js // Project configuration. @@ -47,7 +47,7 @@ grunt.initConfig({ uglify: { options: { mangle: { - except: ['jQuery', 'Backbone'] + reserved: ['jQuery', 'Backbone'] } }, my_target: { @@ -85,7 +85,7 @@ grunt.initConfig({ ## Advanced source maps -Set the `sourceMapIncludeSources` option to `true` to embed your sources directly into the map. To include +Set the `sourceMap.includeSources` option to `true` to embed your sources directly into the map. To include a source map from a previous compilation pass it as the value of the `sourceMapIn` option. ```js @@ -94,8 +94,9 @@ grunt.initConfig({ uglify: { my_target: { options: { - sourceMap: true, - sourceMapIncludeSources: true, + sourceMap: { + includeSources: true + }, sourceMapIn: 'example/coffeescript-sourcemap.js', // input sourcemap from a previous compilation }, files: { @@ -106,7 +107,7 @@ grunt.initConfig({ }); ``` -Refer to the [UglifyJS SourceMap Documentation](http://lisperator.net/uglifyjs/codegen#source-map) for more information. +Refer to the [UglifyJS SourceMap Documentation](https://github.com/mishoo/UglifyJS2#source-map-options) for more information. ## Turn off console warnings @@ -134,11 +135,9 @@ grunt.initConfig({ ## Beautify Specify `beautify: true` to beautify your code for debugging/troubleshooting purposes. -Pass an object to manually configure any other output options passed directly to `UglifyJS.OutputStream()`. - -See [UglifyJS Codegen documentation](http://lisperator.net/uglifyjs/codegen) for more information. +Pass an object to manually configure any other output options. -_Note that manual configuration will require you to explicitly set `beautify: true` if you want traditional, beautified output._ +See [UglifyJS documentation](https://github.com/mishoo/UglifyJS2#beautifier-options) for more information. ```js // Project configuration. @@ -155,8 +154,7 @@ grunt.initConfig({ my_advanced_target: { options: { beautify: { - width: 80, - beautify: true + width: 80 } }, files: { @@ -193,9 +191,9 @@ grunt.initConfig({ ## Conditional compilation -You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds. This is equivalent to the command line [`--define` option](https://github.com/mishoo/UglifyJS#use-as-a-code-pre-processor). +You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds. This is equivalent to the command line `--define` option. -See [UglifyJS global definitions documentation](http://lisperator.net/uglifyjs/compress#global-defs) for more information. +See [UglifyJS global definitions documentation](https://github.com/mishoo/UglifyJS2#conditional-compilation) for more information. ```js // Project configuration. @@ -250,7 +248,7 @@ uglify: { dev: { options: { mangle: { - except: ['jQuery'] + reserved: ['jQuery'] } }, files: [{ @@ -280,7 +278,9 @@ on the format of the exception file format please see the [UglifyJS docs](https: grunt.initConfig({ uglify: { options: { - mangleProperties: true, + mangle: { + properties: true + }, reserveDOMCache: true, exceptionsFiles: [ 'myExceptionsFile.json' ] }, diff --git a/docs/uglify-options.md b/docs/uglify-options.md index 48d4252a..d819a164 100644 --- a/docs/uglify-options.md +++ b/docs/uglify-options.md @@ -1,9 +1,25 @@ # Options -This task primarily delegates to [UglifyJS2][], so please consider the [UglifyJS documentation][] as required reading for advanced configuration. +This task primarily delegates to [UglifyJS](https://github.com/mishoo/UglifyJS2), so please consider their documentation as required reading for advanced configuration. -[UglifyJS2]: https://github.com/mishoo/UglifyJS2 -[UglifyJS documentation]: http://lisperator.net/uglifyjs/ + +#### Deprecated options from `2.x` + +Option | Replacement +----------------------- | ----------- +ASCIIOnly | output.ascii_only +enclose | — +exportAll | — +expression | parse.expression +indentLevel | output.indent_level +mangleProperties | mangle.properties +maxLineLen | output.max\_line_len +preserveComments | output.comments +quoteStyle | output.quote_style +screwIE8 | !ie8 +sourceMapIncludeSources | sourceMap.includeSources +sourceMapRoot | sourceMap.root +sourceMapUrl | sourceMap.url ## mangle @@ -22,9 +38,9 @@ Turn on or off source compression with default options. If an `Object` is specif Type: `Boolean` `Object` Default: `false` -Turns on beautification of the generated source code. An `Object` will be merged and passed with the options sent to `UglifyJS.OutputStream()`. [View all options here](https://github.com/mishoo/UglifyJS2#beautifier-options) +Turns on beautification of the generated source code. [View all options here](https://github.com/mishoo/UglifyJS2#beautifier-options) -#### expression +#### parse.expression Type: `Boolean` Default: `false` @@ -58,33 +74,26 @@ The location of an input source map from an earlier compilation, e.g. from Coffe uglify source is passed as the argument and the return value will be used as the sourceMap name. This only makes sense when there's one source file. -## sourceMapIncludeSources +## sourceMap.includeSources Type: `Boolean` Default: `false` Pass this flag if you want to include the content of source files in the source map as sourcesContent property. -#### sourceMapRoot +#### sourceMap.root Type: `String` Default: `undefined` With this option you can customize root URL that browser will use when looking for sources. -If the sources are not absolute URLs after prepending of the `sourceMapRoot`, the sources are resolved relative to the source map. +If the sources are not absolute URLs after prepending of the `sourceMap.root`, the sources are resolved relative to the source map. -## sourceMapUrl +## sourceMap.url Type: `String` Default: `undefined` Override the calculated value for `sourceMappingURL` in the source map. This is useful if the source map location is not relative to the base path of the minified file, i.e. when using a CDN -#### enclose -Type: `Object` -Default: `undefined` - -Wrap all of the code in a closure with a configurable arguments/parameters list. -Each key-value pair in the `enclose` object is effectively an argument-parameter pair. - ## wrap Type: `String` Default: `undefined` @@ -93,25 +102,13 @@ Wrap all of the code in a closure, an easy way to make sure nothing is leaking. For variables that need to be public `exports` and `global` variables are made available. The value of wrap is the global variable exports will be available as. -## maxLineLen -Type: `Number` -Default: `32000` - -Limit the line length in symbols. Pass maxLineLen = 0 to disable this safety feature. - -## ASCIIOnly +## output.ascii_only Type: `Boolean` Default: `false` Enables to encode non-ASCII characters as \uXXXX. -## exportAll -Type: `Boolean` -Default: `false` - -When using `wrap` this will make all global functions and variables available via the export variable. - -## preserveComments +## output.comments Type: `Boolean` `String` `Function` Default: `undefined` Options: `false` `'all'` `'some'` @@ -136,13 +133,13 @@ Default: `''` This string will be appended to the minified output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. -## screwIE8 +## ie8 Type: `Boolean` -Default: `true` +Default: `false` -Set this to `false` if you still care about full compliance with Internet Explorer 6-8 quirks. +Set this to `true` if you still care about full compliance with Internet Explorer 6-8 quirks. -## mangleProperties +## mangle.properties Type: `Boolean` `Object` Default: `false` @@ -152,13 +149,13 @@ Turn on or off property mangling with default options. If an `Object` is specifi Type: `Boolean` Default: `false` -Use this flag in conjunction with `mangleProperties` to prevent built-in browser object properties from being mangled. +Use this flag in conjunction with `mangle.properties` to prevent built-in browser object properties from being mangled. ## exceptionsFiles Type: `Array` Default: `[]` -Use this with `mangleProperties` to pass one or more JSON files containing a list of variables and object properties +Use this with `mangle.properties` to pass one or more JSON files containing a list of variables and object properties that should not be mangled. See the [UglifyJS docs](https://www.npmjs.com/package/uglify-js) for more info on the file syntax. ## nameCache @@ -168,7 +165,7 @@ Default: `''` A string that is a path to a JSON cache file that uglify will create and use to coordinate symbol mangling between multiple runs of uglify. Note: this generated file uses the same JSON format as the `exceptionsFiles` files. -## quoteStyle +## output.quote_style Type: `Integer` Default: `0` diff --git a/package.json b/package.json index a8c61dc4..1b292a4b 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,7 @@ "dependencies": { "chalk": "^1.0.0", "maxmin": "^1.1.0", - "object.assign": "^4.0.4", - "uglify-js": "~2.8.21", + "uglify-js": "~3.0.4", "uri-path": "^1.0.0" }, "devDependencies": { diff --git a/tasks/lib/uglify.js b/tasks/lib/uglify.js index 4923c2b6..17bf4bb0 100644 --- a/tasks/lib/uglify.js +++ b/tasks/lib/uglify.js @@ -2,7 +2,7 @@ * grunt-contrib-uglify * https://gruntjs.com/ * - * Copyright (c) 2016 "Cowboy" Ben Alman, contributors + * Copyright (c) 2017 "Cowboy" Ben Alman, contributors * Licensed under the MIT license. */ @@ -11,288 +11,147 @@ // External libs. var path = require('path'); var UglifyJS = require('uglify-js'); -var assign = require('object.assign'); var uriPath = require('uri-path'); -var getOutputOptions; // Converts \r\n to \n function normalizeLf(string) { return string.replace(/\r\n/g, '\n'); } +function toCache(cache, key) { + if (cache[key]) { + cache[key].props = UglifyJS.Dictionary.fromObject(cache[key].props); + } else { + cache[key] = { + cname: -1, + props: new UglifyJS.Dictionary() + }; + } + return cache[key]; +} + exports.init = function(grunt) { var exports = {}; // Minify with UglifyJS. // From https://github.com/mishoo/UglifyJS2 - // API docs at http://lisperator.net/uglifyjs/ exports.minify = function(files, dest, options) { options = options || {}; grunt.verbose.write('Minifying with UglifyJS...'); - var topLevel = null; var totalCode = ''; - var sourcesContent = {}; - - var outputOptions = getOutputOptions(options, dest); - var output = UglifyJS.OutputStream(outputOptions); - - // Grab and parse all source files - files.forEach(function(file) { - - var code = grunt.file.read(file); - totalCode += code; - - // The src file name must be relative to the source map for things to work - var basename = path.basename(file); - var fileDir = path.dirname(file); - var sourceMapDir = path.dirname(options.generatedSourceMapName); - var relativePath = path.relative(sourceMapDir, fileDir); - var pathPrefix = relativePath ? relativePath + path.sep : ''; - var bare_returns = options.bare_returns || undefined; - - // Convert paths to use forward slashes for sourcemap use in the browser - file = uriPath(pathPrefix + basename); - - sourcesContent[file] = code; - topLevel = UglifyJS.parse(code, { - filename: file, - toplevel: topLevel, - expression: options.expression, - bare_returns: bare_returns - }); - }); - - // Wrap code in a common js wrapper. - if (options.wrap) { - topLevel = topLevel.wrap_commonjs(options.wrap, options.exportAll); - } - - // Wrap code in closure with configurable arguments/parameters list. - if (options.enclose) { - var argParamList = Object.keys(options.enclose).map(function(key) { - return key + ':' + options.enclose[key]; - }); - - topLevel = topLevel.wrap_enclose(argParamList); - } - - var topLevelCache = null; - if (options.nameCache) { - topLevelCache = UglifyJS.readNameCache(options.nameCache, 'vars'); - } + var minifyOptions = { + compress: options.compress, + ie8: options.ie8, + keep_fnames: options.keep_fnames, + mangle: options.mangle, + output: options.output || {}, + parse: options.parse || {}, + sourceMap: options.sourceMap, + toplevel: options.topLevel, + wrap: options.wrap + }; - // Need to call this before we mangle or compress, - // and call after any compression or ast altering - if (options.expression === false) { - topLevel.figure_out_scope({ - screw_ie8: options.screwIE8, - cache: topLevelCache - }); + if (options.banner) { + minifyOptions.output.preamble = normalizeLf(options.banner); } - if (options.compress !== false) { - if (options.compress === true) { - options.compress = {}; - } - if (options.compress.warnings !== true) { - options.compress.warnings = false; - } - if (options.screwIE8 === false) { - options.compress.screw_ie8 = false; - } - var compressor = UglifyJS.Compressor(options.compress); - topLevel = compressor.compress(topLevel); - - // Need to figure out scope again after source being altered - if (options.expression === false) { - topLevel.figure_out_scope({ - screw_ie8: options.screwIE8, - cache: topLevelCache - }); + if (options.beautify) { + minifyOptions.output.beautify = true; + for (var key in options.beautify) { + minifyOptions.output[key] = options.beautify[key]; } } - var mangleExclusions = { - vars: [], - props: [] - }; - if (options.reserveDOMProperties) { - mangleExclusions = UglifyJS.readDefaultReservedFile(); - } - - if (options.exceptionsFiles) { + var cache; + if (options.nameCache) { try { - options.exceptionsFiles.forEach(function(filename) { - mangleExclusions = UglifyJS.readReservedFile(filename, mangleExclusions); - }); + cache = JSON.parse(grunt.file.read(options.nameCache)); } catch (ex) { - grunt.warn(ex); + cache = {}; } } - var cache = null; - if (options.nameCache) { - cache = UglifyJS.readNameCache(options.nameCache, 'props'); - } - - if (typeof options.mangleProperties !== 'undefined' && options.mangleProperties !== false) { - // if options.mangleProperties is a boolean (true) convert it into an object - if (typeof options.mangleProperties !== 'object') { - options.mangleProperties = {}; + if (minifyOptions.mangle) { + if (typeof minifyOptions.mangle !== 'object') { + minifyOptions.mangle = {}; } - - options.mangleProperties.reserved = mangleExclusions ? mangleExclusions.props : null; - options.mangleProperties.cache = cache; - - topLevel = UglifyJS.mangle_properties(topLevel, options.mangleProperties); - - if (options.nameCache) { - UglifyJS.writeNameCache(options.nameCache, 'props', cache); - } - - // Need to figure out scope again since topLevel has been altered - if (options.expression === false) { - topLevel.figure_out_scope({ - screw_ie8: options.screwIE8, - cache: topLevelCache - }); - } - } - - if (options.mangle !== false) { - if (options.mangle === true) { - options.mangle = {}; - } - if (options.screwIE8 === false) { - options.mangle.screw_ie8 = false; - } - // disabled due to: - // 1) preserve stable name mangling - // 2) it increases gzipped file size, see https://github.com/mishoo/UglifyJS2#mangler-options - // // compute_char_frequency optimizes names for compression - // topLevel.compute_char_frequency(options.mangle); - - // if options.mangle is a boolean (true) convert it into an object - if (typeof options.mangle !== 'object') { - options.mangle = {}; + if (cache) { + minifyOptions.mangle.cache = toCache(cache, 'vars'); } - - options.mangle.cache = topLevelCache; - - options.mangle.except = options.mangle.except ? options.mangle.except : []; - if (mangleExclusions.vars) { - mangleExclusions.vars.forEach(function(name) { - UglifyJS.push_uniq(options.mangle.except, name); - }); + if (!Array.isArray(minifyOptions.mangle.reserved)) { + minifyOptions.mangle.reserved = []; } - - // Requires previous call to figure_out_scope - // and should always be called after compressor transform - topLevel.mangle_names(options.mangle); - - UglifyJS.writeNameCache(options.nameCache, 'vars', options.mangle.cache); - } - - if (options.sourceMap && options.sourceMapIncludeSources) { - for (var file in sourcesContent) { - if (sourcesContent.hasOwnProperty(file)) { - outputOptions.source_map.get().setSourceContent(file, sourcesContent[file]); + if (minifyOptions.mangle.properties) { + if (typeof minifyOptions.mangle.properties !== 'object') { + minifyOptions.mangle.properties = {}; + } + if (cache) { + minifyOptions.mangle.properties.cache = toCache(cache, 'props'); + } + if (!Array.isArray(minifyOptions.mangle.properties.reserved)) { + minifyOptions.mangle.properties.reserved = []; + } + if (options.reserveDOMProperties) { + require('uglify-js/tools/domprops').forEach(function(name) { + UglifyJS._push_uniq(minifyOptions.mangle.properties.reserved, name); + }); } } - } - - // Print the ast to OutputStream - topLevel.print(output); - - var min = output.get(); - - // Add the source map reference to the end of the file - if (options.sourceMap) { - // Set all paths to forward slashes for use in the browser - var sourceMappingURL; - sourceMappingURL = options.destToSourceMap.match(/^http[s]?:\/\//) === null ? uriPath(options.destToSourceMap) : options.destToSourceMap; - min += '\n//# sourceMappingURL=' + sourceMappingURL; - } - - var result = { - max: totalCode, - min: min, - sourceMap: outputOptions.source_map - }; - - grunt.verbose.ok(); - - return result; - }; - - getOutputOptions = function(options, dest) { - var outputOptions = { - beautify: false, - source_map: null - }; - - if (options.banner) { - outputOptions.preamble = normalizeLf(options.banner); - } - - if (options.screwIE8 === false) { - outputOptions.screw_ie8 = false; - } - - if (options.sourceMap) { - - var destBasename = path.basename(dest); - var sourceMapIn; - if (options.sourceMapIn) { - sourceMapIn = grunt.file.readJSON(options.sourceMapIn); - } - outputOptions.source_map = UglifyJS.SourceMap({ - file: destBasename, - root: options.sourceMapRoot, - orig: sourceMapIn - }); - if (options.sourceMapIncludeSources && sourceMapIn && sourceMapIn.sourcesContent) { - sourceMapIn.sourcesContent.forEach(function(content, idx) { - outputOptions.source_map.get().setSourceContent(sourceMapIn.sources[idx], content); + if (options.exceptionsFiles) { + options.exceptionsFiles.forEach(function(file) { + try { + var obj = JSON.parse(grunt.file.read(file)); + if (minifyOptions.mangle && obj.vars) { + obj.vars.forEach(function(name) { + UglifyJS._push_uniq(minifyOptions.mangle.reserved, name); + }); + } + if (minifyOptions.mangle.properties && obj.props) { + obj.props.forEach(function(name) { + UglifyJS._push_uniq(minifyOptions.mangle.properties.reserved, name); + }); + } + } catch (ex) { + grunt.warn(ex); + } }); } - - if (options.sourceMapIn) { - outputOptions.source_map.get()._file = destBasename; - } } - if (typeof options.indentLevel !== 'undefined') { - outputOptions.indent_level = options.indentLevel; - } - - if (typeof options.maxLineLen !== 'undefined') { - outputOptions.max_line_len = options.maxLineLen; - } + var result = UglifyJS.minify(files.reduce(function(o, file) { + var code = grunt.file.read(file); + totalCode += code; - if (typeof options.ASCIIOnly !== 'undefined') { - outputOptions.ascii_only = options.ASCIIOnly; - } + // The src file name must be relative to the source map for things to work + var basename = path.basename(file); + var fileDir = path.dirname(file); + var sourceMapDir = path.dirname(options.generatedSourceMapName); + var relativePath = path.relative(sourceMapDir, fileDir); + var pathPrefix = relativePath ? relativePath + path.sep : ''; - if (typeof options.quoteStyle !== 'undefined') { - outputOptions.quote_style = options.quoteStyle; + // Convert paths to use forward slashes for sourcemap use in the browser + o[uriPath(pathPrefix + basename)] = code; + return o; + }, {}), minifyOptions); + if (result.error) { + throw result.error; } - if (typeof options.preserveComments !== 'undefined') { - outputOptions.comments = options.preserveComments; + if (options.nameCache) { + grunt.file.write(options.nameCache, JSON.stringify(cache, function(key, value) { + return value instanceof UglifyJS.Dictionary ? value.toObject() : value; + })); } - if (options.beautify) { - if (typeof options.beautify === 'object') { - assign(outputOptions, options.beautify); - } else { - outputOptions.beautify = true; - } - } + grunt.verbose.ok(); - return outputOptions; + return { + max: totalCode, + min: result.code, + sourceMap: result.map + }; }; return exports; diff --git a/tasks/uglify.js b/tasks/uglify.js index 0e502067..dd02fbc4 100644 --- a/tasks/uglify.js +++ b/tasks/uglify.js @@ -11,6 +11,7 @@ var path = require('path'); var chalk = require('chalk'); var maxmin = require('maxmin'); +var uriPath = require('uri-path'); var err; // Return the relative path from file1 => file2 @@ -19,7 +20,7 @@ function relativePath(file1, file2) { var file2Dirname = path.dirname(file2); if (file1Dirname !== file2Dirname) { - return path.relative(file1Dirname, file2Dirname) + path.sep; + return path.relative(file1Dirname, file2Dirname); } return ''; } @@ -48,17 +49,11 @@ module.exports = function(grunt) { var options = this.options({ banner: '', footer: '', - compress: { - warnings: false - }, + compress: {}, mangle: {}, beautify: false, report: 'min', - expression: false, - maxLineLen: 32000, - ASCIIOnly: false, - screwIE8: true, - quoteStyle: 0 + ie8: false }); var footer = normalizeLf(options.footer); @@ -71,6 +66,13 @@ module.exports = function(grunt) { before: 0, after: 0 }; + var generateSourceMapURL = options.sourceMap && !options.sourceMap.url; + var generateSourceMapFilename = options.sourceMap && !options.sourceMap.filename; + + // function to get the name of the sourceMap + if (typeof options.sourceMapName === 'function') { + mapNameGenerator = options.sourceMapName; + } // Iterate over all src-dest file pairs. this.files.forEach(function (f) { @@ -81,18 +83,6 @@ module.exports = function(grunt) { return; } - // Warn on incompatible options - if (options.expression && (options.compress || options.mangle)) { - grunt.log.warn('Option ' + chalk.cyan('expression') + ' not compatible with ' + chalk.cyan('compress and mangle')); - options.compress = false; - options.mangle = false; - } - - // function to get the name of the sourceMap - if (typeof options.sourceMapName === 'function') { - mapNameGenerator = options.sourceMapName; - } - // function to get the name of the sourceMapIn file if (typeof options.sourceMapIn === 'function') { if (availableFiles.length !== 1) { @@ -128,17 +118,21 @@ module.exports = function(grunt) { } } - // Calculate the path from the dest file to the sourcemap for the - // sourceMappingURL reference - // If sourceMapUrl is defined, use this instead - if (options.sourceMap) { - var destToSourceMapPath, sourceMapBasename; - if (!options.sourceMapUrl) { - destToSourceMapPath = relativePath(f.dest, options.generatedSourceMapName); - sourceMapBasename = path.basename(options.generatedSourceMapName); - options.destToSourceMap = destToSourceMapPath + sourceMapBasename; - } else { - options.destToSourceMap = options.sourceMapUrl; + if (options.sourceMap && generateSourceMapURL) { + if (typeof options.sourceMap !== 'object') { + options.sourceMap = {}; + } + if (generateSourceMapFilename) { + options.sourceMap.filename = path.basename(f.dest); + } + if (options.sourceMapIn) { + options.sourceMap.content = grunt.file.read(options.sourceMapIn); + } + // Calculate the path from the dest file to the sourcemap for sourceMap.url + if (generateSourceMapURL) { + var destToSourceMapPath = relativePath(f.dest, options.generatedSourceMapName); + var sourceMapBasename = path.basename(options.generatedSourceMapName); + options.sourceMap.url = uriPath(path.join(destToSourceMapPath, sourceMapBasename)); } } diff --git a/test/fixtures/expected/beautify.js b/test/fixtures/expected/beautify.js index 786298ad..79048f65 100644 --- a/test/fixtures/expected/beautify.js +++ b/test/fixtures/expected/beautify.js @@ -1,3 +1,5 @@ -function longFunctionC(a,b){ -return longNameA+longNameB+a+b} -var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file + function longFunctionC(n, o) { + return longNameA + longNameB + n + o; + } + + var longNameA = 1, longNameB = 2, result = longFunctionC(3, 4); \ No newline at end of file diff --git a/test/fixtures/expected/compress_explicit.js b/test/fixtures/expected/compress_explicit.js index c66c512d..51750421 100644 --- a/test/fixtures/expected/compress_explicit.js +++ b/test/fixtures/expected/compress_explicit.js @@ -1 +1 @@ -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/fixtures/expected/compress_mangle.js b/test/fixtures/expected/compress_mangle.js index c66c512d..51750421 100644 --- a/test/fixtures/expected/compress_mangle.js +++ b/test/fixtures/expected/compress_mangle.js @@ -1 +1 @@ -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/fixtures/expected/compress_mangle_banner.js b/test/fixtures/expected/compress_mangle_banner.js index fee07369..5864a1d8 100644 --- a/test/fixtures/expected/compress_mangle_banner.js +++ b/test/fixtures/expected/compress_mangle_banner.js @@ -1,3 +1,3 @@ // banner without sourcemap -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/fixtures/expected/compress_mangle_beautify.js b/test/fixtures/expected/compress_mangle_beautify.js index 15b03f05..0375fd46 100644 --- a/test/fixtures/expected/compress_mangle_beautify.js +++ b/test/fixtures/expected/compress_mangle_beautify.js @@ -1,5 +1,5 @@ -function longFunctionC(a, b) { - return longNameA + longNameB + a + b; +function longFunctionC(n, o) { + return longNameA + longNameB + n + o; } var longNameA = 1, longNameB = 2, result = longFunctionC(3, 4); diff --git a/test/fixtures/expected/compress_mangle_except.js b/test/fixtures/expected/compress_mangle_except.js index 6830da93..c0bb99e7 100644 --- a/test/fixtures/expected/compress_mangle_except.js +++ b/test/fixtures/expected/compress_mangle_except.js @@ -1 +1 @@ -function longFunctionC(argumentC,a){return longNameA+longNameB+argumentC+a}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file +function longFunctionC(argumentC,n){return longNameA+longNameB+argumentC+n}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/fixtures/expected/enclose.js b/test/fixtures/expected/enclose.js deleted file mode 100644 index 85dbcf82..00000000 --- a/test/fixtures/expected/enclose.js +++ /dev/null @@ -1,8 +0,0 @@ -(function(paramA, paramB) { - var longNameA = 1; - var longNameB = 2; - function longFunctionC(argumentC, argumentD) { - return longNameA + longNameB + argumentC + argumentD; - } - var result = longFunctionC(3, 4); -})(window.argA, window.argB); \ No newline at end of file diff --git a/test/fixtures/expected/exportAll.js b/test/fixtures/expected/exportAll.js deleted file mode 100644 index 604faa1e..00000000 --- a/test/fixtures/expected/exportAll.js +++ /dev/null @@ -1 +0,0 @@ -!function(exports,global){function longFunctionC(argumentC,argumentD){return longNameA+longNameB+argumentC+argumentD}var longNameA=1,longNameB=2,result=longFunctionC(3,4);exports.longNameA=longNameA,exports.longNameB=longNameB,exports.longFunctionC=longFunctionC,exports.result=result,global.testExport=exports}({},function(){return this}()); \ No newline at end of file diff --git a/test/fixtures/expected/mangle.js b/test/fixtures/expected/mangle.js index c66c512d..51750421 100644 --- a/test/fixtures/expected/mangle.js +++ b/test/fixtures/expected/mangle.js @@ -1 +1 @@ -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops.js b/test/fixtures/expected/mangleprops.js index 19e7eb95..c9da02f2 100644 --- a/test/fixtures/expected/mangleprops.js +++ b/test/fixtures/expected/mangleprops.js @@ -1 +1 @@ -var myObj={a:function(a){a++},b:function(){},c:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file +var myObj={n:function(n){n++},e:function(){},o:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops_withExcept.js b/test/fixtures/expected/mangleprops_withExcept.js index 11187262..a4692b73 100644 --- a/test/fixtures/expected/mangleprops_withExcept.js +++ b/test/fixtures/expected/mangleprops_withExcept.js @@ -1 +1 @@ -var myObj={a:function(dontMangleMeVariable){dontMangleMeVariable++},b:function(){},c:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file +var myObj={n:function(dontMangleMeVariable){dontMangleMeVariable++},e:function(){},o:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops_withExceptAndExceptionsFiles.js b/test/fixtures/expected/mangleprops_withExceptAndExceptionsFiles.js index 334f4a50..8eed85c7 100644 --- a/test/fixtures/expected/mangleprops_withExceptAndExceptionsFiles.js +++ b/test/fixtures/expected/mangleprops_withExceptAndExceptionsFiles.js @@ -1 +1 @@ -var a={a:function(dontMangleMeVariable){dontMangleMeVariable++},dontMangleMeProperty:function(){},b:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file +var n={n:function(dontMangleMeVariable){dontMangleMeVariable++},dontMangleMeProperty:function(){},o:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops_withExceptionsFiles.js b/test/fixtures/expected/mangleprops_withExceptionsFiles.js index c7ec6d02..94939011 100644 --- a/test/fixtures/expected/mangleprops_withExceptionsFiles.js +++ b/test/fixtures/expected/mangleprops_withExceptionsFiles.js @@ -1 +1 @@ -var a={a:function(a){a++},dontMangleMeProperty:function(){},b:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file +var n={n:function(n){n++},dontMangleMeProperty:function(){},o:function(){}},dontMangleMeVariable2=function(){},dontMangleMeVariable3=function(){}; \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops_withNameCacheFile1.js b/test/fixtures/expected/mangleprops_withNameCacheFile1.js index 4205c8e8..e00ff6e1 100644 --- a/test/fixtures/expected/mangleprops_withNameCacheFile1.js +++ b/test/fixtures/expected/mangleprops_withNameCacheFile1.js @@ -1 +1 @@ -var a={a:function(a){a++},b:function(){},c:function(){}},b=function(){},c=function(){}; \ No newline at end of file +var n={n:function(n){n++},o:function(){},t:function(){}},o=function(){},t=function(){}; \ No newline at end of file diff --git a/test/fixtures/expected/mangleprops_withNameCacheFile2.js b/test/fixtures/expected/mangleprops_withNameCacheFile2.js index 92a68ba9..d4e5147f 100644 --- a/test/fixtures/expected/mangleprops_withNameCacheFile2.js +++ b/test/fixtures/expected/mangleprops_withNameCacheFile2.js @@ -1 +1 @@ -var d=10;a.a(d); \ No newline at end of file +var a=10;n.n(a); \ No newline at end of file diff --git a/test/fixtures/expected/maxLineLen.js b/test/fixtures/expected/maxLineLen.js index 757c532e..20c1739f 100644 --- a/test/fixtures/expected/maxLineLen.js +++ b/test/fixtures/expected/maxLineLen.js @@ -1,5 +1,5 @@ -(function(){var list,math,opposite,square;opposite=!0,square=function(x){return x*x}, -list=[1,2,3,4,5],math={root:Math.sqrt,square:square,cube:function(x){return x*square(x)}}, -"undefined"!=typeof elvis&&null!=elvis&&alert("I knew it!"),function(accum$){ +(function(){var list,math,square;square=function(x){return x*x},list=[1,2,3,4,5],math={ +root:Math.sqrt,square:square,cube:function(x){return x*square(x)} +},"undefined"!=typeof elvis&&null!=elvis&&alert("I knew it!"),function(accum$){ for(var num,i$=0,length$=list.length;i$ x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)"]} \ No newline at end of file +{"version":3,"sources":["../test/fixtures/src/simple2.coffee"],"names":["square","x","list","math","root","Math","sqrt","cube","elvis","alert","accum$","i$","length$","length","num"],"mappings":";;gCAQCA,QAAS,SAAAC,SAAOA,GAAIA,GAGpBC,MAAQ,EAAG,EAAG,EAAG,EAAG,GAGpBC,MACGC,KAAQC,KAAIC,KACbN,OAAQA,OACRO,KAAQ,SAAAN,SAAOA,GAAID,OAAOC,KAO1B,mBAAsBO,QAAA,MAAAA,OAAtBC,MAAM,cAGR,SAAAC,QAAS,IAAA,QAAAC,GAAA,EAAAC,QAAyBV,KAAAW,OAAzBF,GAAAC,UAAAD,GAAkBG,IAAOZ,KAAAS,gBAAzBR,KAAII,KAAMO","file":"sourcemapin.js","sourcesContent":["# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)"]} \ No newline at end of file diff --git a/test/fixtures/expected/sourcemapin_sources.js b/test/fixtures/expected/sourcemapin_sources.js index 44a03400..707c18fe 100644 --- a/test/fixtures/expected/sourcemapin_sources.js +++ b/test/fixtures/expected/sourcemapin_sources.js @@ -1,2 +1,2 @@ -(function(){var a,b,c,d;c=!0,d=function(a){return a*a},a=[1,2,3,4,5],b={root:Math.sqrt,square:d,cube:function(a){return a*d(a)}},"undefined"!=typeof elvis&&null!=elvis&&alert("I knew it!"),function(c){for(var d,e=0,f=a.length;e x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)"]} \ No newline at end of file +{"version":3,"sources":["../test/fixtures/src/simple2.coffee"],"names":["square","x","list","math","root","Math","sqrt","cube","elvis","alert","accum$","i$","length$","length","num"],"mappings":"qBAQCA,GAAS,SAAAC,SAAOA,GAAIA,GAGpBC,GAAQ,EAAG,EAAG,EAAG,EAAG,GAGpBC,GACGC,KAAQC,KAAIC,KACbN,OAAQA,EACRO,KAAQ,SAAAN,SAAOA,GAAID,EAAOC,KAO1B,mBAAsBO,QAAA,MAAAA,OAAtBC,MAAM,cAGR,SAAAC,GAAS,IAAA,MAAAC,EAAA,EAAAC,EAAyBV,EAAAW,OAAzBF,EAAAC,IAAAD,EAAkBG,EAAOZ,EAAAS,UAAzBR,EAAII,KAAMO","file":"sourcemapin_sources.js","sourcesContent":["# Assignment:\nnumber = 42\nopposite = true\n\n# Conditions:\nnumber = -42 if opposite\n\n# Functions:\nsquare = (x) -> x * x\n\n# Arrays:\nlist = [1, 2, 3, 4, 5]\n\n# Objects:\nmath =\n root: Math.sqrt\n square: square\n cube: (x) -> x * square x\n\n# Splats:\nrace = (winner, runners...) ->\n print winner, runners\n\n# Existence:\nalert \"I knew it!\" if elvis?\n\n# Array comprehensions:\ncubes = (math.cube num for num in list)"]} \ No newline at end of file diff --git a/test/fixtures/expected/sourcemaps_multiple1.js b/test/fixtures/expected/sourcemaps_multiple1.js index 69953e78..cde46a4e 100644 --- a/test/fixtures/expected/sourcemaps_multiple1.js +++ b/test/fixtures/expected/sourcemaps_multiple1.js @@ -1,2 +1,2 @@ -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); //# sourceMappingURL=sourcemaps_multiple1.js.map \ No newline at end of file diff --git a/test/fixtures/expected/sourcemaps_multiple1_fnName.js b/test/fixtures/expected/sourcemaps_multiple1_fnName.js index 4e0e3f93..a75f03b1 100644 --- a/test/fixtures/expected/sourcemaps_multiple1_fnName.js +++ b/test/fixtures/expected/sourcemaps_multiple1_fnName.js @@ -1,2 +1,2 @@ -function longFunctionC(a,b){return longNameA+longNameB+a+b}var longNameA=1,longNameB=2,result=longFunctionC(3,4); +function longFunctionC(n,o){return longNameA+longNameB+n+o}var longNameA=1,longNameB=2,result=longFunctionC(3,4); //# sourceMappingURL=sourcemaps_multiple1_fnName.js.fn.map \ No newline at end of file diff --git a/test/fixtures/expected/uglify_name_cache.json b/test/fixtures/expected/uglify_name_cache.json index 3c40b56a..8f1ad583 100644 --- a/test/fixtures/expected/uglify_name_cache.json +++ b/test/fixtures/expected/uglify_name_cache.json @@ -1,19 +1 @@ -{ - "props": { - "cname": 2, - "props": { - "$myFunction": "a", - "$dontMangleMeProperty": "b", - "$dontMangleMeProperty2": "c" - } - }, - "vars": { - "cname": 3, - "props": { - "$myObj": "a", - "$dontMangleMeVariable2": "b", - "$dontMangleMeVariable3": "c", - "$myNumber": "d" - } - } -} \ No newline at end of file +{"vars":{"cname":3,"props":{"$myObj":"n","$dontMangleMeVariable2":"o","$dontMangleMeVariable3":"t","$myNumber":"a"}},"props":{"cname":2,"props":{"$myFunction":"n","$dontMangleMeProperty":"o","$dontMangleMeProperty2":"t"}}} \ No newline at end of file diff --git a/test/fixtures/expected/wrap.js b/test/fixtures/expected/wrap.js index 228e9e5a..dc8e698a 100644 --- a/test/fixtures/expected/wrap.js +++ b/test/fixtures/expected/wrap.js @@ -1 +1 @@ -!function(exports,global){var longNameA=1,longNameB=2;global.testExport=exports}({},function(){return this}()); \ No newline at end of file +!function(exports){var longNameA=1,longNameB=2}("undefined"==typeof testExport?testExport={}:testExport); \ No newline at end of file diff --git a/test/uglify_test.js b/test/uglify_test.js index 63c1f5c1..517090f2 100644 --- a/test/uglify_test.js +++ b/test/uglify_test.js @@ -21,20 +21,20 @@ exports.contrib_uglify = { 'compress_mangle_banner.js', 'compress_mangle_beautify.js', 'compress_mangle_except.js', - 'enclose.js', 'multifile.js', 'wrap.js', 'maxLineLen.js', 'asciionly.js', - 'exportAll.js', 'screwIE8.js', 'sourcemap_basic.js', 'sourcemap_basic.js.map', 'sourcemap_customDir.js', 'sourcemap_customName.js', + 'source_map_custom_name', 'sourcemap_customRoot.js', 'sourcemap_customRoot.js.map', 'sourcemap_customUrl.js', + 'sourcemap_customUrl.js.map', 'sourcemap_functionName.js', 'sourcemap_functionName.js.fn.map', path.join('deep', 'directory', 'location', 'source_map.js.map'),