2015-08-06 19:27:46 +00:00
new _statement : {
input : {
new x ( 1 ) ;
new x ( 1 ) ( 2 ) ;
new x ( 1 ) ( 2 ) ( 3 ) ;
new new x ( 1 ) ;
new new x ( 1 ) ( 2 ) ;
new ( new x ( 1 ) ) ( 2 ) ;
( new new x ( 1 ) ) ( 2 ) ;
}
expect _exact : "new x(1);new x(1)(2);new x(1)(2)(3);new new x(1);new new x(1)(2);new new x(1)(2);(new new x(1))(2);"
}
2016-06-06 23:33:13 +00:00
2016-06-10 13:42:55 +00:00
new _statements _2 : {
input : {
new x ;
new new x ;
new new new x ;
new true ;
new ( 0 ) ;
new ( ! 0 ) ;
new ( bar = function ( foo ) { this . foo = foo ; } ) ( 123 ) ;
new ( bar = function ( foo ) { this . foo = foo ; } ) ( ) ;
}
expect _exact : "new x;new(new x);new(new(new x));new true;new 0;new(!0);new(bar=function(foo){this.foo=foo})(123);new(bar=function(foo){this.foo=foo});"
}
new _statements _3 : {
input : {
new ( function ( foo ) { this . foo = foo ; } ) ( 1 ) ;
new ( function ( foo ) { this . foo = foo ; } ) ( ) ;
new ( function test ( foo ) { this . foo = foo ; } ) ( 1 ) ;
new ( function test ( foo ) { this . foo = foo ; } ) ( ) ;
}
expect _exact : "new function(foo){this.foo=foo}(1);new function(foo){this.foo=foo};new function test(foo){this.foo=foo}(1);new function test(foo){this.foo=foo};"
}
2016-06-06 23:33:13 +00:00
new _with _rewritten _true _value : {
2018-07-01 06:34:42 +00:00
options = {
booleans : true ,
}
2016-06-06 23:33:13 +00:00
input : {
new true ;
}
expect _exact : "new(!0);"
}
2016-06-10 13:42:55 +00:00
new _with _many _parameters : {
input : {
new foo . bar ( "baz" ) ;
new x ( /123/ , 456 ) ;
}
expect _exact : 'new foo.bar("baz");new x(/123/,456);'
}
2016-07-23 15:50:44 +00:00
new _constructor _with _unary _arguments : {
input : {
new x ( ) ;
new x ( - 1 ) ;
new x ( - 1 , - 2 ) ;
new x ( void 1 , + 2 , - 3 , ~ 4 , ! 5 , -- a , ++ b , c -- , d ++ , typeof e , delete f ) ;
new ( - 1 ) ; // should parse despite being invalid at runtime.
new ( - 1 ) ( ) ; // should parse despite being invalid at runtime.
new ( - 1 ) ( - 2 ) ; // should parse despite being invalid at runtime.
}
expect _exact : "new x;new x(-1);new x(-1,-2);new x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);new(-1);new(-1);new(-1)(-2);"
}
call _with _unary _arguments : {
input : {
x ( ) ;
x ( - 1 ) ;
x ( - 1 , - 2 ) ;
x ( void 1 , + 2 , - 3 , ~ 4 , ! 5 , -- a , ++ b , c -- , d ++ , typeof e , delete f ) ;
( - 1 ) ( ) ; // should parse despite being invalid at runtime.
( - 1 ) ( - 2 ) ; // should parse despite being invalid at runtime.
}
expect _exact : "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);"
}
2016-08-17 09:43:50 +00:00
new _with _unary _prefix : {
input : {
var bar = ( + new Date ( ) ) . toString ( 32 ) ;
}
expect _exact : 'var bar=(+new Date).toString(32);' ;
}
2017-07-02 20:17:37 +00:00
dot _parenthesis _1 : {
input : {
console . log ( new ( Math . random ( ) . constructor ) instanceof Number ) ;
}
expect _exact : "console.log(new(Math.random().constructor)instanceof Number);"
expect _stdout : "true"
}
dot _parenthesis _2 : {
input : {
console . log ( typeof new function ( ) { Math . random ( ) } . constructor ) ;
}
expect _exact : "console.log(typeof new function(){Math.random()}.constructor);"
expect _stdout : "function"
}