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