syntax.js (32255B)
1 function test_syntax(postfixes, check_error, ignore_opts) { 2 function test_reflect(code, module) { 3 var options = undefined; 4 if (module) { 5 options = {target: "module"}; 6 } 7 for (var postfix of postfixes) { 8 var cur_code = code + postfix; 9 10 var caught = false; 11 try { 12 Reflect.parse(cur_code, options); 13 } catch (e) { 14 caught = true; 15 check_error(e, cur_code, "reflect"); 16 } 17 assertEq(caught, true); 18 } 19 } 20 21 function test_eval(code) { 22 for (var postfix of postfixes) { 23 var cur_code = code + postfix; 24 25 var caught = false; 26 try { 27 eval(cur_code); 28 } catch (e) { 29 caught = true; 30 check_error(e, cur_code, "eval"); 31 } 32 assertEq(caught, true); 33 } 34 } 35 36 function test(code, opts={}) { 37 if (ignore_opts) { 38 opts = {}; 39 } 40 41 let no_strict = "no_strict" in opts && opts.no_strict; 42 let no_fun = "no_fun" in opts && opts.no_fun; 43 let no_eval = "no_eval" in opts && opts.no_eval; 44 let module = "module" in opts && opts.module; 45 46 test_reflect(code, module); 47 if (!no_strict) { 48 test_reflect("'use strict'; " + code, module); 49 } 50 if (!no_fun) { 51 test_reflect("(function() { " + code, module); 52 if (!no_strict) { 53 test_reflect("(function() { 'use strict'; " + code, module); 54 } 55 } 56 57 if (!no_eval) { 58 test_eval(code); 59 if (!no_strict) { 60 test_eval("'use strict'; " + code); 61 } 62 if (!no_fun) { 63 test_eval("(function() { " + code); 64 if (!no_strict) { 65 test_eval("(function() { 'use strict'; " + code); 66 } 67 } 68 } 69 } 70 71 function test_fun_arg(arg) { 72 for (var postfix of postfixes) { 73 var cur_arg = arg + postfix; 74 75 var caught = false; 76 try { 77 new Function(cur_arg, ""); 78 } catch (e) { 79 caught = true; 80 check_error(e, cur_arg, "fun_arg"); 81 } 82 assertEq(caught, true); 83 } 84 } 85 86 // ==== Statements and declarations ==== 87 88 // ---- Control flow ---- 89 90 // Block 91 92 test("{ "); 93 test("{ } "); 94 95 test("{ 1 "); 96 test("{ 1; "); 97 test("{ 1; } "); 98 99 // break 100 101 test("a: for (;;) { break "); 102 test("a: for (;;) { break; "); 103 test("a: for (;;) { break a "); 104 test("a: for (;;) { break a; "); 105 106 test("a: for (;;) { break\n"); 107 108 // continue 109 110 test("a: for (;;) { continue "); 111 test("a: for (;;) { continue; "); 112 test("a: for (;;) { continue a "); 113 test("a: for (;;) { continue a; "); 114 115 test("a: for (;;) { continue\n"); 116 117 // Empty 118 119 test(""); 120 test("; "); 121 122 // if...else 123 124 test("if "); 125 test("if ("); 126 test("if (x "); 127 test("if (x) "); 128 test("if (x) { "); 129 test("if (x) {} "); 130 test("if (x) {} else "); 131 test("if (x) {} else { "); 132 test("if (x) {} else {} "); 133 test("if (x) x "); 134 test("if (x) x; "); 135 test("if (x) x; else "); 136 test("if (x) x; else y "); 137 test("if (x) x; else y; "); 138 139 // switch 140 141 test("switch "); 142 test("switch ("); 143 test("switch (x "); 144 test("switch (x) "); 145 test("switch (x) { "); 146 test("switch (x) { case "); 147 test("switch (x) { case 1 "); 148 test("switch (x) { case 1: "); 149 test("switch (x) { case 1: case "); 150 test("switch (x) { case 1: case 2 "); 151 test("switch (x) { case 1: case 2: "); 152 test("switch (x) { case 1: case 2: x "); 153 test("switch (x) { case 1: case 2: x; "); 154 test("switch (x) { case 1: case 2: x; break "); 155 test("switch (x) { case 1: case 2: x; break; "); 156 test("switch (x) { case 1: case 2: x; break; case "); 157 test("switch (x) { case 1: case 2: x; break; case 3 "); 158 test("switch (x) { case 1: case 2: x; break; case 3: y "); 159 test("switch (x) { case 1: case 2: x; break; case 3: y; "); 160 test("switch (x) { case 1: case 2: x; break; case 3: y; default "); 161 test("switch (x) { case 1: case 2: x; break; case 3: y; default: "); 162 test("switch (x) { case 1: case 2: x; break; case 3: y; default: z "); 163 test("switch (x) { case 1: case 2: x; break; case 3: y; default: z; "); 164 test("switch (x) { case 1: case 2: x; break; case 3: y; default: z; } "); 165 166 // throw 167 168 test("throw "); 169 test("throw x "); 170 test("throw x; "); 171 172 // try...catch 173 174 test("try "); 175 test("try { "); 176 test("try {} "); 177 test("try {} catch "); 178 test("try {} catch ( "); 179 test("try {} catch (e "); 180 test("try {} catch (e) "); 181 test("try {} catch (e) { "); 182 test("try {} catch (e) {} "); 183 test("try {} catch (e) {} finally "); 184 test("try {} catch (e) {} finally { "); 185 test("try {} catch (e) {} finally {} "); 186 187 // ---- Declarations ---- 188 189 // var 190 191 test("var "); 192 test("var x "); 193 test("var x = "); 194 test("var x = 1 "); 195 test("var x = 1 + "); 196 test("var x = 1 + 2 "); 197 test("var x = 1 + 2, "); 198 test("var x = 1 + 2, y "); 199 test("var x = 1 + 2, y, "); 200 test("var x = 1 + 2, y, z "); 201 test("var x = 1 + 2, y, z; "); 202 203 test("var [ "); 204 test("var [ x "); 205 test("var [ x, "); 206 test("var [ x, ... "); 207 test("var { "); 208 test("var { x "); 209 test("var { x: "); 210 test("var { x: y "); 211 test("var { x: y, "); 212 test("var { x: y } "); 213 test("var { x: y } = "); 214 215 // let 216 217 test("let "); 218 test("let x "); 219 test("let x = "); 220 test("let x = 1 "); 221 test("let x = 1 + "); 222 test("let x = 1 + 2 "); 223 test("let x = 1 + 2, "); 224 test("let x = 1 + 2, y "); 225 test("let x = 1 + 2, y, "); 226 test("let x = 1 + 2, y, z "); 227 test("let x = 1 + 2, y, z; "); 228 229 test("let [ "); 230 test("let [ x "); 231 test("let [ x, "); 232 test("let [ x, ... "); 233 test("let { "); 234 test("let { x "); 235 test("let { x: "); 236 test("let { x: y "); 237 test("let { x: y, "); 238 test("let { x: y } "); 239 test("let { x: y } = "); 240 241 // const 242 243 test("const "); 244 test("const x "); 245 test("const x = "); 246 test("const x = 1 "); 247 test("const x = 1 + "); 248 test("const x = 1 + 2 "); 249 test("const x = 1 + 2, "); 250 test("const x = 1 + 2, y = 0"); 251 test("const x = 1 + 2, y = 0, "); 252 test("const x = 1 + 2, y = 0, z = 0 "); 253 test("const x = 1 + 2, y = 0, z = 0; "); 254 255 test("const [ "); 256 test("const [ x "); 257 test("const [ x, "); 258 test("const [ x, ... "); 259 test("const { "); 260 test("const { x "); 261 test("const { x: "); 262 test("const { x: y "); 263 test("const { x: y, "); 264 test("const { x: y } "); 265 test("const { x: y } = "); 266 267 // ---- Functions ---- 268 269 // function 270 271 test("function "); 272 test("function f "); 273 test("function f( "); 274 test("function f(x "); 275 test("function f(x, "); 276 test("function f(x, [ "); 277 test("function f(x, [y "); 278 test("function f(x, [y, "); 279 test("function f(x, [y, { "); 280 test("function f(x, [y, {z "); 281 test("function f(x, [y, {z: "); 282 test("function f(x, [y, {z: zz "); 283 test("function f(x, [y, {z: zz, "); 284 test("function f(x, [y, {z: zz, w "); 285 test("function f(x, [y, {z: zz, w} "); 286 test("function f(x, [y, {z: zz, w}] "); 287 test("function f(x, [y, {z: zz, w}], "); 288 test("function f(x, [y, {z: zz, w}], v "); 289 test("function f(x, [y, {z: zz, w}], v= "); 290 test("function f(x, [y, {z: zz, w}], v=1 "); 291 test("function f(x, [y, {z: zz, w}], v=1, "); 292 test("function f(x, [y, {z: zz, w}], v=1, ... "); 293 test("function f(x, [y, {z: zz, w}], v=1, ...t "); 294 test("function f(x, [y, {z: zz, w}], v=1, ...t) "); 295 test("function f(x, [y, {z: zz, w}], v=1, ...t) {"); 296 test("function f(x, [y, {z: zz, w}], v=1, ...t) { x "); 297 test("function f(x, [y, {z: zz, w}], v=1, ...t) { x; "); 298 test("function f(x, [y, {z: zz, w}], v=1, ...t) { x; } "); 299 300 // star function 301 302 test("function* "); 303 test("function* f "); 304 test("function* f( "); 305 test("function* f(x "); 306 test("function* f(x, "); 307 test("function* f(x, ... "); 308 test("function* f(x, ...t "); 309 test("function* f(x, ...t) "); 310 test("function* f(x, ...t) {"); 311 test("function* f(x, ...t) { x "); 312 test("function* f(x, ...t) { x; "); 313 test("function* f(x, ...t) { x; } "); 314 315 // return 316 317 test("function f() { return "); 318 test("function f() { return 1 "); 319 test("function f() { return 1; "); 320 test("function f() { return 1; } "); 321 test("function f() { return; "); 322 test("function f() { return\n"); 323 324 // yield 325 326 test("function* f() { yield "); 327 test("function* f() { yield 1 "); 328 test("function* f() { yield* "); 329 test("function* f() { yield* 1 "); 330 331 test("function* f() { yield\n"); 332 test("function* f() { yield*\n"); 333 334 // ---- Iterations ---- 335 336 // do...while 337 338 test("do "); 339 test("do {"); 340 test("do {} "); 341 test("do {} while "); 342 test("do {} while ( "); 343 test("do {} while (x "); 344 test("do {} while (x) "); 345 test("do {} while (x); "); 346 347 test("do x "); 348 test("do x; "); 349 test("do x; while "); 350 351 // for 352 353 test("for "); 354 test("for ("); 355 test("for (x "); 356 test("for (x; "); 357 test("for (x; y "); 358 test("for (x; y; "); 359 test("for (x; y; z "); 360 test("for (x; y; z) "); 361 test("for (x; y; z) { "); 362 test("for (x; y; z) {} "); 363 364 test("for (x; y; z) x "); 365 test("for (x; y; z) x; "); 366 367 test("for (var "); 368 test("for (var x "); 369 test("for (var x = "); 370 test("for (var x = y "); 371 test("for (var x = y; "); 372 373 test("for (let "); 374 test("for (let x "); 375 test("for (let x = "); 376 test("for (let x = y "); 377 test("for (let x = y; "); 378 379 // for...in 380 381 test("for (x in "); 382 test("for (x in y "); 383 test("for (x in y) "); 384 385 test("for (var x in "); 386 test("for (var x in y "); 387 test("for (var x in y) "); 388 389 test("for (let x in "); 390 test("for (let x in y "); 391 test("for (let x in y) "); 392 393 // for...of 394 395 test("for (x of "); 396 test("for (x of y "); 397 test("for (x of y) "); 398 399 test("for (var x of "); 400 test("for (var x of y "); 401 test("for (var x of y) "); 402 403 test("for (let x of "); 404 test("for (let x of y "); 405 test("for (let x of y) "); 406 407 // while 408 409 test("while "); 410 test("while ("); 411 test("while (x "); 412 test("while (x) "); 413 test("while (x) { "); 414 test("while (x) {} "); 415 416 test("while (x) x "); 417 test("while (x) x; "); 418 419 // ---- Others ---- 420 421 // debugger 422 423 test("debugger "); 424 test("debugger; "); 425 426 // export 427 428 var opts = { no_fun: true, no_eval: true, module: true }; 429 test("export ", opts); 430 test("export { ", opts); 431 test("export { x ", opts); 432 test("export { x, ", opts); 433 test("export { x, y ", opts); 434 test("export { x, y as ", opts); 435 test("export { x, y as z ", opts); 436 test("export { x, y as z } ", opts); 437 test("export { x, y as z } from ", opts); 438 test("export { x, y as z } from 'a' ", opts); 439 test("export { x, y as z } from 'a'; ", opts); 440 441 test("export * ", opts); 442 test("export * from ", opts); 443 test("export * from 'a' ", opts); 444 test("export * from 'a'; ", opts); 445 446 test("export * ", opts); 447 test("export * as ", opts); 448 test("export * as ns ", opts); 449 test("export * as ns from ", opts); 450 test("export * as ns from 'a' ", opts); 451 test("export * as ns from 'a'; ", opts); 452 453 test("export function ", opts); 454 test("export function f ", opts); 455 test("export function f( ", opts); 456 test("export function f() ", opts); 457 test("export function f() { ", opts); 458 test("export function f() {} ", opts); 459 test("export function f() {}; ", opts); 460 461 test("export var ", opts); 462 test("export var a ", opts); 463 test("export var a = ", opts); 464 test("export var a = 1 ", opts); 465 test("export var a = 1, ", opts); 466 test("export var a = 1, b ", opts); 467 test("export var a = 1, b = ", opts); 468 test("export var a = 1, b = 2 ", opts); 469 test("export var a = 1, b = 2; ", opts); 470 471 test("export let ", opts); 472 test("export let a ", opts); 473 test("export let a = ", opts); 474 test("export let a = 1 ", opts); 475 test("export let a = 1, ", opts); 476 test("export let a = 1, b ", opts); 477 test("export let a = 1, b = ", opts); 478 test("export let a = 1, b = 2 ", opts); 479 test("export let a = 1, b = 2; ", opts); 480 481 test("export const ", opts); 482 test("export const a ", opts); 483 test("export const a = ", opts); 484 test("export const a = 1 ", opts); 485 test("export const a = 1, ", opts); 486 test("export const a = 1, b ", opts); 487 test("export const a = 1, b = ", opts); 488 test("export const a = 1, b = 2 ", opts); 489 test("export const a = 1, b = 2; ", opts); 490 491 test("export class ", opts); 492 test("export class Foo ", opts); 493 test("export class Foo { ", opts); 494 test("export class Foo { constructor ", opts); 495 test("export class Foo { constructor( ", opts); 496 test("export class Foo { constructor() ", opts); 497 test("export class Foo { constructor() { ", opts); 498 test("export class Foo { constructor() {} ", opts); 499 test("export class Foo { constructor() {} } ", opts); 500 test("export class Foo { constructor() {} }; ", opts); 501 502 test("export default ", opts); 503 test("export default 1 ", opts); 504 test("export default 1; ", opts); 505 506 test("export default function ", opts); 507 test("export default function() ", opts); 508 test("export default function() { ", opts); 509 test("export default function() {} ", opts); 510 test("export default function() {}; ", opts); 511 512 test("export default function foo ", opts); 513 test("export default function foo( ", opts); 514 test("export default function foo() ", opts); 515 test("export default function foo() { ", opts); 516 test("export default function foo() {} ", opts); 517 test("export default function foo() {}; ", opts); 518 519 test("export default class ", opts); 520 test("export default class { ", opts); 521 test("export default class { constructor ", opts); 522 test("export default class { constructor( ", opts); 523 test("export default class { constructor() ", opts); 524 test("export default class { constructor() { ", opts); 525 test("export default class { constructor() {} ", opts); 526 test("export default class { constructor() {} } ", opts); 527 test("export default class { constructor() {} }; ", opts); 528 529 test("export default class Foo ", opts); 530 test("export default class Foo { ", opts); 531 test("export default class Foo { constructor ", opts); 532 test("export default class Foo { constructor( ", opts); 533 test("export default class Foo { constructor() ", opts); 534 test("export default class Foo { constructor() { ", opts); 535 test("export default class Foo { constructor() {} ", opts); 536 test("export default class Foo { constructor() {} } ", opts); 537 test("export default class Foo { constructor() {} }; ", opts); 538 539 // import 540 541 test("import ", opts); 542 test("import x ", opts); 543 test("import x from ", opts); 544 test("import x from 'a' ", opts); 545 test("import x from 'a'; ", opts); 546 547 test("import { ", opts); 548 test("import { x ", opts); 549 test("import { x, ", opts); 550 test("import { x, y ", opts); 551 test("import { x, y } ", opts); 552 test("import { x, y } from ", opts); 553 test("import { x, y } from 'a' ", opts); 554 test("import { x, y } from 'a'; ", opts); 555 556 test("import { x as ", opts); 557 test("import { x as y ", opts); 558 test("import { x as y } ", opts); 559 test("import { x as y } from ", opts); 560 test("import { x as y } from 'a' ", opts); 561 test("import { x as y } from 'a'; ", opts); 562 563 test("import 'a' ", opts); 564 test("import 'a'; ", opts); 565 566 test("import * ", opts); 567 test("import * as ", opts); 568 test("import * as a ", opts); 569 test("import * as a from ", opts); 570 test("import * as a from 'a' ", opts); 571 test("import * as a from 'a'; ", opts); 572 573 test("import a ", opts); 574 test("import a, ", opts); 575 test("import a, * ", opts); 576 test("import a, * as ", opts); 577 test("import a, * as b ", opts); 578 test("import a, * as b from ", opts); 579 test("import a, * as b from 'c' ", opts); 580 test("import a, * as b from 'c'; ", opts); 581 582 test("import a, { ", opts); 583 test("import a, { b ", opts); 584 test("import a, { b } ", opts); 585 test("import a, { b } from ", opts); 586 test("import a, { b } from 'c' ", opts); 587 test("import a, { b } from 'c'; ", opts); 588 589 // label 590 591 test("a "); 592 test("a: "); 593 594 // with 595 596 opts = { no_strict: true }; 597 test("with ", opts); 598 test("with (", opts); 599 test("with (x ", opts); 600 test("with (x) ", opts); 601 test("with (x) { ", opts); 602 test("with (x) {} ", opts); 603 604 test("with (x) x ", opts); 605 test("with (x) x; ", opts); 606 607 // ==== Expressions and operators ==== 608 609 // ---- Primary expressions ---- 610 611 // this 612 613 test("this "); 614 615 // function 616 617 test("(function "); 618 test("(function ( "); 619 test("(function (x "); 620 test("(function (x, "); 621 test("(function (x, ... "); 622 test("(function (x, ...t "); 623 test("(function (x, ...t) "); 624 test("(function (x, ...t) {"); 625 test("(function (x, ...t) { x "); 626 test("(function (x, ...t) { x; "); 627 test("(function (x, ...t) { x; } "); 628 test("(function (x, ...t) { x; }) "); 629 630 // star function 631 632 test("(function* "); 633 test("(function* ( "); 634 test("(function* (x "); 635 test("(function* (x, "); 636 test("(function* (x, ... "); 637 test("(function* (x, ...t "); 638 test("(function* (x, ...t) "); 639 test("(function* (x, ...t) {"); 640 test("(function* (x, ...t) { x "); 641 test("(function* (x, ...t) { x; "); 642 test("(function* (x, ...t) { x; } "); 643 test("(function* (x, ...t) { x; }) "); 644 645 // Array literal 646 647 test("[ "); 648 test("[] "); 649 test("[1 "); 650 test("[1, "); 651 test("[1, ... "); 652 test("[1, ...x "); 653 test("[1, ...x] "); 654 655 // object 656 657 test("({ "); 658 test("({ x "); 659 test("({ x: "); 660 test("({ x: 1 "); 661 test("({ x: 1, "); 662 test("({ x: 1, y "); 663 test("({ x: 1, y: "); 664 test("({ x: 1, y: 2 "); 665 test("({ x: 1, y: 2, "); 666 test("({ x: 1, y: 2, z "); 667 test("({ x: 1, y: 2, z, "); 668 test("({ x: 1, y: 2, z, w "); 669 test("({ x: 1, y: 2, z, w } "); 670 test("({ x: 1, y: 2, z, w }) "); 671 672 // object: computed property 673 674 test("({ ["); 675 test("({ [k "); 676 test("({ [k] "); 677 test("({ [k]: "); 678 test("({ [k]: 1 "); 679 test("({ [k]: 1, "); 680 681 // object: getter 682 683 test("({ get "); 684 test("({ get p "); 685 test("({ get p( "); 686 test("({ get p() "); 687 test("({ get p() { "); 688 test("({ get p() {} "); 689 test("({ get p() {}, "); 690 test("({ get p() {}, } "); 691 692 test("({ get [ "); 693 test("({ get [p "); 694 test("({ get [p] "); 695 test("({ get [p]( "); 696 test("({ get [p]() "); 697 698 // object: setter 699 700 test("({ set "); 701 test("({ set p "); 702 test("({ set p( "); 703 test("({ set p(v "); 704 test("({ set p(v) "); 705 test("({ set p(v) { "); 706 test("({ set p(v) {} "); 707 708 test("({ set [ "); 709 test("({ set [p "); 710 test("({ set [p] "); 711 test("({ set [p]( "); 712 test("({ set [p](v "); 713 test("({ set [p](v) "); 714 715 // object: method 716 717 test("({ m "); 718 test("({ m( "); 719 test("({ m() "); 720 test("({ m() { "); 721 test("({ m() {} "); 722 test("({ m() {}, "); 723 724 test("({ [ "); 725 test("({ [m "); 726 test("({ [m] "); 727 test("({ [m]( "); 728 test("({ [m]() "); 729 test("({ [m]() { "); 730 test("({ [m]() {} "); 731 test("({ [m]() {}, "); 732 733 test("({ * "); 734 test("({ *m "); 735 test("({ *m( "); 736 test("({ *m() "); 737 test("({ *m() { "); 738 test("({ *m() {} "); 739 test("({ *m() {}, "); 740 741 test("({ *[ "); 742 test("({ *[m "); 743 test("({ *[m] "); 744 test("({ *[m]( "); 745 test("({ *[m]() "); 746 test("({ *[m]() { "); 747 test("({ *[m]() {} "); 748 test("({ *[m]() {}, "); 749 750 test("({ * get "); 751 test("({ * get ( "); 752 test("({ * get () "); 753 test("({ * get () { "); 754 test("({ * get () {} "); 755 test("({ * get () {}, "); 756 757 test("({ * set "); 758 test("({ * set ( "); 759 test("({ * set () "); 760 test("({ * set () { "); 761 test("({ * set () {} "); 762 test("({ * set () {}, "); 763 764 // Regular expression literal 765 766 test("/a/ "); 767 test("/a/g "); 768 769 // ---- Left-hand-side expressions ---- 770 771 // property access 772 773 test("a[ "); 774 test("a[1 "); 775 test("a[1] "); 776 777 test("a. "); 778 test("a.b "); 779 test("a.b; "); 780 781 // new 782 783 test("new "); 784 test("new f "); 785 test("new f( "); 786 test("new f() "); 787 test("new f(); "); 788 789 // ---- Increment and decrement ---- 790 791 test("a ++ "); 792 test("a ++; "); 793 794 test("-- "); 795 test("-- a "); 796 test("-- a; "); 797 798 // ---- Unary operators ---- 799 800 // delete 801 802 test("delete "); 803 test("delete a "); 804 test("delete a[ "); 805 test("delete a[b "); 806 test("delete a[b] "); 807 test("delete a[b]; "); 808 809 test("delete ( "); 810 test("delete (a "); 811 test("delete (a[ "); 812 test("delete (a[b "); 813 test("delete (a[b] "); 814 test("delete (a[b]) "); 815 test("delete (a[b]); "); 816 817 // void 818 819 test("void "); 820 test("void a "); 821 test("void a; "); 822 823 test("void ("); 824 test("void (a "); 825 test("void (a) "); 826 test("void (a); "); 827 828 // typeof 829 830 test("typeof "); 831 test("typeof a "); 832 test("typeof a; "); 833 834 test("typeof ("); 835 test("typeof (a "); 836 test("typeof (a) "); 837 test("typeof (a); "); 838 839 // - 840 841 test("- "); 842 test("- 1 "); 843 test("- 1; "); 844 845 // + 846 847 test("+ "); 848 test("+ 1 "); 849 test("+ 1; "); 850 851 // ---- Arithmetic operators ---- 852 853 // + 854 855 test("1 + "); 856 test("1 + 1 "); 857 test("1 + 1; "); 858 859 // ---- Relational operators ---- 860 861 // in 862 863 test("a in "); 864 test("a in b "); 865 test("a in b; "); 866 867 // instanceof 868 869 test("a instanceof "); 870 test("a instanceof b "); 871 test("a instanceof b; "); 872 873 // ---- Equality operators ---- 874 875 // == 876 877 test("1 == "); 878 test("1 == 1 "); 879 test("1 == 1; "); 880 881 // ---- Bitwise shift operators ---- 882 883 // << 884 885 test("1 << "); 886 test("1 << 1 "); 887 test("1 << 1; "); 888 889 // ---- Binary bitwise operators ---- 890 891 // & 892 893 test("1 & "); 894 test("1 & 1 "); 895 test("1 & 1; "); 896 897 // ---- Binary logical operators ---- 898 899 // || 900 901 test("1 || "); 902 test("1 || 1 "); 903 test("1 || 1; "); 904 905 // ---- Conditional (ternary) operator ---- 906 907 test("1 ? "); 908 test("1 ? 2 "); 909 test("1 ? 2 : "); 910 test("1 ? 2 : 3 "); 911 test("1 ? 2 : 3; "); 912 913 // ---- Assignment operators ---- 914 915 test("x = "); 916 test("x = 1 "); 917 test("x = 1 + "); 918 test("x = 1 + 2 "); 919 test("x = 1 + 2; "); 920 921 // ---- Comma operator ---- 922 923 test("1, "); 924 test("1, 2 "); 925 test("1, 2; "); 926 927 // ---- Functions ---- 928 929 // Arrow functions 930 931 test("a => "); 932 test("a => 1 "); 933 test("a => 1; "); 934 test("a => { "); 935 test("a => {} "); 936 test("a => {}; "); 937 938 test("( "); 939 test("() "); 940 test("() => "); 941 942 test("(..."); 943 test("(...a "); 944 test("(...a) "); 945 test("(...a) => "); 946 947 test("([ "); 948 test("([a "); 949 test("([a] "); 950 test("([a]) "); 951 test("([a]) => "); 952 953 test("({ "); 954 test("({a "); 955 test("({a} "); 956 test("({a}) "); 957 test("({a}) => "); 958 test("({a: "); 959 test("({a: b "); 960 test("({a: b, "); 961 test("({a: b} "); 962 test("({a: b}) "); 963 test("({a: b}) => "); 964 965 // ---- Class declaration ---- 966 967 test("class "); 968 test("class a "); 969 test("class a { "); 970 test("class a { constructor "); 971 test("class a { constructor( "); 972 test("class a { constructor() "); 973 test("class a { constructor() { "); 974 test("class a { constructor() { } "); 975 test("class a { constructor() { } } "); 976 977 test("class a { constructor() { } static "); 978 test("class a { constructor() { } static m "); 979 test("class a { constructor() { } static m( "); 980 test("class a { constructor() { } static m() "); 981 test("class a { constructor() { } static m() { "); 982 test("class a { constructor() { } static m() {} "); 983 test("class a { constructor() { } static m() {} } "); 984 985 test("class a { constructor() { } static ( "); 986 test("class a { constructor() { } static () "); 987 test("class a { constructor() { } static () { "); 988 test("class a { constructor() { } static () {} "); 989 test("class a { constructor() { } static () {} } "); 990 991 test("class a { constructor() { } static get "); 992 test("class a { constructor() { } static get p "); 993 test("class a { constructor() { } static get p( "); 994 test("class a { constructor() { } static get p() "); 995 test("class a { constructor() { } static get p() { "); 996 test("class a { constructor() { } static get p() {} "); 997 test("class a { constructor() { } static get p() {} } "); 998 999 test("class a { constructor() { } static set "); 1000 test("class a { constructor() { } static set p "); 1001 test("class a { constructor() { } static set p( "); 1002 test("class a { constructor() { } static set p(v "); 1003 test("class a { constructor() { } static set p(v) "); 1004 test("class a { constructor() { } static set p(v) { "); 1005 test("class a { constructor() { } static set p(v) {} "); 1006 test("class a { constructor() { } static set p(v) {} } "); 1007 1008 test("class a { constructor() { } * "); 1009 test("class a { constructor() { } *m "); 1010 test("class a { constructor() { } *m( "); 1011 test("class a { constructor() { } *m() "); 1012 test("class a { constructor() { } *m() { "); 1013 test("class a { constructor() { } *m() {} "); 1014 test("class a { constructor() { } *m() {} } "); 1015 1016 test("class a { constructor() { } static * "); 1017 test("class a { constructor() { } static *m "); 1018 test("class a { constructor() { } static *m( "); 1019 test("class a { constructor() { } static *m() "); 1020 test("class a { constructor() { } static *m() { "); 1021 test("class a { constructor() { } static *m() {} "); 1022 test("class a { constructor() { } static *m() {} } "); 1023 1024 test("class a extends "); 1025 test("class a extends b "); 1026 test("class a extends b { "); 1027 1028 test("class a extends ( "); 1029 test("class a extends ( b "); 1030 test("class a extends ( b ) "); 1031 test("class a extends ( b ) { "); 1032 1033 // ---- Class expression ---- 1034 1035 test("( class "); 1036 test("( class a "); 1037 test("( class a { "); 1038 test("( class a { constructor "); 1039 test("( class a { constructor( "); 1040 test("( class a { constructor() "); 1041 test("( class a { constructor() { "); 1042 test("( class a { constructor() { } "); 1043 test("( class a { constructor() { } } "); 1044 test("( class a { constructor() { } } ) "); 1045 1046 test("(class a extends "); 1047 test("(class a extends b "); 1048 test("(class a extends b { "); 1049 1050 test("(class a extends ( "); 1051 test("(class a extends ( b "); 1052 test("(class a extends ( b ) "); 1053 test("(class a extends ( b ) { "); 1054 1055 test("( class { "); 1056 test("( class { constructor "); 1057 test("( class { constructor( "); 1058 test("( class { constructor() "); 1059 test("( class { constructor() { "); 1060 test("( class { constructor() { } "); 1061 test("( class { constructor() { } } "); 1062 test("( class { constructor() { } } ) "); 1063 1064 test("(class extends "); 1065 test("(class extends b "); 1066 test("(class extends b { "); 1067 1068 test("(class extends ( "); 1069 test("(class extends ( b "); 1070 test("(class extends ( b ) "); 1071 test("(class extends ( b ) { "); 1072 1073 // ---- Other ---- 1074 1075 // Literals 1076 1077 test("a "); 1078 test("1 "); 1079 test("1. "); 1080 test("1.2 "); 1081 test("true "); 1082 test("false "); 1083 test("\"a\" "); 1084 test("'a' "); 1085 test("null "); 1086 1087 // Template strings 1088 1089 test("`${ "); 1090 test("`${a "); 1091 test("`${a}` "); 1092 1093 // Function calls 1094 1095 test("f( "); 1096 test("f() "); 1097 test("f(); "); 1098 1099 test("f(... "); 1100 test("f(...x "); 1101 test("f(...x) "); 1102 1103 // Function constructors 1104 1105 test_fun_arg(""); 1106 test_fun_arg("a "); 1107 test_fun_arg("... "); 1108 test_fun_arg("...a "); 1109 1110 // ==== Legacy ==== 1111 1112 // ==== asm.js ==== 1113 1114 test("(function() { 'use asm'; "); 1115 test("(function() { 'use asm'; var "); 1116 test("(function() { 'use asm'; var a "); 1117 test("(function() { 'use asm'; var a = "); 1118 test("(function() { 'use asm'; var a = 1 "); 1119 test("(function() { 'use asm'; var a = 1; "); 1120 test("(function() { 'use asm'; var a = 1; function "); 1121 test("(function() { 'use asm'; var a = 1; function f "); 1122 test("(function() { 'use asm'; var a = 1; function f( "); 1123 test("(function() { 'use asm'; var a = 1; function f() "); 1124 test("(function() { 'use asm'; var a = 1; function f() { "); 1125 test("(function() { 'use asm'; var a = 1; function f() { } "); 1126 test("(function() { 'use asm'; var a = 1; function f() { } var "); 1127 test("(function() { 'use asm'; var a = 1; function f() { } var tbl "); 1128 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = "); 1129 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [ "); 1130 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f "); 1131 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f] "); 1132 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; "); 1133 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return "); 1134 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return f "); 1135 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return f; "); 1136 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return f; } "); 1137 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return f; }) "); 1138 test("(function() { 'use asm'; var a = 1; function f() { } var tbl = [f]; return f; }); "); 1139 1140 // ==== async/await ==== 1141 1142 // async/await function decralation 1143 1144 test("async "); 1145 test("async function "); 1146 test("async function A "); 1147 test("async function A( "); 1148 test("async function A() "); 1149 test("async function A(a "); 1150 test("async function A(a) "); 1151 test("async function A(a) { "); 1152 test("async function A(a) {} "); 1153 test("async function A(a) { await "); 1154 test("async function A(a) { await X "); 1155 test("async function A(a) { await X; "); 1156 test("async function A(a) { await X; } "); 1157 test("async function A(a) { await await "); 1158 test("async function A(a) { await await await "); 1159 test("async function A(a) { await await await X "); 1160 test("async function A(a) { await await await X; "); 1161 test("async function A(a) { await await await X; } "); 1162 1163 opts = { no_fun: true, no_eval: true, module: true }; 1164 test("export default async ", opts); 1165 test("export default async function ", opts); 1166 test("export default async function ( ", opts); 1167 test("export default async function () ", opts); 1168 test("export default async function (a ", opts); 1169 test("export default async function (a) ", opts); 1170 test("export default async function (a) { ", opts); 1171 test("export default async function (a) {} ", opts); 1172 test("export default async function (a) { await ", opts); 1173 test("export default async function (a) { await X ", opts); 1174 test("export default async function (a) { await X; ", opts); 1175 test("export default async function (a) { await X; } ", opts); 1176 1177 // async/await function expression 1178 1179 test("(async "); 1180 test("(async function "); 1181 test("(async function A "); 1182 test("(async function A( "); 1183 test("(async function A() "); 1184 test("(async function A(a "); 1185 test("(async function A(a) "); 1186 test("(async function A(a) { "); 1187 test("(async function A(a) {} "); 1188 test("(async function A(a) { await "); 1189 test("(async function A(a) { await X "); 1190 test("(async function A(a) { await X; "); 1191 test("(async function A(a) { await X; } "); 1192 test("(async function A(a) { await X; }) "); 1193 1194 test("(async function ( "); 1195 test("(async function () "); 1196 test("(async function (a "); 1197 test("(async function (a) "); 1198 test("(async function (a) { "); 1199 test("(async function (a) {} "); 1200 test("(async function (a) { await "); 1201 test("(async function (a) { await X "); 1202 test("(async function (a) { await X; "); 1203 test("(async function (a) { await X; } "); 1204 test("(async function (a) { await X; }) "); 1205 1206 // async/await method 1207 1208 test("({ async "); 1209 test("({ async m "); 1210 test("({ async m( "); 1211 test("({ async m() "); 1212 test("({ async m() { "); 1213 test("({ async m() {} "); 1214 test("({ async m() {}, "); 1215 1216 test("class X { async "); 1217 test("class X { async m "); 1218 test("class X { async m( "); 1219 test("class X { async m() "); 1220 test("class X { async m() { "); 1221 test("class X { async m() {} "); 1222 1223 test("class X { static async "); 1224 test("class X { static async m "); 1225 test("class X { static async m( "); 1226 test("class X { static async m() "); 1227 test("class X { static async m() { "); 1228 test("class X { static async m() {} "); 1229 1230 // async/await arrow 1231 1232 test("(async a "); 1233 test("(async a => "); 1234 test("(async a => b "); 1235 test("(async a => b) "); 1236 1237 test("(async a => { "); 1238 test("(async a => { b "); 1239 test("(async a => { b } "); 1240 test("(async a => { b }) "); 1241 1242 test("(async ( "); 1243 test("(async (a "); 1244 test("(async (a) "); 1245 test("(async (a) => "); 1246 test("(async (a) => b "); 1247 test("(async (a) => b) "); 1248 test("(async (a, "); 1249 test("(async (a, b "); 1250 test("(async (a, b) "); 1251 test("(async (a, b) => "); 1252 test("(async (a, b) => b "); 1253 test("(async (a, b) => b) "); 1254 1255 test("(async ([ "); 1256 test("(async ([a "); 1257 test("(async ([a] "); 1258 test("(async ([a]) "); 1259 test("(async ([a]) => "); 1260 test("(async ([a]) => b "); 1261 test("(async ([a]) => b) "); 1262 test("(async ([a, "); 1263 test("(async ([a, b "); 1264 test("(async ([a, b] "); 1265 test("(async ([a, b]) "); 1266 test("(async ([a, b]) => "); 1267 test("(async ([a, b]) => b "); 1268 test("(async ([a, b]) => b) "); 1269 1270 test("(async ({ "); 1271 test("(async ({a "); 1272 test("(async ({a} "); 1273 test("(async ({a}) "); 1274 test("(async ({a}) => "); 1275 test("(async ({a}) => b "); 1276 test("(async ({a}) => b) "); 1277 test("(async ({a, "); 1278 test("(async ({a, b "); 1279 test("(async ({a, b} "); 1280 test("(async ({a, b}) "); 1281 test("(async ({a, b}) => "); 1282 test("(async ({a, b}) => b "); 1283 test("(async ({a, b}) => b) "); 1284 }