keyword-unescaped-requirement-modules.js (3073B)
1 /* 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/licenses/publicdomain/ 4 */ 5 6 //----------------------------------------------------------------------------- 7 var BUGNUMBER = 1204027; 8 var summary = 9 "Escape sequences aren't allowed in bolded grammar tokens (that is, in " + 10 "keywords, possibly contextual keywords)"; 11 12 print(BUGNUMBER + ": " + summary); 13 14 /************** 15 * BEGIN TEST * 16 **************/ 17 18 var badModules = 19 [ 20 "\\u0069mport f from 'g'", 21 "i\\u006dport g from 'h'", 22 "import * \\u0061s foo", 23 "import {} fro\\u006d 'bar'", 24 "import { x \\u0061s y } from 'baz'", 25 26 "\\u0065xport function f() {}", 27 "e\\u0078port function g() {}", 28 "export * fro\\u006d 'fnord'", 29 "export d\\u0065fault var x = 3;", 30 "export { q } fro\\u006d 'qSupplier';", 31 32 ]; 33 34 if (typeof parseModule === "function") 35 { 36 for (var module of badModules) 37 { 38 assertThrowsInstanceOf(() => parseModule(module), SyntaxError, 39 "bad behavior for: " + module); 40 } 41 } 42 43 if (typeof Reflect.parse === "function") 44 { 45 var twoStatementAST = 46 Reflect.parse(`let x = 0; 47 export { x } /* ASI should trigger here */ 48 fro\\u006D`, 49 { target: "module" }); 50 51 var statements = twoStatementAST.body; 52 assertEq(statements.length, 3, 53 "should have two items in the module, not one ExportDeclaration"); 54 assertEq(statements[0].type, "VariableDeclaration"); 55 assertEq(statements[1].type, "ExportDeclaration"); 56 assertEq(statements[2].type, "ExpressionStatement"); 57 assertEq(statements[2].expression.name, "from"); 58 59 var oneStatementAST = 60 Reflect.parse(`export { x } /* no ASI here */ 61 from 'foo'`, 62 { target: "module" }); 63 64 assertEq(oneStatementAST.body.length, 1); 65 assertEq(oneStatementAST.body[0].type, "ExportDeclaration"); 66 67 twoStatementAST = 68 Reflect.parse(`export { x } from "bar" 69 /bar/g`, 70 { target: "module" }); 71 72 statements = twoStatementAST.body; 73 assertEq(statements.length, 2, 74 "should have two items in the module, not one ExportDeclaration"); 75 assertEq(statements[0].type, "ExportDeclaration"); 76 assertEq(statements[1].type, "ExpressionStatement"); 77 assertEq(statements[1].expression.type, "Literal"); 78 assertEq(statements[1].expression.value.toString(), "/bar/g"); 79 80 twoStatementAST = 81 Reflect.parse(`export * from "bar" 82 /bar/g`, 83 { target: "module" }); 84 85 statements = twoStatementAST.body; 86 assertEq(statements.length, 2, 87 "should have two items in the module, not one ExportDeclaration"); 88 assertEq(statements[0].type, "ExportDeclaration"); 89 assertEq(statements[1].type, "ExpressionStatement"); 90 assertEq(statements[1].expression.type, "Literal"); 91 assertEq(statements[1].expression.value.toString(), "/bar/g"); 92 } 93 94 /******************************************************************************/ 95 96 if (typeof reportCompare === "function") 97 reportCompare(true, true); 98 99 print("Tests complete");