syntax.js (22697B)
1 // |jit-test| skip-if: !getBuildConfiguration("explicit-resource-management"); --enable-explicit-resource-management 2 3 load(libdir + "asserts.js"); 4 5 // Valid `using` syntaxes 6 Reflect.parse("{ using x = {} }"); 7 Reflect.parse("using x = {}", { target: "module" }); 8 Reflect.parse("{ using x = fn() }"); 9 Reflect.parse("{ using x = fn(); }"); 10 Reflect.parse("function f() { using x = fn(); }"); 11 Reflect.parse("if (x == 1) { using x = fn(); }"); 12 Reflect.parse("for (let i = 0; i < 10; i++) { using x = fn(); }"); 13 Reflect.parse("for (const i of [1, 2, 3]) { using x = fn(); }"); 14 Reflect.parse("for (const i in {a: 1, b: 2}) { using x = fn(); }"); 15 Reflect.parse("function* gen() { using x = fn(); }"); 16 Reflect.parse("async function* fn() { using x = fn(); }"); 17 Reflect.parse("async function fn() { using x = fn(); }"); 18 Reflect.parse("class xyz { static { using x = fn(); } }"); 19 Reflect.parse("{ using a = fn1(), b = fn2(); }"); 20 Reflect.parse("{ using x = null }"); 21 Reflect.parse("{ using x = undefined }"); 22 Reflect.parse("{ for (using x of y) {} }"); 23 Reflect.parse("for (using x of y) {}"); 24 Reflect.parse("for (using x = y;;) {}"); 25 Reflect.parse("for await (using x of y) {}", { target: "module" }); 26 Reflect.parse("async function fn() { for await (using x of y) {} }"); 27 28 const ast = Reflect.parse("{ using x = {} }"); 29 assertEq(ast.body[0].body[0].type, "VariableDeclaration"); 30 assertEq(ast.body[0].body[0].kind, "using"); 31 assertEq(ast.body[0].body[0].declarations[0].type, "VariableDeclarator"); 32 assertEq(ast.body[0].body[0].declarations[0].id.name, "x"); 33 34 const ast2 = Reflect.parse("for (using x of y) {}"); 35 assertEq(ast2.body[0].type, "ForOfStatement"); 36 assertEq(ast2.body[0].left.type, "VariableDeclaration"); 37 assertEq(ast2.body[0].left.kind, "using"); 38 assertEq(ast2.body[0].left.declarations[0].type, "VariableDeclarator"); 39 assertEq(ast2.body[0].left.declarations[0].id.type, "Identifier"); 40 assertEq(ast2.body[0].left.declarations[0].id.name, "x"); 41 42 const ast3 = Reflect.parse("async function fn() { for await (using x of y) {} }"); 43 const forStatement = ast3.body[0].body.body[0]; 44 assertEq(forStatement.type, "ForOfStatement"); 45 assertEq(forStatement.left.type, "VariableDeclaration"); 46 assertEq(forStatement.left.kind, "using"); 47 assertEq(forStatement.left.declarations[0].type, "VariableDeclarator"); 48 assertEq(forStatement.left.declarations[0].id.type, "Identifier"); 49 assertEq(forStatement.left.declarations[0].id.name, "x"); 50 51 // Valid `await using` syntaxes 52 Reflect.parse("await using x = {}", { target: "module" }); 53 Reflect.parse("if (x == 1) { await using x = fn(); }", { target: "module" }); 54 Reflect.parse("async function fn() { await using x = {}; }"); 55 Reflect.parse("async function* gen() { await using x = {}; }"); 56 Reflect.parse("for (let i = 0; i < 10; i++) { await using x = fn(); }", { target: "module" }); 57 Reflect.parse("for (const i of [1, 2, 3]) { await using x = fn(); }", { target: "module" }); 58 Reflect.parse("for (const i in {a: 1, b: 2}) { await using x = fn(); }", { target: "module" }); 59 Reflect.parse("for (await using x of y) {}", { target: "module" }); 60 Reflect.parse("for await (await using x of y) {}", { target: "module" }); 61 Reflect.parse("async function fn() { for (await using x of y) {} }"); 62 Reflect.parse("async function fn() { for await (await using x of y) {} }"); 63 64 const ast16 = Reflect.parse("await using x = {}", { target: "module" }); 65 assertEq(ast16.body[0].type, "VariableDeclaration"); 66 assertEq(ast16.body[0].kind, "await using"); 67 assertEq(ast16.body[0].declarations[0].type, "VariableDeclarator"); 68 assertEq(ast16.body[0].declarations[0].id.name, "x"); 69 70 const ast17 = Reflect.parse("for (await using x of y) {}", { target: "module" }); 71 assertEq(ast17.body[0].type, "ForOfStatement"); 72 assertEq(ast17.body[0].left.type, "VariableDeclaration"); 73 assertEq(ast17.body[0].left.kind, "await using"); 74 assertEq(ast17.body[0].left.declarations[0].type, "VariableDeclarator"); 75 assertEq(ast17.body[0].left.declarations[0].id.type, "Identifier"); 76 assertEq(ast17.body[0].left.declarations[0].id.name, "x"); 77 78 const ast18 = Reflect.parse("for await (await using x of y) {}", { target: "module" }); 79 assertEq(ast18.body[0].type, "ForOfStatement"); 80 assertEq(ast18.body[0].left.type, "VariableDeclaration"); 81 assertEq(ast18.body[0].left.kind, "await using"); 82 assertEq(ast18.body[0].left.declarations[0].type, "VariableDeclarator"); 83 assertEq(ast18.body[0].left.declarations[0].id.type, "Identifier"); 84 assertEq(ast18.body[0].left.declarations[0].id.name, "x"); 85 86 // Invalid `using` syntaxes 87 assertThrowsInstanceOf(() => Reflect.parse("using x = {}"), SyntaxError); 88 assertThrowsInstanceOf(() => Reflect.parse("{ const using x = fn() }"), SyntaxError); 89 assertThrowsInstanceOf(() => Reflect.parse("{ let using x = fn() }"), SyntaxError); 90 assertThrowsInstanceOf(() => Reflect.parse("{ var using x = fn() }"), SyntaxError); 91 assertThrowsInstanceOf(() => Reflect.parse("{ using const x = fn() }"), SyntaxError); 92 assertThrowsInstanceOf(() => Reflect.parse("{ using let x = fn() }"), SyntaxError); 93 assertThrowsInstanceOf(() => Reflect.parse("{ using var x = fn() }"), SyntaxError); 94 assertThrowsInstanceOf(() => Reflect.parse("{ using x = fn(), x = fn() }"), SyntaxError); 95 assertThrowsInstanceOf(() => Reflect.parse("for (using x in y) {}"), SyntaxError); 96 assertThrowsInstanceOf(() => Reflect.parse("for (using\nx of y) {}"), SyntaxError); 97 assertThrowsInstanceOf(() => Reflect.parse("for (using of of y) {}"), SyntaxError); 98 assertThrowsInstanceOf(() => Reflect.parse("{ using /a/; }"), SyntaxError); 99 assertThrowsInstanceOf(() => Reflect.parse("for (using /a/g of y) {}"), SyntaxError); 100 assertThrowsInstanceOf(() => Reflect.parse("if(1) using x = {}"), SyntaxError); 101 assertThrowsInstanceOf(() => Reflect.parse("for (;;) using x = 10;"), SyntaxError); 102 assertThrowsInstanceOf(() => Reflect.parse("foo: using x = 10;"), SyntaxError); 103 assertThrowsInstanceOf(() => Reflect.parse("export using x = 10", { target: "module" }), SyntaxError); 104 assertThrowsInstanceOf(() => Reflect.parse("{ using a }"), SyntaxError); 105 assertThrowsInstanceOf(() => Reflect.parse("{ using a, b }"), SyntaxError); 106 assertThrowsInstanceOf(() => Reflect.parse("switch (x) { case 1: using x = fn(); }"), SyntaxError); 107 assertThrowsInstanceOf(() => Reflect.parse("switch (x) { case 1: break; default: using x = fn(); }"), SyntaxError); 108 109 // Invalid `await using` syntaxes 110 assertThrowsInstanceOf(() => Reflect.parse("{ await using }"), SyntaxError); 111 assertThrowsInstanceOf(() => Reflect.parse("await using x = fn(), x = fn()", { target: "module" }), SyntaxError); 112 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { await using x = fn(), x = fn(); }"), SyntaxError); 113 assertThrowsInstanceOf(() => Reflect.parse("for (await using x in y) {}", { target: "module" }), SyntaxError); 114 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (await using x in y) {} }"), SyntaxError); 115 assertThrowsInstanceOf(() => Reflect.parse("for (await using\nx of y) {}", { target: "module" }), SyntaxError); 116 assertThrowsInstanceOf(() => Reflect.parse("for (await\nusing x of y) {}", { target: "module" }), SyntaxError); 117 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (await\nusing x of y) {} }"), SyntaxError); 118 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (await using\nx of y) {} }"), SyntaxError); 119 assertThrowsInstanceOf(() => Reflect.parse("for (await using;;) {}"), SyntaxError); 120 assertThrowsInstanceOf(() => Reflect.parse("await using /a/;", { target: "module" }), SyntaxError); 121 assertThrowsInstanceOf(() => Reflect.parse("for (await using /a/g of y) {}", { target: "module" }), SyntaxError); 122 assertThrowsInstanceOf(() => Reflect.parse("if(1) await using x = {}", { target: "module" }), SyntaxError); 123 assertThrowsInstanceOf(() => Reflect.parse("for (;;) await using x = 10;", { target: "module" }), SyntaxError); 124 assertThrowsInstanceOf(() => Reflect.parse("foo: await using x = 10;", { target: "module" }), SyntaxError); 125 assertThrowsInstanceOf(() => Reflect.parse("export await using x = 10", { target: "module" }), SyntaxError); 126 assertThrowsInstanceOf(() => Reflect.parse("for (await using [x,y] of z) {}", { target: "module" }), SyntaxError); 127 assertThrowsInstanceOf(() => Reflect.parse("for (await using {x,y} of z) {}", { target: "module" }), SyntaxError); 128 assertThrowsInstanceOf(() => Reflect.parse("{ await using a }", { target: "module" }), SyntaxError); 129 assertThrowsInstanceOf(() => Reflect.parse("{ await using a, b }", { target: "module" }), SyntaxError); 130 assertThrowsInstanceOf(() => Reflect.parse("switch (x) { case 1: await using x = fn(); }", { target: "module" }), SyntaxError); 131 assertThrowsInstanceOf(() => Reflect.parse("switch (x) { case 1: break; default: await using x = fn(); }", { target: "module" }), SyntaxError); 132 133 // Valid usage of `using` syntax with contextual keywords 134 Reflect.parse("{ using await = {}; }"); 135 Reflect.parse("{ using yield = {}; }"); 136 Reflect.parse("{ using public = {}; }"); 137 Reflect.parse("{ using private = {}; }"); 138 Reflect.parse("{ using protected = {}; }"); 139 Reflect.parse("{ using static = {}; }"); 140 Reflect.parse("{ using as = {}; }"); 141 Reflect.parse("{ using async = {}; }"); 142 Reflect.parse("{ using implements = {}; }"); 143 Reflect.parse("{ using interface = {}; }"); 144 Reflect.parse("{ using package = {}; }"); 145 Reflect.parse("'use strict'; { using await = {}; }"); 146 Reflect.parse("for (using await of y) {}"); 147 Reflect.parse("for (using yield of y) {}"); 148 Reflect.parse("for (using of = null;;) {}"); 149 Reflect.parse("using async = {};", { target: "module" }); 150 Reflect.parse("await using async = {};", { target: "module" }); 151 Reflect.parse("async function fn() { using async = {}; }"); 152 153 // Valid usage of `await using` syntax with contextual keywords. 154 Reflect.parse("async function fn() { await using yield = {} }"); 155 Reflect.parse("async function fn() { await using public = {} }"); 156 Reflect.parse("async function fn() { await using private = {} }"); 157 Reflect.parse("async function fn() { await using protected = {} }"); 158 Reflect.parse("async function fn() { await using static = {} }"); 159 Reflect.parse("async function fn() { await using as = {} }"); 160 Reflect.parse("async function fn() { await using async = {} }"); 161 Reflect.parse("async function fn() { await using implements = {} }"); 162 Reflect.parse("async function fn() { await using package = {}; }"); 163 Reflect.parse("await using as = {}", { target: "module" }); 164 Reflect.parse("await using async = {};", { target: "module" }); 165 Reflect.parse("for (await using of of y) {}", { target: "module" }) 166 Reflect.parse("async () => { for (await using of = 0;;) {} }"); 167 Reflect.parse("for (await using of = 0;;) {}", { target: "module" }); 168 169 // Invalid usage of `using` syntax with contextual keywords. 170 assertThrowsInstanceOf(() => Reflect.parse("{ using let = {} }"), SyntaxError); 171 assertThrowsInstanceOf(() => Reflect.parse("using await = {}", { target: "module" }), SyntaxError); 172 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { using await = {}; }"), SyntaxError); 173 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (using await of y) {} }"), SyntaxError); 174 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using yield = {}; }"), SyntaxError); 175 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using public = {}; }"), SyntaxError); 176 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using private = {}; }"), SyntaxError); 177 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using protected = {}; }"), SyntaxError); 178 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using static = {}; }"), SyntaxError); 179 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using implements = {}; }"), SyntaxError); 180 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using interface = {}; }"), SyntaxError); 181 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; { using package = {}; }"), SyntaxError); 182 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; for (using yield of y) {}"), SyntaxError); 183 assertThrowsInstanceOf(() => Reflect.parse("function* gen() { using yield = {}; }"), SyntaxError); 184 assertThrowsInstanceOf(() => Reflect.parse("for (using await of y) {}", { target: "module" }), SyntaxError); 185 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (using await of y) {} }"), SyntaxError); 186 assertThrowsInstanceOf(() => Reflect.parse("function* gen() { for (using yield of y) {} }"), SyntaxError); 187 assertThrowsInstanceOf(() => Reflect.parse("for (using of;;) {}"), SyntaxError); 188 assertThrowsInstanceOf(() => Reflect.parse("for (using of = 0 in {}) {}"), SyntaxError); 189 assertThrowsInstanceOf(() => Reflect.parse("for (using\nof = null;;) {}"), SyntaxError); 190 191 // Invalid usage of `await using` syntax with contextual keywords. 192 assertThrowsInstanceOf(() => Reflect.parse("await using yield = {};", { target: "module" }), SyntaxError); 193 assertThrowsInstanceOf(() => Reflect.parse("await using public = {};", { target: "module" }), SyntaxError); 194 assertThrowsInstanceOf(() => Reflect.parse("await using private = {};", { target: "module" }), SyntaxError); 195 assertThrowsInstanceOf(() => Reflect.parse("await using protected = {};", { target: "module" }), SyntaxError); 196 assertThrowsInstanceOf(() => Reflect.parse("await using static = {};", { target: "module" }), SyntaxError); 197 assertThrowsInstanceOf(() => Reflect.parse("await using implements = {};", { target: "module" }), SyntaxError); 198 assertThrowsInstanceOf(() => Reflect.parse("await using interface = {};", { target: "module" }), SyntaxError); 199 assertThrowsInstanceOf(() => Reflect.parse("await using package = {};", { target: "module" }), SyntaxError); 200 assertThrowsInstanceOf(() => Reflect.parse("await using await = {};", { target: "module" }), SyntaxError); 201 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { await using await = {} }"), SyntaxError); 202 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using await = {} }"), SyntaxError); 203 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using yield = {} }"), SyntaxError); 204 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using public = {} }"), SyntaxError); 205 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using private = {} }"), SyntaxError); 206 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using protected = {} }"), SyntaxError); 207 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using static = {} }"), SyntaxError); 208 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using implements = {} }"), SyntaxError); 209 assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async function fn() { await using package = {} }"), SyntaxError); 210 assertThrowsInstanceOf(() => Reflect.parse("async function* gen() { await using yield = {}; } "), SyntaxError); 211 assertThrowsInstanceOf(() => Reflect.parse("async function fn() { for (await using await of y) {} }"), SyntaxError); 212 assertThrowsInstanceOf(() => Reflect.parse("async function* gen() { for (await using yield of y) {} }"), SyntaxError); 213 assertThrowsInstanceOf(() => Reflect.parse("async () => { for (await using of;;) {} }"), SyntaxError); 214 assertThrowsInstanceOf(() => Reflect.parse("async () => { for await (using of = 0;;) {} }"), SyntaxError); 215 216 // Valid syntaxes close to `using` but not `using` declarations. 217 Reflect.parse("for (using of y) {}"); 218 Reflect.parse("for (using of of) {}"); 219 Reflect.parse("for (using\nof y) {}"); 220 Reflect.parse("{ const using = 10; }"); 221 Reflect.parse("{ let using = 10 }"); 222 Reflect.parse("{ var using = 10 }"); 223 Reflect.parse("{ using = 10 }"); 224 Reflect.parse("{ using + 1 }"); 225 Reflect.parse("{ using++ }"); 226 Reflect.parse("{ using\nx = 10 }"); 227 Reflect.parse("{ using = {x: 10} }"); 228 Reflect.parse("{ x = { using: 10 } }"); 229 Reflect.parse("{ x.using = 10 }"); 230 Reflect.parse("{ x\n.using = 10 }"); 231 Reflect.parse("{ using.x = 10 }"); 232 Reflect.parse("{ using\n.x = 10 }"); 233 Reflect.parse("for (using[1] of {}) {}"); 234 Reflect.parse("for (using\n[1] of {}) {}") 235 Reflect.parse("for (using.x of {}) {}"); 236 Reflect.parse("for (using\n.x of {}) {}"); 237 Reflect.parse("for (x.using in {}) {}"); 238 Reflect.parse("for (x\n.using in {}) {}") 239 Reflect.parse("{ using: x = 10; }"); 240 Reflect.parse("{ using\n: x = 10; }"); 241 Reflect.parse("{ using /a/g; }"); 242 Reflect.parse("{ /using/g }"); 243 Reflect.parse("{ using\nlet = {} }"); 244 Reflect.parse("export const using = 10", { target: "module" }); 245 Reflect.parse("import using from 'xyz'", { target: "module" }); 246 Reflect.parse("switch (x) { case 1: using: fn(); }"); 247 Reflect.parse("switch (x) { case 1: break; default: using: fn(); }"); 248 249 const ast4 = Reflect.parse("{ using = 10 }"); 250 assertEq(ast4.body[0].body[0].type, "ExpressionStatement"); 251 assertEq(ast4.body[0].body[0].expression.type, "AssignmentExpression"); 252 assertEq(ast4.body[0].body[0].expression.left.type, "Identifier"); 253 assertEq(ast4.body[0].body[0].expression.left.name, "using"); 254 255 const ast5 = Reflect.parse("for (using of y) {}"); 256 assertEq(ast5.body[0].type, "ForOfStatement"); 257 assertEq(ast5.body[0].left.type, "Identifier"); 258 assertEq(ast5.body[0].left.name, "using"); 259 260 const ast6 = Reflect.parse("{ using + 1 }"); 261 assertEq(ast6.body[0].body[0].type, "ExpressionStatement"); 262 assertEq(ast6.body[0].body[0].expression.type, "BinaryExpression"); 263 assertEq(ast6.body[0].body[0].expression.left.type, "Identifier"); 264 assertEq(ast6.body[0].body[0].expression.left.name, "using"); 265 266 const ast7 = Reflect.parse("for (using of of) {}"); 267 assertEq(ast7.body[0].type, "ForOfStatement"); 268 assertEq(ast7.body[0].left.type, "Identifier"); 269 assertEq(ast7.body[0].left.name, "using"); 270 assertEq(ast7.body[0].right.type, "Identifier"); 271 assertEq(ast7.body[0].right.name, "of"); 272 273 const ast8 = Reflect.parse("for (using\nof y) {}"); 274 assertEq(ast8.body[0].type, "ForOfStatement"); 275 assertEq(ast8.body[0].left.type, "Identifier"); 276 assertEq(ast8.body[0].left.name, "using"); 277 assertEq(ast8.body[0].right.type, "Identifier"); 278 assertEq(ast8.body[0].right.name, "y"); 279 280 const ast9 = Reflect.parse("for (using[1] of {}) {}"); 281 assertEq(ast9.body[0].type, "ForOfStatement"); 282 assertEq(ast9.body[0].left.type, "MemberExpression"); 283 assertEq(ast9.body[0].left.object.type, "Identifier"); 284 assertEq(ast9.body[0].left.object.name, "using"); 285 assertEq(ast9.body[0].left.property.type, "Literal"); 286 assertEq(ast9.body[0].left.property.value, 1); 287 288 const ast10 = Reflect.parse("for (using\n[1] of {}) {}"); 289 assertEq(ast10.body[0].type, "ForOfStatement"); 290 assertEq(ast10.body[0].left.type, "MemberExpression"); 291 assertEq(ast10.body[0].left.object.type, "Identifier"); 292 assertEq(ast10.body[0].left.object.name, "using"); 293 assertEq(ast10.body[0].left.property.type, "Literal"); 294 assertEq(ast10.body[0].left.property.value, 1); 295 296 const ast11 = Reflect.parse("{ /using/g }"); 297 assertEq(ast11.body[0].body[0].type, "ExpressionStatement"); 298 assertEq(ast11.body[0].body[0].expression.type, "Literal"); 299 assertEq(ast11.body[0].body[0].expression.value.source, "using"); 300 assertEq(ast11.body[0].body[0].expression.value.flags, "g"); 301 302 const ast12 = Reflect.parse("{ using: x = 10; }"); 303 assertEq(ast12.body[0].body[0].type, "LabeledStatement"); 304 assertEq(ast12.body[0].body[0].label.type, "Identifier"); 305 assertEq(ast12.body[0].body[0].label.name, "using"); 306 307 const ast13 = Reflect.parse("{ using\n: x = 10; }"); 308 assertEq(ast13.body[0].body[0].type, "LabeledStatement"); 309 assertEq(ast13.body[0].body[0].label.type, "Identifier"); 310 assertEq(ast13.body[0].body[0].label.name, "using"); 311 312 const ast14 = Reflect.parse("{ using /a/g; }"); 313 // should be parsed as division, not regex 314 assertEq(ast14.body[0].body[0].type, "ExpressionStatement"); 315 assertEq(ast14.body[0].body[0].expression.type, "BinaryExpression"); 316 assertEq(ast14.body[0].body[0].expression.operator, "/"); 317 assertEq(ast14.body[0].body[0].expression.left.type, "BinaryExpression"); 318 assertEq(ast14.body[0].body[0].expression.left.operator, "/"); 319 320 const ast15 = Reflect.parse("import using from 'xyz'", { target: "module" }); 321 assertEq(ast15.body[0].type, "ImportDeclaration"); 322 assertEq(ast15.body[0].specifiers[0].type, "ImportSpecifier"); 323 assertEq(ast15.body[0].specifiers[0].name.name, "using"); 324 325 // Valid syntaxes close to `await using` but not `await using` declarations. 326 Reflect.parse("await /xyz/g"); 327 Reflect.parse("{ await /using/g }"); 328 Reflect.parse("async function fn() { await using; }"); 329 Reflect.parse("async function fn() { await\nusing; }") 330 Reflect.parse("async function fn() { await /using/g }"); 331 Reflect.parse("async function fn() { await using/g }"); 332 Reflect.parse("async function fn() { await using/\ng }"); 333 Reflect.parse("async function fn() { for(await using;;) {} }"); 334 Reflect.parse("await using;", { target: "module" }); 335 Reflect.parse("await\nusing;", { target: "module" }); 336 Reflect.parse("await /using/g", { target: "module" }); 337 Reflect.parse("await using/g", { target: "module" }); 338 Reflect.parse("await using/\ng", { target: "module" }); 339 Reflect.parse("for(await using;;) {}", { target: "module" }); 340 Reflect.parse("await using\nx;", { target: "module" }); 341 342 const ast19 = Reflect.parse("await using", { target: "module" }); 343 assertEq(ast19.body[0].type, "ExpressionStatement"); 344 assertEq(ast19.body[0].expression.type, "UnaryExpression"); 345 assertEq(ast19.body[0].expression.operator, "await"); 346 assertEq(ast19.body[0].expression.argument.type, "Identifier"); 347 assertEq(ast19.body[0].expression.argument.name, "using"); 348 349 const ast20 = Reflect.parse("await /using/g", { target: "module" }); 350 assertEq(ast20.body[0].type, "ExpressionStatement"); 351 assertEq(ast20.body[0].expression.type, "UnaryExpression"); 352 assertEq(ast20.body[0].expression.operator, "await"); 353 assertEq(ast20.body[0].expression.argument.type, "Literal"); 354 assertEq(ast20.body[0].expression.argument.value.source, "using"); 355 assertEq(ast20.body[0].expression.argument.value.flags, "g"); 356 357 const ast21 = Reflect.parse("await using/g", { target: "module" }); 358 assertEq(ast21.body[0].type, "ExpressionStatement"); 359 assertEq(ast21.body[0].expression.type, "BinaryExpression"); 360 assertEq(ast21.body[0].expression.operator, "/"); 361 assertEq(ast21.body[0].expression.left.type, "UnaryExpression"); 362 assertEq(ast21.body[0].expression.left.operator, "await"); 363 assertEq(ast21.body[0].expression.left.argument.type, "Identifier"); 364 assertEq(ast21.body[0].expression.left.argument.name, "using"); 365 366 const ast22 = Reflect.parse("for(await using;;) {}", { target: "module" }); 367 assertEq(ast22.body[0].type, "ForStatement"); 368 assertEq(ast22.body[0].init.type, "UnaryExpression"); 369 assertEq(ast22.body[0].init.operator, "await"); 370 assertEq(ast22.body[0].init.argument.type, "Identifier"); 371 assertEq(ast22.body[0].init.argument.name, "using");