398
399(function testMethodDefinition() {
400 testSyntax("({ async [foo]() {} })");
401 testSyntax("({ async [Symbol.asyncIterator]() {} })");
402 testSyntax("({ async 0() {} })");
403 testSyntax("({ async 'string'() {} })");
404 testSyntax("({ async ident() {} })");
405
406 testSyntax("(class { async [foo]() {} })");
407 testSyntax("(class { async [Symbol.asyncIterator]() {} })");
408 testSyntax("(class { async 0() {} })");
409 testSyntax("(class { async 'string'() {} })");
410 testSyntax("(class { async ident() {} })");
411
412 testSyntax("(class { static async [foo]() {} })");
413 testSyntax("(class { static async [Symbol.asyncIterator]() {} })");
414 testSyntax("(class { static async 0() {} })");
415 testSyntax("(class { static async 'string'() {} })");
416 testSyntax("(class { static async ident() {} })");
417})();
418
419(function testLineTerminator() {
420 let testLineFeedErrors = (prefix, suffix) => {
421 testSyntaxError(`${prefix}// comment
422 ${suffix}`);
423 testSyntaxError(`${prefix}/* comment
424 */ ${suffix}`);
425 testSyntaxError(`${prefix}
426 ${suffix}`);
427 testSyntaxError(`"use strict";${prefix}// comment
428 ${suffix}`);
429 testSyntaxError(`"use strict";${prefix}/* comment
430 */ ${suffix}`);
431 testSyntaxError(`"use strict";${prefix}
432 ${suffix}`);
433 };
434
435 let testLineFeeds = (prefix, suffix) => {
436 testSyntax(`${prefix}// comment
437 ${suffix}`);
438 testSyntax(`${prefix}/* comment
439 */${suffix}`);
440 testSyntax(`${prefix}
441 ${suffix}`);
442 testSyntax(`"use strict";${prefix}// comment
443 ${suffix}`);
444 testSyntax(`"use strict";${prefix}/* comment
445 */${suffix}`);
446 testSyntax(`"use strict";${prefix}
447 ${suffix}`);
448 };
449
450 let tests = [
451 // ObjectLiteral AsyncMethodDefinition
452 { prefix: "({ async", suffix: "method() {} }).method" },
453
454 // ClassLiteral AsyncMethodDefinition
455 { prefix: "(class { async", suffix: "method() {} }).prototype.method" },
456
457 // AsyncArrowFunctions
458 { prefix: "(async", suffix: "param => 1)" },
459 { prefix: "(async", suffix: "(param) => 1)" },
460 { prefix: "(async", suffix: "param => {})" },
461 { prefix: "(async", suffix: "(param) => {})" },
462 ];
463
464 for (let { prefix, suffix } of tests) {
465 testSyntax(`${prefix} ${suffix}`);
466 testSyntax(`"use strict";${prefix} ${suffix}`);
467 shouldBe("function", typeof eval(`${prefix} ${suffix}`));
468 shouldBe("function", typeof eval(`"use strict";${prefix} ${suffix}`));
469 testLineFeedErrors(prefix, suffix);
470 }
471
472 // AsyncFunctionDeclaration
473 testSyntax("async function foo() {}");
474 testLineFeeds("async", "function foo() {}");
475
476 // AsyncFunctionExpression
477 testSyntax("var x = async function foo() {}");
478 testSyntax("'use strict';var x = async function foo() {}");
479 testLineFeeds("var x = async", "function foo() {}");
480 testLineFeedErrors("var x = async", "function() {}");
481})();