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 = {
evaluate : true
}
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 {
}
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 { } ;
}
}
}
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 ;
2016-02-27 12:24:18 +00:00
export var foo = 4 ;
export let foo = 6 ;
export const foo = 6 ;
export function foo ( ) { } ;
export class foo { } ;
}
2017-05-13 04:56:46 +00:00
expect _exact : "export default 3;export var foo=4;export let foo=6;export const foo=6;export function foo(){};export class foo{};"
}
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 : {
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-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 ( ) {
for ( const n of [ 6 , 5 ] )
for ( let r of [ 4 , 3 ] )
for ( var o of [ 2 , 1 ] )
console . log ( n , r , o ) ;
}
}
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 ) {
let a = [ ] ;
for ( let s = 0 ; s < 6 ; s ++ )
a . push ( {
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 ) {
let a = [ ] ;
for ( let r = 0 ; r < 6 ; r ++ )
a . push ( {
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{};"
}