yield-in-arrow.js (2425B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const yieldInParameters = [ 6 `(a = yield) => {}`, 7 `(a = yield /a/g) => {}`, // Should parse as division, not yield expression with regexp. 8 `yield => {};`, 9 `(yield) => {};`, 10 `(yield = 0) => {};`, 11 `([yield]) => {};`, 12 `([yield = 0]) => {};`, 13 `([...yield]) => {};`, 14 `({a: yield}) => {};`, 15 `({yield}) => {};`, 16 `({yield = 0}) => {};`, 17 ]; 18 19 const yieldInBody = [ 20 `() => yield;`, 21 `() => yield /a/g;`, 22 `() => { var x = yield; }`, 23 `() => { var x = yield /a/g; }`, 24 25 `() => { var yield; };`, 26 `() => { var yield = 0; };`, 27 `() => { var [yield] = []; };`, 28 `() => { var [yield = 0] = []; };`, 29 `() => { var [...yield] = []; };`, 30 `() => { var {a: yield} = {}; };`, 31 `() => { var {yield} = {}; };`, 32 `() => { var {yield = 0} = {}; };`, 33 34 `() => { let yield; };`, 35 `() => { let yield = 0; };`, 36 `() => { let [yield] = []; };`, 37 `() => { let [yield = 0] = []; };`, 38 `() => { let [...yield] = []; };`, 39 `() => { let {a: yield} = {}; };`, 40 `() => { let {yield} = {}; };`, 41 `() => { let {yield = 0} = {}; };`, 42 43 `() => { const yield = 0; };`, 44 `() => { const [yield] = []; };`, 45 `() => { const [yield = 0] = []; };`, 46 `() => { const [...yield] = []; };`, 47 `() => { const {a: yield} = {}; };`, 48 `() => { const {yield} = {}; };`, 49 `() => { const {yield = 0} = {}; };`, 50 ]; 51 52 53 // Script context. 54 for (let test of [...yieldInParameters, ...yieldInBody]) { 55 eval(test); 56 assertThrowsInstanceOf(() => eval(`"use strict"; ${test}`), SyntaxError); 57 } 58 59 // Function context. 60 for (let test of [...yieldInParameters, ...yieldInBody]) { 61 eval(`function f() { ${test} }`); 62 assertThrowsInstanceOf(() => eval(`"use strict"; function f() { ${test} }`), SyntaxError); 63 } 64 65 // Generator context. 66 for (let test of yieldInParameters) { 67 assertThrowsInstanceOf(() => eval(`function* g() { ${test} }`), SyntaxError); 68 } 69 for (let test of yieldInBody) { 70 eval(`function* g() { ${test} }`); 71 } 72 for (let test of [...yieldInParameters, ...yieldInBody]) { 73 assertThrowsInstanceOf(() => eval(`"use strict"; function* g() { ${test} }`), SyntaxError); 74 } 75 76 if (typeof reportCompare === "function") 77 reportCompare(0, 0, "ok");