no-variable-name.js (6655B)
1 function assertThrowsMsgEndsWith(f, msg) { 2 try { 3 f(); 4 assertEq(0, 1); 5 } catch (e) { 6 assertEq(e instanceof SyntaxError, true); 7 assertEq(e.message.endsWith(msg), true); 8 } 9 } 10 11 assertThrowsMsgEndsWith(() => { 12 Reflect.parse("var break;"); 13 }, "missing variable name, got keyword 'break'"); 14 assertThrowsMsgEndsWith(() => { 15 Reflect.parse("var case;"); 16 }, "missing variable name, got keyword 'case'"); 17 assertThrowsMsgEndsWith(() => { 18 Reflect.parse("var catch;"); 19 }, "missing variable name, got keyword 'catch'"); 20 assertThrowsMsgEndsWith(() => { 21 Reflect.parse("var class;"); 22 }, "missing variable name, got keyword 'class'"); 23 assertThrowsMsgEndsWith(() => { 24 Reflect.parse("var const;"); 25 }, "missing variable name, got keyword 'const'"); 26 assertThrowsMsgEndsWith(() => { 27 Reflect.parse("var continue;"); 28 }, "missing variable name, got keyword 'continue'"); 29 assertThrowsMsgEndsWith(() => { 30 Reflect.parse("var debugger;"); 31 }, "missing variable name, got keyword 'debugger'"); 32 assertThrowsMsgEndsWith(() => { 33 Reflect.parse("var default;"); 34 }, "missing variable name, got keyword 'default'"); 35 assertThrowsMsgEndsWith(() => { 36 Reflect.parse("var delete;"); 37 }, "missing variable name, got keyword 'delete'"); 38 assertThrowsMsgEndsWith(() => { 39 Reflect.parse("var do;"); 40 }, "missing variable name, got keyword 'do'"); 41 assertThrowsMsgEndsWith(() => { 42 Reflect.parse("var else;"); 43 }, "missing variable name, got keyword 'else'"); 44 assertThrowsMsgEndsWith(() => { 45 Reflect.parse("var enum;"); 46 }, "missing variable name, got reserved word 'enum'"); 47 assertThrowsMsgEndsWith(() => { 48 Reflect.parse("var export;"); 49 }, "missing variable name, got keyword 'export'"); 50 assertThrowsMsgEndsWith(() => { 51 Reflect.parse("var extends;"); 52 }, "missing variable name, got keyword 'extends'"); 53 assertThrowsMsgEndsWith(() => { 54 Reflect.parse("var false;"); 55 }, "missing variable name, got boolean literal 'false'"); 56 assertThrowsMsgEndsWith(() => { 57 Reflect.parse("var finally;"); 58 }, "missing variable name, got keyword 'finally'"); 59 assertThrowsMsgEndsWith(() => { 60 Reflect.parse("var for;"); 61 }, "missing variable name, got keyword 'for'"); 62 assertThrowsMsgEndsWith(() => { 63 Reflect.parse("var function;"); 64 }, "missing variable name, got keyword 'function'"); 65 assertThrowsMsgEndsWith(() => { 66 Reflect.parse("var if;"); 67 }, "missing variable name, got keyword 'if'"); 68 assertThrowsMsgEndsWith(() => { 69 Reflect.parse("var import;"); 70 }, "missing variable name, got keyword 'import'"); 71 assertThrowsMsgEndsWith(() => { 72 Reflect.parse("var in;"); 73 }, "missing variable name, got keyword 'in'"); 74 assertThrowsMsgEndsWith(() => { 75 Reflect.parse("var instanceof;"); 76 }, "missing variable name, got keyword 'instanceof'"); 77 assertThrowsMsgEndsWith(() => { 78 Reflect.parse("var new;"); 79 }, "missing variable name, got keyword 'new'"); 80 assertThrowsMsgEndsWith(() => { 81 Reflect.parse("var null;"); 82 }, "missing variable name, got null literal"); 83 assertThrowsMsgEndsWith(() => { 84 Reflect.parse("var return;"); 85 }, "missing variable name, got keyword 'return'"); 86 assertThrowsMsgEndsWith(() => { 87 Reflect.parse("var super;"); 88 }, "missing variable name, got keyword 'super'"); 89 assertThrowsMsgEndsWith(() => { 90 Reflect.parse("var switch;"); 91 }, "missing variable name, got keyword 'switch'"); 92 assertThrowsMsgEndsWith(() => { 93 Reflect.parse("var this;"); 94 }, "missing variable name, got keyword 'this'"); 95 assertThrowsMsgEndsWith(() => { 96 Reflect.parse("var throw;"); 97 }, "missing variable name, got keyword 'throw'"); 98 assertThrowsMsgEndsWith(() => { 99 Reflect.parse("var true;"); 100 }, "missing variable name, got boolean literal 'true'"); 101 assertThrowsMsgEndsWith(() => { 102 Reflect.parse("var try;"); 103 }, "missing variable name, got keyword 'try'"); 104 assertThrowsMsgEndsWith(() => { 105 Reflect.parse("var typeof;"); 106 }, "missing variable name, got keyword 'typeof'"); 107 assertThrowsMsgEndsWith(() => { 108 Reflect.parse("var var;"); 109 }, "missing variable name, got keyword 'var'"); 110 assertThrowsMsgEndsWith(() => { 111 Reflect.parse("var void;"); 112 }, "missing variable name, got keyword 'void'"); 113 assertThrowsMsgEndsWith(() => { 114 Reflect.parse("var while;"); 115 }, "missing variable name, got keyword 'while'"); 116 assertThrowsMsgEndsWith(() => { 117 Reflect.parse("var with;"); 118 }, "missing variable name, got keyword 'with'"); 119 assertThrowsMsgEndsWith(() => { 120 Reflect.parse("var;"); 121 }, "missing variable name, got ';'"); 122 assertThrowsMsgEndsWith(() => { 123 Reflect.parse("var a, , b;"); 124 }, "missing variable name, got ','"); 125 126 assertThrowsMsgEndsWith(() => { 127 Reflect.parse("for (var else of arr) {}"); 128 }, "missing variable name, got keyword 'else'"); 129 130 // Object and Array Binding Tests 131 var o = { a: 10 }; 132 assertThrowsMsgEndsWith(() => { 133 Reflect.parse("var {a: /a/} = o;"); 134 }, "missing variable name, got regular expression literal"); 135 assertThrowsMsgEndsWith(() => { 136 Reflect.parse("var {a:} = o;"); 137 }, "missing variable name, got '}'"); 138 assertThrowsMsgEndsWith(() => { 139 Reflect.parse("var {a:1} = o;"); 140 }, "missing variable name, got numeric literal"); 141 assertThrowsMsgEndsWith(() => { 142 Reflect.parse("var {a:'a'} = o;"); 143 }, "missing variable name, got string literal"); 144 assertThrowsMsgEndsWith(() => { 145 Reflect.parse("var {a: , b} = o;"); 146 }, "missing variable name, got ','"); 147 assertThrowsMsgEndsWith(() => { 148 Reflect.parse("var {a: `template`} = o;"); 149 }, "missing variable name, got template literal"); 150 assertThrowsMsgEndsWith(() => { 151 Reflect.parse("var {a: ()=>10} = o;"); 152 }, "missing variable name, got '('"); 153 assertThrowsMsgEndsWith(() => { 154 Reflect.parse("var {a: !true} = o;"); 155 }, "missing variable name, got '!'"); 156 assertThrowsMsgEndsWith(() => { 157 Reflect.parse("var [/a/] = [];"); 158 }, "missing variable name, got '/'"); 159 assertThrowsMsgEndsWith(() => { 160 Reflect.parse("var [1] = [];"); 161 }, "missing variable name, got numeric literal"); 162 assertThrowsMsgEndsWith(() => { 163 Reflect.parse("var [, 1] = [];"); 164 }, "missing variable name, got numeric literal"); 165 assertThrowsMsgEndsWith(() => { 166 Reflect.parse("var {a: [{b: 'str'}]} = o;"); 167 }, "missing variable name, got string literal"); 168 assertThrowsMsgEndsWith(() => { 169 Reflect.parse("var {a: 10n} = o;"); 170 }, "missing variable name, got bigint literal"); 171 assertThrowsMsgEndsWith(() => { 172 Reflect.parse("var { [10]: 10 } = o;"); 173 }, "missing variable name, got numeric literal"); 174 assertThrowsMsgEndsWith(() => { 175 Reflect.parse("var {...42} = o;"); 176 }, "missing variable name, got numeric literal"); 177 178 assertThrowsMsgEndsWith(() => { 179 Reflect.parse("var { [propName]: } = o;"); 180 }, "missing variable name, got '}'"); 181 182 assertThrowsMsgEndsWith(() => { 183 Reflect.parse("var {f(): x = 10} = 0"); 184 }, "missing variable name, got identifier");