| 1 |
load(libdir + 'asserts.js'); |
| 2 |
|
| 3 |
let source = `class C { |
| 4 |
x = |
| 5 |
}`; |
| 6 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 7 |
|
| 8 |
source = `class C { |
| 9 |
-2; |
| 10 |
-2 = 2; |
| 11 |
}`; |
| 12 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 13 |
|
| 14 |
source = `class C { |
| 15 |
x += 2; |
| 16 |
}`; |
| 17 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 18 |
|
| 19 |
source = `class C { |
| 20 |
#2; |
| 21 |
}`; |
| 22 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 23 |
|
| 24 |
source = `class C { |
| 25 |
#["h" + "i"]; |
| 26 |
}`; |
| 27 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 28 |
|
| 29 |
source = `class C { |
| 30 |
#"hi"; |
| 31 |
}`; |
| 32 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 33 |
|
| 34 |
source = `class C { |
| 35 |
constructor; |
| 36 |
}`; |
| 37 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 38 |
|
| 39 |
source = `class C { |
| 40 |
"constructor"; |
| 41 |
}`; |
| 42 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 43 |
|
| 44 |
source = `class C { |
| 45 |
x = arguments; |
| 46 |
}`; |
| 47 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 48 |
|
| 49 |
source = `class C { |
| 50 |
x = super(); |
| 51 |
}`; |
| 52 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 53 |
|
| 54 |
source = `function f() { |
| 55 |
class C { |
| 56 |
#"should still throw error during lazy parse"; |
| 57 |
} |
| 58 |
}`; |
| 59 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 60 |
|
| 61 |
source = `#outside;`; |
| 62 |
assertErrorMessage(() => eval(source), SyntaxError, /./); |
| 63 |
|
| 64 |
source = `class C { |
| 65 |
x = super(); |
| 66 |
}`; |
| 67 |
assertErrorMessage(() => Function(source), SyntaxError, /./); |
| 68 |
|
| 69 |
source = `class C { |
| 70 |
x = sper(); |
| 71 |
}`; |
| 72 |
eval(source); |
| 73 |
|
| 74 |
|
| 75 |
// The following test cases fail to parse because ASI does not happen if the |
| 76 |
// next token might be valid, even if it leads to a SyntaxError further down |
| 77 |
// the road. |
| 78 |
|
| 79 |
source = `class C { |
| 80 |
x = 0 |
| 81 |
["computedMethodName"](){} |
| 82 |
}`; |
| 83 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 84 |
|
| 85 |
source = `class C { |
| 86 |
x = 0 |
| 87 |
*f(){} |
| 88 |
}`; |
| 89 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 90 |
|
| 91 |
|
| 92 |
// The following test cases fail to parse because ASI doesn't happen without a |
| 93 |
// newline. |
| 94 |
|
| 95 |
source = `class C { x y }`; |
| 96 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 97 |
|
| 98 |
source = `class C { if var } // identifiers that look like keywords`; |
| 99 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 100 |
|
| 101 |
source = `class C { x = 1 y }`; |
| 102 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 103 |
|
| 104 |
source = `class C { x async f() {} }`; |
| 105 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 106 |
|
| 107 |
source = `class C { x static f() {} }`; |
| 108 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 109 |
|
| 110 |
source = `class C { field1 static field2 }`; |
| 111 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 112 |
|
| 113 |
source = `class C { x get f() {} }`; |
| 114 |
assertThrowsInstanceOf(() => Function(source), SyntaxError); |
| 115 |
|
| 116 |
if (typeof reportCompare === 'function') reportCompare(true, true); |