2015-06-26 06:49:20 +00:00
description ( "Tests for ES6 arrow function syntax errors" ) ;
shouldThrow ( '=>{}' ) ;
function checkStatement ( statement ) {
var unexpectedSymbols = [ "" ,
"*" , "/" , "%" , "+" , "-" ,
"<<" , ">>" , ">>>" ,
"<" , ">" , "<=" , ">=" , "instanceof" , "in" ,
"==" , "!=" , "===" , "!==" ,
"&" , "^" , "|" ,
"&&" , "||" , ";" , ","
] ;
for ( var i = 0 ; i < unexpectedSymbols . length ; i ++ ) {
shouldThrow ( statement + unexpectedSymbols [ i ] ) ;
}
}
checkStatement ( 'x=>' ) ;
checkStatement ( 'x=>{' ) ;
shouldThrow ( 'x=>}' ) ;
checkStatement ( 'var y = x=>' ) ;
checkStatement ( 'var y = x=>{' ) ;
shouldThrow ( 'var y = x=>}' ) ;
shouldThrow ( 'var t = x=>x+1; =>{}' ) ;
shouldThrow ( '[=>x+1]' ) ;
shouldThrow ( '[x=>x+1, =>x+1]' ) ;
shouldThrow ( 'var f=>x+1;' ) ;
shouldThrow ( 'var x, y=>y+1;' ) ;
shouldThrow ( 'debug(=>x+1)' ) ;
shouldThrow ( 'debug("xyz", =>x+1)' ) ;
2015-06-28 16:18:26 +00:00
shouldThrow ( "var af1=y\n=>y+1" ) ;
shouldThrow ( "var af2=(y)\n=>y+1" ) ;
shouldThrow ( "var af3=(x, y)\n=>y+1" ) ;
2016-01-17 00:04:37 +00:00
shouldThrow ( '([a, b] => a + b)(["a_", "b_"])' ) ;
shouldThrow ( '({a, b} => a + b)({a:"a_", b:"b_"})' ) ;
shouldThrow ( '({c:a,d:b} => a + b)({c:"a_", d:"b_"})' ) ;
shouldThrow ( '({c:b,d:a} => a + b)({c:"a_", d:"b_"})' ) ;
shouldThrow ( 'var arr1 = [a, b] => a + b;' ) ;
shouldThrow ( 'var arr2 = {a, b} => a + b;' ) ;
shouldThrow ( 'var arr3 = {c:a,d:b} => a + b;' ) ;
shouldThrow ( 'var arr3 = {c:b,d:a} => a + b;' ) ;
2016-04-22 23:04:55 +00:00
shouldThrow ( 'var arr4 = () => { super(); };' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'var arr4 = () => { super; };' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'var arr5 = () => { super.getValue(); };' , '"SyntaxError: super is not valid in this context."' ) ;
2016-02-08 19:29:24 +00:00
2016-04-22 23:04:55 +00:00
shouldThrow ( 'var arr6 = () => super();' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'var arr7 = () => super;' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'var arr8 = () => super.getValue();' , '"SyntaxError: super is not valid in this context."' ) ;
2016-02-08 19:29:24 +00:00
2016-04-22 23:04:55 +00:00
shouldThrow ( 'class A { constructor() { function a () { return () => { super(); };}}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class B { constructor() { function b () { return () => { super; }; }; }}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class C { constructor() { function c () { return () => { super.getValue(); };}}' , '"SyntaxError: super is not valid in this context."' ) ;
2016-02-08 19:29:24 +00:00
2016-04-22 23:04:55 +00:00
shouldThrow ( 'class D { constructor() { function a () { return () => super(); }}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class E { constructor() { function b () { return () => super; }; }}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class F { constructor() { function c () { return () => super.getValue(); }}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class G {}; class G2 extends G { getValue() { function c () { return () => super.getValue(); }}' , '"SyntaxError: super is not valid in this context."' ) ;
shouldThrow ( 'class H {}; class H2 extends H { method() { function *gen() { let arr = () => super.getValue(); arr(); } } }' , '"SyntaxError: super is not valid in this context."' ) ;
2016-02-08 19:29:24 +00:00
2015-06-26 06:49:20 +00:00
var successfullyParsed = true ;