2015-01-11 20:07:19 +00:00
arrow _function _parens : {
input : {
something && ( ( ) => { } ) ;
}
expect _exact : "something&&(()=>{});"
}
arrow _function _parens _2 : {
input : {
( ( ) => null ) ( ) ;
}
expect _exact : "(()=>null)();"
}
2015-08-14 21:05:42 +00:00
typeof _arrow _functions : {
options = {
2017-12-03 04:14:31 +00:00
evaluate : true ,
typeofs : true ,
2015-08-14 21:05:42 +00:00
}
input : {
2017-06-23 21:26:35 +00:00
var foo = typeof ( x => null ) ;
console . log ( foo ) ;
2015-08-14 21:05:42 +00:00
}
2017-06-23 21:26:35 +00:00
expect _exact : "var foo=\"function\";console.log(foo);"
expect _stdout : "function"
node _version : ">=4"
2015-08-14 21:05:42 +00:00
}
2015-10-27 00:40:46 +00:00
classes : {
input : {
class SomeClass {
constructor ( ) {
} ;
foo ( ) { } ;
} ;
class NoSemi {
constructor ( ... args ) {
}
foo ( ) { }
} ;
class ChildClass extends SomeClass { } ;
var asExpression = class AsExpression { } ;
var nameless = class { } ;
}
expect _exact : "class SomeClass{constructor(){}foo(){}}class NoSemi{constructor(...args){}foo(){}}class ChildClass extends SomeClass{}var asExpression=class AsExpression{};var nameless=class{};"
}
2015-10-27 00:51:47 +00:00
class _statics : {
input : {
x = class {
static staticMethod ( ) { }
static get foo ( ) { }
static set bar ( ) { }
static ( ) { /* "static" can be a method name! */ }
get ( ) { /* "get" can be a method name! */ }
set ( ) { /* "set" can be a method name! */ }
}
}
expect _exact : "x=class{static staticMethod(){}static get foo(){}static set bar(){}static(){}get(){}set(){}};"
}
2015-11-21 12:20:20 +00:00
class _name _can _be _mangled : {
mangle = { } ;
input : {
function x ( ) {
class Foo {
}
2017-06-25 08:02:46 +00:00
var class1 = Foo ;
var class2 = class Bar { } ;
2015-11-21 12:20:20 +00:00
}
}
expect : {
function x ( ) {
class a { }
2017-06-25 08:02:46 +00:00
var s = a ;
var c = class a { } ;
2015-11-21 12:20:20 +00:00
}
}
}
2015-11-21 13:59:18 +00:00
class _name _can _be _preserved : {
mangle = {
keep _classnames : true
}
input : {
function x ( ) {
( class Baz { } ) ;
class Foo { } ;
}
}
expect : {
function x ( ) {
( class Baz { } ) ;
class Foo { } ;
}
}
}
2016-05-26 15:00:37 +00:00
classes _can _have _generators : {
input : {
class Foo {
* bar ( ) { }
static * baz ( ) { }
}
}
expect : {
class Foo {
* bar ( ) { }
static * baz ( ) { }
}
}
}
2016-07-05 22:40:28 +00:00
classes _can _have _computed _generators : {
input : {
class C4 {
* [ 'constructor' ] ( ) { }
}
}
expect : {
class C4 {
* [ 'constructor' ] ( ) { }
}
}
}
classes _can _have _computed _static : {
input : {
class C4 {
static [ 'constructor' ] ( ) { }
}
}
expect : {
class C4 {
static [ 'constructor' ] ( ) { }
}
}
}
2016-07-29 01:18:21 +00:00
class _methods _and _getters _with _keep _quoted _props _enabled : {
beautify = {
quote _style : 3 ,
keep _quoted _props : true ,
}
input : {
class clss {
a ( ) { }
"b" ( ) { }
get c ( ) { return "c" }
get "d" ( ) { return "d" }
set e ( a ) { doSomething ( a ) ; }
set 'f' ( a ) { doSomething ( b ) ; }
static g ( ) { }
static "h" ( ) { }
}
}
expect _exact : 'class clss{a(){}"b"(){}get c(){return"c"}get"d"(){return"d"}set e(a){doSomething(a)}set\'f\'(a){doSomething(b)}static g(){}static"h"(){}}'
}
2017-04-04 04:38:13 +00:00
classes _with _expression _as _expand : {
input : {
class D extends ( calls ++ , C ) { }
}
expect _exact : "class D extends(calls++,C){}"
}
2015-11-21 14:48:23 +00:00
new _target : {
input : {
new . target ;
new . target . name ;
}
expect _exact : "new.target;new.target.name;"
}
2015-08-17 15:23:43 +00:00
number _literals : {
2015-08-17 10:50:56 +00:00
input : {
0b1001 ;
0B1001 ;
0o11 ;
0O11 ;
}
expect : {
9 ;
9 ;
9 ;
9 ;
}
}
2015-09-05 22:01:25 +00:00
2016-01-29 20:47:49 +00:00
import _statement : {
input : {
import "mod-name" ;
2016-02-21 17:06:09 +00:00
import Foo from "bar" ;
2016-02-26 21:12:19 +00:00
import { Bar , Baz } from 'lel' ;
import Bar , { Foo } from 'lel' ;
import { Bar as kex , Baz as food } from 'lel' ;
2016-02-21 17:06:09 +00:00
}
2017-03-31 09:52:56 +00:00
expect _exact : 'import"mod-name";import Foo from"bar";import{Bar,Baz}from"lel";import Bar,{Foo}from"lel";import{Bar as kex,Baz as food}from"lel";'
}
import _all _statement : {
input : {
import * from 'lel' ;
import * as Lel from 'lel' ;
}
expect _exact : 'import*from"lel";import*as Lel from"lel";'
2016-02-21 17:06:09 +00:00
}
2016-02-27 12:24:18 +00:00
export _statement : {
2017-05-13 04:56:46 +00:00
options = {
evaluate : true ,
}
2016-02-27 12:24:18 +00:00
input : {
2017-05-13 04:56:46 +00:00
export default 1 + 2 ;
2017-08-14 04:31:12 +00:00
export var a = 4 ;
export let b = 6 ;
export const c = 6 ;
export function d ( ) { } ;
export class e { } ;
2016-02-27 12:24:18 +00:00
}
2017-08-14 04:31:12 +00:00
expect _exact : "export default 3;export var a=4;export let b=6;export const c=6;export function d(){};export class e{};"
2017-05-13 04:56:46 +00:00
}
export _default _object _expression : {
options = {
evaluate : true ,
}
input : {
export default {
foo : 1 + 2 ,
bar ( ) { return 4 ; } ,
get baz ( ) { return this . foo ; } ,
} ;
}
expect _exact : "export default{foo:3,bar(){return 4},get baz(){return this.foo}};"
}
export _default _array : {
options = {
evaluate : true ,
}
input : {
export default [ 1 + 2 , foo ] ;
}
expect _exact : "export default[3,foo];"
2016-02-27 12:24:18 +00:00
}
2017-05-16 19:28:24 +00:00
export _default _anon _function : {
options = {
evaluate : true ,
}
input : {
export default function ( ) {
console . log ( 1 + 2 ) ;
}
}
expect _exact : "export default function(){console.log(3)};"
}
export _default _anon _class : {
options = {
evaluate : true ,
}
input : {
export default class {
foo ( ) { console . log ( 1 + 2 ) ; }
}
}
expect _exact : "export default class{foo(){console.log(3)}};"
}
2017-03-30 09:07:50 +00:00
export _module _statement : {
input : {
export * from "a.js" ;
export { A } from "a.js" ;
export { A , B } from "a.js" ;
2017-03-31 09:51:27 +00:00
export { C } ;
2017-03-30 09:07:50 +00:00
}
2017-03-31 09:51:27 +00:00
expect _exact : 'export*from"a.js";export{A}from"a.js";export{A,B}from"a.js";export{C};'
2017-03-30 09:07:50 +00:00
}
2016-02-21 17:06:09 +00:00
import _statement _mangling : {
2017-02-27 03:39:48 +00:00
mangle = { toplevel : true } ;
2016-02-21 17:06:09 +00:00
input : {
import Foo from "foo" ;
2016-02-27 12:01:16 +00:00
import Bar , { Food } from "lel" ;
import { What as Whatever } from "lel" ;
2016-02-21 17:06:09 +00:00
Foo ( ) ;
2016-02-27 12:01:16 +00:00
Bar ( ) ;
Food ( ) ;
Whatever ( ) ;
2016-02-21 17:06:09 +00:00
}
expect : {
2017-06-25 08:02:46 +00:00
import o from "foo" ;
import m , { Food as r } from "lel" ;
2016-04-18 13:51:32 +00:00
import { What as f } from "lel" ;
o ( ) ;
2017-06-25 08:02:46 +00:00
m ( ) ;
r ( ) ;
2016-04-18 13:51:32 +00:00
f ( ) ;
2016-01-29 20:47:49 +00:00
}
}
2016-02-27 12:40:57 +00:00
export _statement _mangling : {
mangle = { } ;
input : {
export var foo = 6 ;
export function bar ( ) { }
export class Baz { }
bar ( foo , Baz )
}
expect : {
export var foo = 6 ;
export function bar ( ) { }
export class Baz { }
bar ( foo , Baz )
}
}
2016-03-27 11:21:39 +00:00
// https://github.com/mishoo/UglifyJS2/issues/1021
regression _for _of _const : {
input : {
for ( const x of y ) { }
for ( const x in y ) { }
}
expect : {
for ( const x of y ) ; for ( const x in y ) ;
}
}
2015-09-05 22:01:25 +00:00
// Fabio: My patches accidentally caused a crash whenever
// there's an extraneous set of parens around an object.
regression _cannot _destructure : {
input : {
var x = ( { x : 3 } ) ;
x ( ( { x : 3 } ) ) ;
}
expect _exact : "var x={x:3};x({x:3});" ;
}
2015-10-26 20:56:59 +00:00
regression _cannot _use _of : {
input : {
function of ( ) {
}
var of = "is a valid variable name" ;
of = { of : "is ok" } ;
x . of ;
of : foo ( )
}
expect : {
function of ( ) { }
var of = "is a valid variable name" ;
of = { of : "is ok" } ;
x . of ;
foo ( ) ; /* Label statement missing? No prob. */
}
2016-09-01 07:35:31 +00:00
}
fat _arrow _as _param : {
input : {
foo ( x => x ) ;
foo ( x => x , y => y ) ;
foo ( x => ( x , x ) ) ;
foo ( x => ( x , x ) , y => ( y , y ) ) ;
}
expect _exact : "foo(x=>x);foo(x=>x,y=>y);foo(x=>(x,x));foo(x=>(x,x),y=>(y,y));"
}
2017-03-14 05:13:43 +00:00
default _assign : {
options = {
keep _fargs : false ,
unused : true ,
}
input : {
function f ( a , b = 3 ) {
console . log ( a ) ;
}
2017-04-03 16:46:05 +00:00
2017-04-03 09:21:27 +00:00
g = ( [ [ ] = 123 ] ) => { } ;
2017-04-03 16:46:05 +00:00
h = ( [ [ x , y , z ] = [ 4 , 5 , 6 ] ] = [ ] ) => { } ;
function i ( [ [ x , y , z ] = [ 4 , 5 , 6 ] ] = [ ] ) {
console . log ( b ) ;
} ;
2017-03-14 05:13:43 +00:00
}
expect : {
function f ( a ) {
console . log ( a ) ;
}
2017-04-03 16:46:05 +00:00
2017-04-03 09:21:27 +00:00
g = ( [ [ ] = 123 ] ) => { } ;
2017-04-03 16:46:05 +00:00
h = ( [ [ x , y , z ] = [ 4 , 5 , 6 ] ] = [ ] ) => { } ;
function i ( [ [ x , y , z ] = [ 4 , 5 , 6 ] ] = [ ] ) {
console . log ( b ) ;
} ;
2017-03-14 05:13:43 +00:00
}
}
expansion : {
options = {
keep _fargs : false ,
unused : true ,
}
input : {
function f ( a , ... b ) {
console . log ( a ) ;
}
}
expect : {
function f ( a ) {
console . log ( a ) ;
}
}
}
2017-03-17 17:29:13 +00:00
issue _1613 : {
mangle = { toplevel : true } ;
input : {
const name = 1 ;
const foo = {
name
} ;
}
expect _exact : "const n=1;const c={name:n};"
}
2017-04-29 10:13:25 +00:00
format _methods : {
beautify = {
beautify : true ,
}
input : {
class A extends B { constructor ( a ) { x ( ) } static s ( b , c ) { y ( ) } run ( d , e , f ) { z ( ) } }
}
expect _exact : [
"class A extends B {" ,
" constructor(a) {" ,
" x();" ,
" }" ,
" static s(b, c) {" ,
" y();" ,
" }" ,
" run(d, e, f) {" ,
" z();" ,
" }" ,
"}" ,
]
}
2017-05-10 03:36:03 +00:00
issue _1898 : {
options = {
}
mangle = {
}
input : {
class Foo {
bar ( ) {
for ( const x of [ 6 , 5 ] ) {
for ( let y of [ 4 , 3 ] ) {
for ( var z of [ 2 , 1 ] ) {
console . log ( x , y , z ) ;
}
}
}
}
}
new Foo ( ) . bar ( ) ;
}
expect : {
class Foo {
bar ( ) {
2017-06-25 08:02:46 +00:00
for ( const f of [ 6 , 5 ] )
2017-05-10 03:36:03 +00:00
for ( let r of [ 4 , 3 ] )
for ( var o of [ 2 , 1 ] )
2017-06-25 08:02:46 +00:00
console . log ( f , r , o ) ;
2017-05-10 03:36:03 +00:00
}
}
new Foo ( ) . bar ( ) ;
}
}
2017-05-11 08:48:43 +00:00
issue _1753 : {
mangle = { safari10 : true } ;
input : {
class SomeClass {
constructor ( props ) {
let pickedSets = [ ] ;
for ( let i = 0 ; i < 6 ; i ++ ) {
pickedSets . push ( {
mainDrawNumbers : [ ] ,
extraDrawNumbers : [ ]
} ) ;
}
}
}
}
expect : {
class SomeClass {
constructor ( r ) {
2017-06-25 08:02:46 +00:00
let s = [ ] ;
for ( let a = 0 ; a < 6 ; a ++ )
s . push ( {
2017-05-11 08:48:43 +00:00
mainDrawNumbers : [ ] ,
extraDrawNumbers : [ ]
} ) ;
}
}
}
}
issue _1753 _disable : {
mangle = { safari10 : false }
input : {
class SomeClass {
constructor ( props ) {
let pickedSets = [ ] ;
for ( let i = 0 ; i < 6 ; i ++ ) {
pickedSets . push ( {
mainDrawNumbers : [ ] ,
extraDrawNumbers : [ ]
} ) ;
}
}
}
}
expect : {
class SomeClass {
constructor ( r ) {
2017-06-25 08:02:46 +00:00
let s = [ ] ;
2017-05-11 08:48:43 +00:00
for ( let r = 0 ; r < 6 ; r ++ )
2017-06-25 08:02:46 +00:00
s . push ( {
2017-05-11 08:48:43 +00:00
mainDrawNumbers : [ ] ,
extraDrawNumbers : [ ]
} ) ;
}
}
}
}
2017-05-16 19:29:25 +00:00
2017-05-17 18:36:29 +00:00
class _extends : {
options = {
evaluate : true ,
}
input : {
function f ( ) {
class foo extends bar { }
class pro extends some . prop { }
class arr extends stuff [ 1 - 1 ] { }
class bin extends ( a || b ) { }
class seq extends ( a , b ) { }
class ter extends ( a ? b : c ) { }
class uni extends ( ! 0 ) { }
}
}
expect _exact : "function f(){class foo extends bar{}class pro extends some.prop{}class arr extends stuff[0]{}class bin extends(a||b){}class seq extends(a,b){}class ter extends(a?b:c){}class uni extends(!0){}}"
}
class _extends _class : {
options = {
}
input : {
class anon extends class { } { }
class named extends class base { } { }
}
expect _exact : "class anon extends class{}{}class named extends class base{}{}"
}
class _extends _function : {
2017-05-16 19:29:25 +00:00
options = {
}
input : {
2017-05-17 18:36:29 +00:00
class anon extends function ( ) { } { }
class named extends function base ( ) { } { }
}
expect _exact : "class anon extends function(){}{}class named extends function base(){}{}"
}
class _extends _regex : {
options = {
}
input : {
function f ( ) {
class rx1 extends ( /rx/ ) { }
// class rx2 extends /rx/ {} // FIXME - parse error
}
2017-05-16 19:29:25 +00:00
}
2017-05-17 18:36:29 +00:00
expect _exact : "function f(){class rx1 extends(/rx/){}}"
2017-05-16 19:29:25 +00:00
}
2017-05-30 17:44:29 +00:00
issue _2028 : {
options = {
side _effects : true ,
}
input : {
var a = { } ;
( function ( x ) {
x . X = function ( ) {
return X ;
} ;
class X {
static hello ( ) {
console . log ( "hello" ) ;
}
}
} ( a ) ) ;
a . X ( ) . hello ( ) ;
}
expect : {
var a = { } ;
( function ( x ) {
x . X = function ( ) {
return X ;
} ;
class X {
static hello ( ) {
console . log ( "hello" ) ;
}
}
} ( a ) ) ;
a . X ( ) . hello ( ) ;
}
expect _stdout : "hello"
node _version : ">=6"
}
2017-06-03 18:45:26 +00:00
class _expression _statement : {
options = {
toplevel : false ,
side _effects : false ,
unused : false ,
}
input : {
( class { } ) ;
( class NamedClassExpr { } ) ;
let expr = ( class AnotherClassExpr { } ) ;
class C { }
}
expect _exact : "(class{});(class NamedClassExpr{});let expr=class AnotherClassExpr{};class C{}"
}
class _expression _statement _unused : {
options = {
toplevel : false ,
side _effects : true ,
unused : true ,
}
input : {
( class { } ) ;
( class NamedClassExpr { } ) ;
let expr = ( class AnotherClassExpr { } ) ;
class C { }
}
expect _exact : "let expr=class{};class C{}"
}
class _expression _statement _unused _toplevel : {
options = {
toplevel : true ,
side _effects : true ,
unused : true ,
}
input : {
( class { } ) ;
( class NamedClassExpr { } ) ;
let expr = ( class AnotherClassExpr { } ) ;
class C { }
}
expect _exact : ""
}
2017-06-19 06:30:59 +00:00
export _default _function _decl : {
options = {
toplevel : true ,
passes : 3 ,
unused : true ,
}
input : {
// do not drop "unused" exports
export default function Foo ( ) { } ;
export function Far ( ) { } ;
}
expect _exact : "export default function Foo(){};export function Far(){};"
}
export _default _class _decl : {
options = {
toplevel : true ,
passes : 3 ,
unused : true ,
}
input : {
// do not drop "unused" exports
export default class Car { } ;
export class Cab { } ;
}
expect _exact : "export default class Car{};export class Cab{};"
}
2017-08-02 05:47:58 +00:00
object _rest _spread : {
mangle = {
toplevel : true ,
}
input : {
var { w : w1 , ... V } = { w : 7 , x : 1 , y : 2 } ; console . log ( w1 , V ) ;
let { w : w2 , ... L } = { w : 8 , x : 3 , y : 4 } ; console . log ( w2 , L ) ;
const { w : w3 , ... C } = { w : 9 , x : 5 , y : 6 } ; console . log ( w3 , C ) ;
let b ;
( { b , ... V } = { a : 1 , b : 2 , c : 3 } ) ; console . log ( V ) ;
( { b , ... L } = { a : 4 , b : 5 , c : 6 } ) ; console . log ( L ) ;
( function ( { y , ... p } ) { console . log ( p ) ; } ) ( { x : 1 , y : 2 , z : 3 } ) ;
( ( { y , ... p } ) => { console . log ( p ) ; } ) ( { x : 4 , y : 5 , z : 6 } ) ;
const T = { a : 1 , b : 2 } ; console . log ( { ... T , w : 0 , ... { } , ... L , ... { K : 9 } } ) ;
}
expect : {
var { w : o , ... l } = { w : 7 , x : 1 , y : 2 } ; console . log ( o , l ) ;
let { w : c , ... n } = { w : 8 , x : 3 , y : 4 } ; console . log ( c , n ) ;
const { w : e , ... s } = { w : 9 , x : 5 , y : 6 } ; console . log ( e , s ) ;
let g ;
( { b : g , ... l } = { a : 1 , b : 2 , c : 3 } ) ; console . log ( l ) ;
( { b : g , ... n } = { a : 4 , b : 5 , c : 6 } ) ; console . log ( n ) ;
( function ( { y : o , ... l } ) { console . log ( l ) ; } ) ( { x : 1 , y : 2 , z : 3 } ) ;
( ( { y : o , ... l } ) => { console . log ( l ) ; } ) ( { x : 4 , y : 5 , z : 6 } ) ;
const w = { a : 1 , b : 2 } ; console . log ( { ... w , w : 0 , ... { } , ... n , ... { K : 9 } } ) ;
}
}
object _spread _unsafe : {
options = {
collapse _vars : true ,
evaluate : true ,
join _vars : true ,
passes : 3 ,
2017-11-11 07:57:47 +00:00
reduce _funcs : true ,
2017-08-02 05:47:58 +00:00
reduce _vars : true ,
side _effects : true ,
toplevel : true ,
unsafe : true ,
unused : true ,
}
mangle = {
toplevel : true ,
}
input : {
var o1 = { x : 1 , y : 2 } ;
var o2 = { x : 3 , z : 4 } ;
var cloned = { ... o1 } ;
var merged = { ... o1 , ... o2 } ;
console . log ( cloned , merged ) ;
}
expect : {
var o = { x : 1 , y : 2 } , l = { ... o } , x = { ... o , ... { x : 3 , z : 4 } } ;
console . log ( l , x ) ;
}
}
2017-08-02 16:40:19 +00:00
array _spread _of _sequence : {
mangle = {
toplevel : true ,
}
input : {
var a = [ 1 ] ;
console . log ( [ ... ( a , a ) ] ) ;
console . log ( [ ... a , a ] ) ;
console . log ( [ ... ( a || a ) ] ) ;
console . log ( [ ... a || a ] ) ;
}
expect : {
var o = [ 1 ] ;
console . log ( [ ... ( o , o ) ] ) ;
console . log ( [ ... o , o ] ) ;
console . log ( [ ... o || o ] ) ;
console . log ( [ ... o || o ] ) ;
}
expect _stdout : [
"[ 1 ]" ,
"[ 1, [ 1 ] ]" ,
"[ 1 ]" ,
"[ 1 ]" ,
]
node _version : ">=6"
}
object _spread _of _sequence : {
mangle = {
toplevel : true ,
}
input : {
var a = { x : 1 } ;
console . log ( { ... ( a , a ) } ) ;
console . log ( { ... a , a } ) ;
console . log ( { ... ( a || a ) } ) ;
console . log ( { ... a || a } ) ;
}
expect : {
var o = { x : 1 } ;
console . log ( { ... ( o , o ) } ) ;
console . log ( { ... o , a : o } ) ;
console . log ( { ... o || o } ) ;
console . log ( { ... o || o } ) ;
}
}
2017-09-23 16:08:47 +00:00
// issue 2316
class _name _can _be _preserved _with _reserved : {
mangle = {
2017-09-23 18:23:38 +00:00
reserved : [ "Foo" ] ,
2017-09-23 16:08:47 +00:00
}
input : {
function x ( ) {
2017-09-23 18:23:38 +00:00
class Foo { }
2017-09-23 16:08:47 +00:00
Foo . bar ;
2017-09-23 18:23:38 +00:00
class Bar { }
2017-09-23 16:08:47 +00:00
Bar . foo ;
}
function y ( ) {
var Foo = class Foo { } ;
2017-09-23 18:23:38 +00:00
Foo . bar ;
2017-09-23 16:08:47 +00:00
var Bar = class Bar { } ;
2017-09-23 18:23:38 +00:00
Bar . bar ;
2017-09-23 16:08:47 +00:00
}
}
expect : {
function x ( ) {
class Foo { }
Foo . bar ;
2017-09-23 18:23:38 +00:00
class a { }
a . foo ;
2017-09-23 16:08:47 +00:00
}
function y ( ) {
var Foo = class Foo { } ;
2017-09-23 18:23:38 +00:00
Foo . bar ;
var a = class a { } ;
a . bar ;
2017-09-23 16:08:47 +00:00
}
}
}
2017-10-05 16:57:00 +00:00
issue _2345 : {
options = {
evaluate : true ,
side _effects : true ,
unsafe : true ,
unused : true ,
}
input : {
console . log ( [ ... [ 3 , 2 , 1 ] ] . join ( "-" ) ) ;
var a = [ 3 , 2 , 1 ] ;
console . log ( [ ... a ] . join ( "-" ) ) ;
}
expect : {
console . log ( [ ... [ 3 , 2 , 1 ] ] . join ( "-" ) ) ;
var a = [ 3 , 2 , 1 ] ;
console . log ( [ ... a ] . join ( "-" ) ) ;
}
expect _stdout : [
"3-2-1" ,
"3-2-1" ,
]
node _version : ">=6"
}
2017-10-15 12:59:52 +00:00
issue _2349 : {
mangle = { }
input : {
function foo ( boo , key ) {
const value = boo . get ( ) ;
return value . map ( ( { [ key ] : bar } ) => bar ) ;
}
console . log ( foo ( {
get : ( ) => [ {
blah : 42
} ]
} , "blah" ) ) ;
}
expect : {
function foo ( o , n ) {
const t = o . get ( ) ;
return t . map ( ( { [ n ] : o } ) => o ) ;
}
console . log ( foo ( {
get : ( ) => [ {
blah : 42
} ]
} , "blah" ) ) ;
}
expect _stdout : [
"[ 42 ]" ,
]
node _version : ">=7"
}
issue _2349b : {
options = {
arrows : true ,
collapse _vars : true ,
ecma : 6 ,
evaluate : true ,
inline : true ,
passes : 3 ,
2017-10-29 09:14:52 +00:00
properties : true ,
2017-11-11 07:57:47 +00:00
reduce _funcs : true ,
2017-10-15 12:59:52 +00:00
reduce _vars : true ,
toplevel : true ,
side _effects : true ,
unsafe _arrows : true ,
unused : true ,
}
mangle = {
toplevel : true ,
}
input : {
function foo ( boo , key ) {
const value = boo . get ( ) ;
return value . map ( function ( { [ key ] : bar } ) { return bar ; } ) ;
}
console . log ( foo ( {
get : function ( ) {
return [ {
blah : 42
} ] ;
}
} , "blah" ) ) ;
}
expect : {
console . log ( [ {
blah : 42
} ] . map ( ( { [ "blah" ] : l } ) => l ) ) ;
}
expect _stdout : [
"[ 42 ]" ,
]
node _version : ">=7"
}
2017-11-19 05:53:42 +00:00
shorthand _keywords : {
beautify = {
ecma : 6 ,
}
input : {
var foo = 0 ,
async = 1 ,
await = 2 ,
implements = 3 ,
package = 4 ,
private = 5 ,
protected = 6 ,
static = 7 ,
yield = 8 ;
console . log ( {
foo : foo ,
0 : 0 ,
NaN : NaN ,
async : async ,
await : await ,
false : false ,
implements : implements ,
null : null ,
package : package ,
private : private ,
protected : protected ,
static : static ,
this : this ,
true : true ,
undefined : undefined ,
yield : yield ,
} ) ;
}
expect _exact : "var foo=0,async=1,await=2,implements=3,package=4,private=5,protected=6,static=7,yield=8;console.log({foo,0:0,NaN:NaN,async,await,false:false,implements:implements,null:null,package:package,private:private,protected:protected,static:static,this:this,true:true,undefined:void 0,yield});"
expect _stdout : true
node _version : ">=4"
}
2017-11-23 18:04:26 +00:00
array _literal _with _spread _1 : {
options = {
properties : true ,
side _effects : true ,
}
input : {
var f = ( x ) => [ ... x ] [ 0 ] ;
console . log ( f ( [ "PASS" ] ) ) ;
}
expect : {
var f = x => [ ... x ] [ 0 ] ;
console . log ( f ( [ "PASS" ] ) ) ;
}
expect _stdout : "PASS"
node _version : ">=6"
}
array _literal _with _spread _2 : {
options = {
properties : true ,
side _effects : true ,
}
input : {
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ "length" ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 0 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 1 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 2 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 3 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 4 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 5 ] ) ;
}
expect : {
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ "length" ] ) ;
console . log ( 10 ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 1 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 2 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 3 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 4 ] ) ;
console . log ( [ 10 , ... [ ] , 20 , ... [ 30 , 40 ] , 50 ] [ 5 ] ) ;
}
expect _stdout : [
"5" ,
"10" ,
"20" ,
"30" ,
"40" ,
"50" ,
"undefined" ,
]
node _version : ">=6"
}
array _literal _with _spread _3 : {
options = {
properties : true ,
side _effects : true ,
}
input : {
console . log ( [ 10 , 20 ] [ 0 ] ) ;
console . log ( [ 10 , 20 ] [ 1 ] ) ;
console . log ( [ 10 , 20 ] [ 2 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 0 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 1 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 2 ] ) ;
console . log ( [ 10 , ... [ ] , 20 ] [ 0 ] ) ;
console . log ( [ 10 , ... [ ] , 20 ] [ 1 ] ) ;
console . log ( [ 10 , ... [ ] , 20 ] [ 2 ] ) ;
console . log ( [ 10 , 20 , ... [ ] ] [ 0 ] ) ;
console . log ( [ 10 , 20 , ... [ ] ] [ 1 ] ) ;
console . log ( [ 10 , 20 , ... [ ] ] [ 2 ] ) ;
}
expect : {
console . log ( 10 ) ;
console . log ( 20 ) ;
console . log ( [ 10 , 20 ] [ 2 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 0 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 1 ] ) ;
console . log ( [ ... [ ] , 10 , 20 ] [ 2 ] ) ;
console . log ( 10 ) ;
console . log ( [ 10 , ... [ ] , 20 ] [ 1 ] ) ;
console . log ( [ 10 , ... [ ] , 20 ] [ 2 ] ) ;
console . log ( 10 ) ;
console . log ( 20 ) ;
console . log ( [ 10 , 20 , ... [ ] ] [ 2 ] ) ;
}
expect _stdout : [
"10" ,
"20" ,
"undefined" ,
"10" ,
"20" ,
"undefined" ,
"10" ,
"20" ,
"undefined" ,
"10" ,
"20" ,
"undefined" ,
]
node _version : ">=6"
}
array _literal _with _spread _4 : {
options = {
properties : true ,
side _effects : true ,
}
input : {
function t ( x ) {
console . log ( "(" + x + ")" ) ;
return 10 * x ;
}
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 1 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 1 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ t ( 1 ) , ... [ ] , t ( 2 ) ] [ 0 ] ) ;
console . log ( [ t ( 1 ) , ... [ ] , t ( 2 ) ] [ 1 ] ) ;
console . log ( [ t ( 1 ) , ... [ ] , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) , ... [ ] ] [ 0 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) , ... [ ] ] [ 1 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) , ... [ ] ] [ 2 ] ) ;
}
expect : {
function t ( x ) {
console . log ( "(" + x + ")" ) ;
return 10 * x ;
}
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( ( t ( 1 ) , t ( 2 ) ) ) ;
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 1 ] ) ;
console . log ( [ ... [ ] , t ( 1 ) , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( [ t ( 1 ) , ... [ ] , t ( 2 ) ] [ 1 ] ) ;
console . log ( [ t ( 1 ) , ... [ ] , t ( 2 ) ] [ 2 ] ) ;
console . log ( [ t ( 1 ) , t ( 2 ) ] [ 0 ] ) ;
console . log ( ( t ( 1 ) , t ( 2 ) ) ) ;
console . log ( [ t ( 1 ) , t ( 2 ) , ... [ ] ] [ 2 ] ) ;
}
expect _stdout : [
"(1)" , "(2)" , "10" ,
"(1)" , "(2)" , "20" ,
"(1)" , "(2)" , "undefined" ,
"(1)" , "(2)" , "10" ,
"(1)" , "(2)" , "20" ,
"(1)" , "(2)" , "undefined" ,
"(1)" , "(2)" , "10" ,
"(1)" , "(2)" , "20" ,
"(1)" , "(2)" , "undefined" ,
"(1)" , "(2)" , "10" ,
"(1)" , "(2)" , "20" ,
"(1)" , "(2)" , "undefined" ,
]
node _version : ">=6"
}
2017-12-21 09:50:26 +00:00
object _literal _method _using _arguments : {
options = {
arrows : true ,
}
input : {
console . log ( ( {
m ( ) {
return arguments [ 0 ] ;
}
} ) . m ( "PASS" ) ) ;
}
expect : {
console . log ( ( {
m ( ) {
return arguments [ 0 ] ;
}
} ) . m ( "PASS" ) ) ;
}
expect _stdout : "PASS"
node _version : ">=6"
}
class _method _using _arguments : {
options = {
arrows : true ,
}
input : {
console . log ( new class {
m ( ) {
return arguments [ 0 ] ;
}
} ( ) . m ( "PASS" ) ) ;
}
expect : {
console . log ( new class {
m ( ) {
return arguments [ 0 ] ;
}
} ( ) . m ( "PASS" ) ) ;
}
expect _stdout : "PASS"
node _version : ">=6"
}
2017-12-27 21:07:19 +00:00
issue _2676 : {
options = {
reduce _vars : true ,
toplevel : true ,
unused : true ,
}
input : {
class A { }
A . a = 42 ;
}
expect : {
( class { } ) . a = 42 ;
}
}
2018-01-14 04:12:29 +00:00
issue _2762 : {
mangle = { }
input : {
var bar = 1 , T = true ;
( function ( ) {
if ( T ) {
const a = function ( ) {
var foo = bar ;
console . log ( foo , a . prop , b . prop ) ;
} ;
a . prop = 2 ;
const b = { prop : 3 } ;
a ( ) ;
}
} ) ( ) ;
}
expect : {
var bar = 1 , T = true ;
( function ( ) {
if ( T ) {
const o = function ( ) {
var p = bar ;
console . log ( p , o . prop , r . prop ) ;
} ;
o . prop = 2 ;
const r = { prop : 3 } ;
o ( ) ;
}
} ) ( ) ;
}
expect _stdout : "1 2 3"
}
2018-01-17 06:46:23 +00:00
issue _2794 _1 : {
options = {
collapse _vars : true ,
evaluate : true ,
inline : true ,
passes : 1 ,
properties : true ,
reduce _funcs : true ,
reduce _vars : true ,
toplevel : false ,
side _effects : true ,
unused : true ,
}
input : {
function foo ( ) {
for ( const a of func ( value ) ) {
console . log ( a ) ;
}
function func ( va ) {
return doSomething ( va ) ;
}
}
function doSomething ( x ) {
return [ x , 2 * x , 3 * x ] ;
}
const value = 10 ;
foo ( ) ;
}
expect : {
function foo ( ) {
2018-01-21 07:53:32 +00:00
for ( const a of doSomething ( value ) ) console . log ( a ) ;
2018-01-17 06:46:23 +00:00
}
function doSomething ( x ) {
return [ x , 2 * x , 3 * x ] ;
}
const value = 10 ;
foo ( ) ;
}
expect _stdout : [
"10" ,
"20" ,
"30" ,
]
node _version : ">=6"
}
issue _2794 _2 : {
mangle = {
toplevel : false ,
}
options = {
collapse _vars : true ,
evaluate : true ,
inline : true ,
passes : 1 ,
properties : true ,
reduce _funcs : true ,
reduce _vars : true ,
toplevel : false ,
side _effects : true ,
unused : true ,
}
input : {
function foo ( ) {
for ( const a of func ( value ) ) {
console . log ( a ) ;
}
function func ( va ) {
return doSomething ( va ) ;
}
}
function doSomething ( x ) {
return [ x , 2 * x , 3 * x ] ;
}
const value = 10 ;
foo ( ) ;
}
expect : {
function foo ( ) {
2018-01-21 07:53:32 +00:00
for ( const o of doSomething ( value ) ) console . log ( o ) ;
2018-01-17 06:46:23 +00:00
}
function doSomething ( o ) {
return [ o , 2 * o , 3 * o ] ;
}
const value = 10 ;
foo ( ) ;
}
expect _stdout : [
"10" ,
"20" ,
"30" ,
]
node _version : ">=6"
}
issue _2794 _3 : {
mangle = {
toplevel : true ,
}
options = {
collapse _vars : true ,
evaluate : true ,
inline : 3 ,
passes : 3 ,
properties : true ,
reduce _funcs : true ,
reduce _vars : true ,
toplevel : true ,
side _effects : true ,
unused : true ,
}
input : {
function foo ( ) {
for ( const a of func ( value ) ) {
console . log ( a ) ;
}
function func ( va ) {
return doSomething ( va ) ;
}
}
function doSomething ( x ) {
return [ x , 2 * x , 3 * x ] ;
}
const value = 10 ;
foo ( ) ;
}
expect : {
( function ( ) {
for ( const o of [ 10 , 20 , 30 ] ) console . log ( o ) ;
} ) ( ) ;
}
expect _stdout : [
"10" ,
"20" ,
"30" ,
]
node _version : ">=6"
}
issue _2794 _4 : {
options = { }
input : {
for ( var x of ( [ 1 , 2 ] , [ 3 , 4 ] ) ) {
console . log ( x ) ;
}
}
expect _exact : "for(var x of([1,2],[3,4]))console.log(x);"
expect _stdout : [
"3" ,
"4" ,
]
node _version : ">=6"
}
issue _2794 _5 : {
mangle = { }
options = {
evaluate : true ,
passes : 1 ,
side _effects : true ,
unused : true ,
}
input : {
for ( var x of ( [ 1 , 2 ] , [ 3 , 4 ] ) ) {
console . log ( x ) ;
}
}
expect _exact : "for(var x of[3,4])console.log(x);"
expect _stdout : [
"3" ,
"4" ,
]
node _version : ">=6"
}
issue _2794 _6 : {
options = {
}
input : {
// TODO (or not): have parser flag invalid for-of expression.
// Consider it an uglify extension in the meantime.
for ( let e of [ 1 , 2 ] , [ 3 , 4 , 5 ] ) {
console . log ( e ) ;
}
}
expect _exact : "for(let e of([1,2],[3,4,5]))console.log(e);"
expect _stdout : [
"3" ,
"4" ,
"5" ,
]
node _version : ">=6"
}
2018-02-03 06:51:19 +00:00
inline _arrow _using _arguments : {
options = {
evaluate : true ,
inline : 1 ,
reduce _funcs : true ,
reduce _vars : true ,
sequences : true ,
side _effects : true ,
unused : true ,
}
input : {
( function ( ) {
( ( x ) => {
console . log . apply ( console , arguments ) ,
console . log ( x ) ;
} ) ( 4 ) ;
} ) ( 3 , 2 , 1 ) ;
}
expect : {
( function ( ) {
console . log . apply ( console , arguments ) ,
console . log ( 4 ) ;
} ) ( 3 , 2 , 1 ) ;
}
expect _stdout : [
"3 2 1" ,
"4" ,
]
node _version : ">=6"
}
2018-02-05 07:01:31 +00:00
issue _2874 _1 : {
options = {
collapse _vars : true ,
evaluate : true ,
inline : 3 ,
reduce _funcs : true ,
reduce _vars : true ,
sequences : true ,
side _effects : true ,
unused : true ,
}
input : {
( function ( ) {
function foo ( ) {
let letters = [ "A" , "B" , "C" ] ;
let result = [ 2 , 1 , 0 ] . map ( key => bar ( letters [ key ] + key ) ) ;
return result ;
}
function bar ( value ) {
return ( ) => console . log ( value ) ;
}
foo ( ) . map ( fn => fn ( ) ) ;
} ) ( ) ;
}
expect : {
( function ( ) {
( function ( ) {
let letters = [ "A" , "B" , "C" ] ;
return [ 2 , 1 , 0 ] . map ( key => ( function ( value ) {
return ( ) => console . log ( value ) ;
} ) ( letters [ key ] + key ) ) ;
} ) ( ) . map ( fn => fn ( ) ) ;
} ) ( ) ;
}
expect _stdout : [
"C2" ,
"B1" ,
"A0" ,
]
node _version : ">=6"
}
issue _2874 _2 : {
options = {
collapse _vars : true ,
evaluate : true ,
inline : 3 ,
reduce _funcs : true ,
reduce _vars : true ,
sequences : true ,
side _effects : true ,
unused : true ,
}
input : {
( function ( ) {
let keys = [ ] ;
function foo ( ) {
var result = [ 2 , 1 , 0 ] . map ( value => {
keys . push ( value ) ;
return bar ( ) ;
} ) ;
return result ;
}
function bar ( ) {
var letters = [ "A" , "B" , "C" ] , key = keys . shift ( ) ;
return ( ) => console . log ( letters [ key ] + key ) ;
}
foo ( ) . map ( fn => fn ( ) ) ;
} ) ( ) ;
}
expect : {
( function ( ) {
let keys = [ ] ;
[ 2 , 1 , 0 ] . map ( value => {
return keys . push ( value ) , function ( ) {
var letters = [ "A" , "B" , "C" ] , key = keys . shift ( ) ;
return ( ) => console . log ( letters [ key ] + key ) ;
} ( ) ;
} ) . map ( fn => fn ( ) ) ;
} ) ( ) ;
}
expect _stdout : [
"C2" ,
"B1" ,
"A0" ,
]
node _version : ">=6"
}
issue _2874 _3 : {
options = {
collapse _vars : true ,
evaluate : true ,
inline : 3 ,
reduce _funcs : false ,
reduce _vars : true ,
sequences : true ,
side _effects : true ,
toplevel : true ,
unused : true ,
}
input : {
function f ( ) {
return x + y ;
}
let x , y ;
let a = ( z ) => {
x = "A" ;
y = z ;
console . log ( f ( ) ) ;
}
a ( 1 ) ;
a ( 2 ) ;
}
expect : {
let x , y ;
let a = z => {
x = "A" ,
y = z ,
console . log ( x + y ) ;
} ;
a ( 1 ) ,
a ( 2 ) ;
}
expect _stdout : [
"A1" ,
"A2" ,
]
node _version : ">=6"
}