michael@0: // Check that we correctly throw SyntaxErrors for various syntactic near-misses. michael@0: michael@0: load(libdir + "asserts.js"); michael@0: michael@0: var mistakes = [ michael@0: "((a)) => expr", michael@0: "a + b => a", michael@0: "'' + a => a", michael@0: "...x", michael@0: "[x] => x", michael@0: "([x] => x)", michael@0: "{p: p} => p", michael@0: "({p: p} => p)", michael@0: "{p} => p", michael@0: "(...x => expr)", michael@0: "1 || a => a", michael@0: "'use strict' => {}", michael@0: "package => {'use strict';}", // tricky: FutureReservedWord in strict mode code only michael@0: "'use strict'; arguments => 0", // names banned in strict mode code michael@0: "'use strict'; eval => 0", michael@0: "a => {'use strict'; with (a) return x; }", michael@0: "a => yield a", michael@0: "a => { yield a; }", michael@0: "a => { { let x; yield a; } }", michael@0: "(a = yield 0) => a", michael@0: "for (;;) a => { break; };", michael@0: "for (;;) a => { continue; };", michael@0: "...rest) =>", michael@0: "2 + ...rest) =>" michael@0: ]; michael@0: michael@0: for (var s of mistakes) michael@0: assertThrowsInstanceOf(function () { Function(s); }, SyntaxError); michael@0: michael@0: // Check that the tricky case is not an error in non-strict-mode code. michael@0: var f = package => 0; michael@0: assertEq(f(1), 0); michael@0: