tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rest-with-trailing-comma.js (1005B)


      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 invalidSyntax = [
      6    "[...r, ]",
      7    "[a, ...r, ]",
      8    "[a = 0, ...r, ]",
      9    "[[], ...r, ]",
     10    "[[...r,]]",
     11    "[[...r,], ]",
     12    "[[...r,], a]",
     13 ];
     14 
     15 const validSyntax = [
     16    "[, ]",
     17    "[a, ]",
     18    "[[], ]",
     19 ];
     20 
     21 const destructuringForms = [
     22    a => `${a} = [];`,
     23    a => `var ${a} = [];`,
     24    a => `let ${a} = [];`,
     25    a => `const ${a} = [];`,
     26    a => `(${a}) => {};`,
     27    a => `(${a} = []) => {};`,
     28    a => `function f(${a}) {}`,
     29 ];
     30 
     31 for (let invalid of invalidSyntax) {
     32    for (let fn of destructuringForms) {
     33        assertThrowsInstanceOf(() => Function(fn(invalid)), SyntaxError);
     34    }
     35 }
     36 
     37 for (let invalid of validSyntax) {
     38    for (let fn of destructuringForms) {
     39        Function(fn(invalid));
     40    }
     41 }
     42 
     43 
     44 if (typeof reportCompare === "function")
     45    reportCompare(0, 0);