From 0e1b33ddab46b481de698a19e65a3a84f39f66dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Mon, 13 Apr 2020 21:59:04 +0200 Subject: [PATCH] update(uglfy-js): Minor updates and version bump (#43868) - bump to version 3.9 - correct options for Minify compress options as it accepts only false or configuration object as per JSDoc comment - add JSDoc comments for Minify options - minor addition to the tests - remove TS version header line as no longer valid (current defaults to TS 2.8 or newer) https://github.com/mishoo/UglifyJS2/releases/tag/v3.9.0 Thanks! --- types/uglify-js/index.d.ts | 63 +++++++++++++++++++++++++++--- types/uglify-js/uglify-js-tests.ts | 25 ++++++++---- 2 files changed, 74 insertions(+), 14 deletions(-) diff --git a/types/uglify-js/index.d.ts b/types/uglify-js/index.d.ts index 082a9ab20a..863d07ba79 100644 --- a/types/uglify-js/index.d.ts +++ b/types/uglify-js/index.d.ts @@ -1,18 +1,24 @@ -// Type definitions for UglifyJS 3.0 +// Type definitions for UglifyJS 3.9 // Project: https://github.com/mishoo/UglifyJS2 // Definitions by: Alan Agius // Tanguy Krotoff // John Reilly // Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 import { RawSourceMap } from 'source-map'; export interface ParseOptions { - /** Support top level `return` statements */ + /** + * Support top level `return` statements + * @default false + */ bare_returns?: boolean; + /** @default true */ html5_comments?: boolean; - /** Support `#!command` as the first line */ + /** + * Support `#!command` as the first line + * @default true + */ shebang?: boolean; } @@ -352,16 +358,61 @@ export enum OutputQuoteStyle { } export interface MinifyOptions { - /** Pass true to return compressor warnings in result.warnings. Use the value `verbose` for more detailed warnings. */ + /** + * Pass `true` to return compressor warnings in result.warnings. + * Use the value `verbose` for more detailed warnings. + * @default false + */ warnings?: boolean | 'verbose'; + /** + * Pass an object if you wish to specify some additional parse options. + */ parse?: ParseOptions; - compress?: boolean | CompressOptions; + /** + * Pass `false` to skip compressing entirely. + * Pass an object to specify custom compress options. + * @default {} + */ + compress?: false | CompressOptions; + /** + * Pass `false` to skip mangling names, + * or pass an object to specify mangle options (see below). + * @default true + */ mangle?: boolean | MangleOptions; + /** + * Pass an object if you wish to specify additional output options. + * The defaults are optimized for best compression + */ output?: OutputOptions; + /** + * Pass an object if you wish to specify source map options. + * @default false + */ sourceMap?: boolean | SourceMapOptions; + /** + * Set to `true` if you wish to enable top level variable and function name mangling + * and to drop unused variables and functions. + * @default false + */ toplevel?: boolean; + /** + * Pass an empty object {} or a previously used nameCache object + * if you wish to cache mangled variable and property names across multiple invocations of minify(). + * Note: this is a read/write property. `minify()` will read the name cache state of this object + * and update it during minification so that it may be reused or externally persisted by the user + */ nameCache?: object; + /** + * Set to true to support IE8 + * @default false + */ ie8?: boolean; + /** + * Pass true to prevent discarding or mangling of function names. + * Useful for code relying on Function.prototype.name. + * @default false + */ keep_fnames?: boolean; } diff --git a/types/uglify-js/uglify-js-tests.ts b/types/uglify-js/uglify-js-tests.ts index 8dbd8f8cf4..160d9c68de 100644 --- a/types/uglify-js/uglify-js-tests.ts +++ b/types/uglify-js/uglify-js-tests.ts @@ -5,19 +5,22 @@ import { OutputQuoteStyle, minify } from 'uglify-js'; let code: any; code = { - "file1.js": "function add(first, second) { return first + second; }", - "file2.js": "console.log(add(1 + 2, 3 + 4));" + 'file1.js': 'function add(first, second) { return first + second; }', + 'file2.js': 'console.log(add(1 + 2, 3 + 4));', }; minify(code); code = "function add(first, second) { return first + second; }"; -minify(code); +minify(code, { toplevel: true }); minify(code, { + warnings: true, output: { - quote_style: OutputQuoteStyle.AlwaysDouble - } + beautify: true, + preamble: '/* uglified */', + quote_style: OutputQuoteStyle.AlwaysDouble, + }, }); const output = minify(code, { @@ -25,14 +28,20 @@ const output = minify(code, { mangle: { properties: { regex: /reg/ - } + }, + toplevel: true, }, sourceMap: { filename: 'foo.map' }, compress: { - arguments: true - } + arguments: true, + global_defs: { + "@console.log": "alert" + }, + passes: 2, + }, + nameCache: {}, }); const compressOptions = {