| 1 |
load(libdir + "asserts.js"); |
| 2 |
|
| 3 |
var functionDeclarations = [ |
| 4 |
"function f(){}", |
| 5 |
"function* f(){}", |
| 6 |
"async function f(){}", |
| 7 |
]; |
| 8 |
|
| 9 |
var varDeclarations = [ |
| 10 |
"var f", |
| 11 |
"{ var f; }", |
| 12 |
"for (var f in null);", |
| 13 |
"for (var f of null);", |
| 14 |
"for (var f; ;);", |
| 15 |
]; |
| 16 |
|
| 17 |
var lexicalDeclarations = [ |
| 18 |
"let f;", |
| 19 |
"const f = 0;", |
| 20 |
"class f {};", |
| 21 |
]; |
| 22 |
|
| 23 |
var imports = [ |
| 24 |
"import f from '';", |
| 25 |
"import f, {} from '';", |
| 26 |
"import d, {f} from '';", |
| 27 |
"import d, {f as f} from '';", |
| 28 |
"import d, {foo as f} from '';", |
| 29 |
"import f, * as d from '';", |
| 30 |
"import d, * as f from '';", |
| 31 |
"import {f} from '';", |
| 32 |
"import {f as f} from '';", |
| 33 |
"import {foo as f} from '';", |
| 34 |
"import* as f from '';", |
| 35 |
]; |
| 36 |
|
| 37 |
var exports = [ |
| 38 |
"export var f;", |
| 39 |
...functionDeclarations.map(fn => `export ${fn};`), |
| 40 |
...lexicalDeclarations.map(ld => `export ${ld};`), |
| 41 |
...functionDeclarations.map(fn => `export default ${fn};`), |
| 42 |
"export default class f {};", |
| 43 |
]; |
| 44 |
|
| 45 |
var redeclarations = [ |
| 46 |
...functionDeclarations, |
| 47 |
...varDeclarations, |
| 48 |
...lexicalDeclarations, |
| 49 |
...imports, |
| 50 |
...exports, |
| 51 |
]; |
| 52 |
|
| 53 |
var noredeclarations = [ |
| 54 |
...functionDeclarations.map(fn => `{ ${fn} }`), |
| 55 |
...lexicalDeclarations.map(ld => `{ ${ld} }`), |
| 56 |
...["let", "const"].map(ld => `for (${ld} f in null);`), |
| 57 |
...["let", "const"].map(ld => `for (${ld} f of null);`), |
| 58 |
...["let", "const"].map(ld => `for (${ld} f = 0; ;);`), |
| 59 |
"export {f};", |
| 60 |
"export {f as f};", |
| 61 |
"export {foo as f}; var foo;", |
| 62 |
"export {f} from '';", |
| 63 |
"export {f as f} from '';", |
| 64 |
"export {foo as f} from '';", |
| 65 |
]; |
| 66 |
|
| 67 |
for (var decl of functionDeclarations) { |
| 68 |
for (var redecl of redeclarations) { |
| 69 |
assertThrowsInstanceOf(() => { |
| 70 |
parseModule(` |
| 71 |
${decl} |
| 72 |
${redecl} |
| 73 |
`); |
| 74 |
}, SyntaxError); |
| 75 |
|
| 76 |
assertThrowsInstanceOf(() => { |
| 77 |
parseModule(` |
| 78 |
${redecl} |
| 79 |
${decl} |
| 80 |
`); |
| 81 |
}, SyntaxError); |
| 82 |
} |
| 83 |
|
| 84 |
for (var redecl of noredeclarations) { |
| 85 |
parseModule(` |
| 86 |
${decl} |
| 87 |
${redecl} |
| 88 |
`); |
| 89 |
parseModule(` |
| 90 |
${redecl} |
| 91 |
${decl} |
| 92 |
`); |
| 93 |
} |
| 94 |
} |