2015-01-11 20:07:19 +00:00
arrow _functions : {
input : {
( a ) => b ; // 1 args
( a , b ) => c ; // n args
( ) => b ; // 0 args
( a ) => ( b ) => c ; // func returns func returns func
( a ) => ( ( b ) => c ) ; // So these parens are dropped
( ) => ( b , c ) => d ; // func returns func returns func
a => { return b ; }
a => 'lel' ; // Dropping the parens
}
expect _exact : "a=>b;(a,b)=>c;()=>b;a=>b=>c;a=>b=>c;()=>(b,c)=>d;a=>{return b};a=>\"lel\";"
}
arrow _function _parens : {
input : {
something && ( ( ) => { } ) ;
}
expect _exact : "something&&(()=>{});"
}
arrow _function _parens _2 : {
input : {
( ( ) => null ) ( ) ;
}
expect _exact : "(()=>null)();"
}
regression _arrow _functions _and _hoist : {
options = {
hoist _vars : true ,
hoist _funs : true
}
input : {
( a ) => b ;
}
expect _exact : "a=>b;"
}
2015-08-03 23:14:18 +00:00
2016-02-09 00:02:23 +00:00
regression _assign _arrow _functions : {
input : {
oninstall = e => false ;
oninstall = ( ) => false ;
}
expect : {
oninstall = e => false ;
oninstall = ( ) => false ;
}
}
2015-09-07 21:46:07 +00:00
computed _property _names : {
input : {
obj ( { [ "x" + "x" ] : 6 } ) ;
}
2015-10-12 20:39:19 +00:00
expect _exact : 'obj({["x"+"x"]:6});'
2015-09-07 21:46:07 +00:00
}
2016-03-12 15:53:57 +00:00
shorthand _properties : {
mangle = true ;
input : ( function ( ) {
var prop = 1 ;
const value = { prop } ;
return value ;
} ) ( ) ;
expect : ( function ( ) {
2016-04-18 13:51:32 +00:00
var n = 1 ;
const r = { prop : n } ;
return r ;
2016-03-12 15:53:57 +00:00
} ) ( ) ;
}
2015-08-14 21:05:42 +00:00
typeof _arrow _functions : {
options = {
evaluate : true
}
input : {
typeof ( x ) => null ;
}
expect _exact : "\"function\";"
}
2015-09-05 21:32:57 +00:00
template _strings : {
input : {
` ` ;
` xx \` x ` ;
` ${ foo + 2 } ` ;
` foo ${ bar + ` baz ${ qux } ` } ` ;
}
expect _exact : "``;`xx\\`x`;`${foo+2}`;` foo ${bar+`baz ${qux}`}`;" ;
}
2015-09-05 21:48:17 +00:00
template _string _prefixes : {
input : {
String . raw ` foo ` ;
foo ` bar ` ;
}
expect _exact : "String.raw`foo`;foo`bar`;" ;
}
2015-08-03 23:14:18 +00:00
destructuring _arguments : {
input : {
( function ( a ) { } ) ;
( function ( [ a ] ) { } ) ;
( function ( [ a , b ] ) { } ) ;
( function ( [ [ a ] ] ) { } ) ;
( function ( [ [ a , b ] ] ) { } ) ;
( function ( [ a , [ b ] ] ) { } ) ;
( function ( [ [ b ] , a ] ) { } ) ;
( function ( { a } ) { } ) ;
( function ( { a , b } ) { } ) ;
( function ( [ { a } ] ) { } ) ;
( function ( [ { a , b } ] ) { } ) ;
( function ( [ a , { b } ] ) { } ) ;
( function ( [ { b } , a ] ) { } ) ;
( [ a ] ) => { } ;
( [ a , b ] ) => { } ;
( { a } ) => { } ;
( { a , b , c , d , e } ) => { } ;
( [ a ] ) => b ;
( [ a , b ] ) => c ;
( { a } ) => b ;
( { a , b } ) => c ;
}
expect : {
( function ( a ) { } ) ;
( function ( [ a ] ) { } ) ;
( function ( [ a , b ] ) { } ) ;
( function ( [ [ a ] ] ) { } ) ;
( function ( [ [ a , b ] ] ) { } ) ;
( function ( [ a , [ b ] ] ) { } ) ;
( function ( [ [ b ] , a ] ) { } ) ;
( function ( { a } ) { } ) ;
( function ( { a , b } ) { } ) ;
( function ( [ { a } ] ) { } ) ;
( function ( [ { a , b } ] ) { } ) ;
( function ( [ a , { b } ] ) { } ) ;
( function ( [ { b } , a ] ) { } ) ;
( [ a ] ) => { } ;
( [ a , b ] ) => { } ;
( { a } ) => { } ;
( { a , b , c , d , e } ) => { } ;
( [ a ] ) => b ;
( [ a , b ] ) => c ;
( { a } ) => b ;
( { a , b } ) => c ;
}
}
2015-11-22 17:40:05 +00:00
default _arguments : {
input : {
function x ( a = 6 ) { }
function x ( a = ( 6 + 5 ) ) { }
2015-11-22 18:02:35 +00:00
function x ( { foo } = { } , [ bar ] = [ 1 ] ) { }
2015-11-22 17:40:05 +00:00
}
2015-11-22 18:02:35 +00:00
expect _exact : "function x(a=6){}function x(a=6+5){}function x({foo}={},[bar]=[1]){}"
2015-11-22 17:40:05 +00:00
}
2015-11-22 19:04:42 +00:00
default _values _in _destructurings : {
input : {
function x ( { a = ( 4 ) , b } ) { }
function x ( [ b , c = ( 12 ) ] ) { }
var { x = ( 6 ) , y } = x ;
var [ x , y = ( 6 ) ] = x ;
}
expect _exact : "function x({a=4,b}){}function x([b,c=12]){}var{x=6,y}=x;var[x,y=6]=x;"
}
2015-10-11 17:22:07 +00:00
concise _methods : {
input : {
x = {
foo ( a , b ) {
return x ;
}
}
y = {
foo ( [ { a } ] ) {
return a ;
2015-10-23 17:59:07 +00:00
} ,
bar ( ) { }
2015-10-11 17:22:07 +00:00
}
}
2015-10-23 17:59:07 +00:00
expect _exact : "x={foo(a,b){return x}};y={foo([{a}]){return a},bar(){}};"
2015-10-11 17:22:07 +00:00
}
2015-10-26 22:15:21 +00:00
concise _methods _and _mangle _props : {
mangle _props = {
regex : /_/
} ;
input : {
function x ( ) {
obj = {
_foo ( ) { return 1 ; }
}
}
}
expect : {
function x ( ) {
obj = {
a ( ) { return 1 ; }
}
}
}
}
2015-10-26 23:24:04 +00:00
concise _methods _and _keyword _names : {
input : {
x = {
catch ( ) { } ,
throw ( ) { }
}
}
expect : {
x = { catch ( ) { } , throw ( ) { } } ;
}
}
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 {
}
var class1 = Foo
var class2 = class Bar { }
}
}
expect : {
function x ( ) {
class a { }
2016-04-18 13:51:32 +00:00
var n = a
var r = 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 { } ;
}
}
}
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
}
2016-02-26 21:12:19 +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\";"
2016-02-21 17:06:09 +00:00
}
2016-02-27 12:24:18 +00:00
export _statement : {
input : {
export default 1 ;
export var foo = 4 ;
export let foo = 6 ;
export const foo = 6 ;
export function foo ( ) { } ;
export class foo { } ;
}
expect _exact : "export default 1;export var foo=4;export let foo=6;export const foo=6;export function foo(){};export class foo{};"
}
2016-02-21 17:06:09 +00:00
import _statement _mangling : {
mangle = { } ;
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 : {
2016-04-18 13:51:32 +00:00
import l from "foo" ;
import e , { Food as o } from "lel" ;
import { What as f } from "lel" ;
l ( ) ;
e ( ) ;
o ( ) ;
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-02-04 21:19:48 +00:00
generators : {
input : {
function * fn ( ) { } ;
}
expect _exact : "function*fn(){}"
}
generators _yield : {
input : {
function * fn ( ) {
yield remote ( ) ;
}
}
expect _exact : "function*fn(){yield remote()}"
}
2016-04-25 23:14:44 +00:00
generators _yield _assign : {
input : {
function * fn ( ) {
var x = { } ;
x . prop = yield 5 ;
}
}
expect _exact : "function*fn(){var x={};x.prop=yield 5}"
}