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
|
load(libdir + "match.js");
load(libdir + "asserts.js");
var { Pattern, MatchError } = Match;
program = (elts) => Pattern({
type: "Program",
body: elts
});
expressionStatement = (expression) => Pattern({
type: "ExpressionStatement",
expression: expression
});
assignmentExpression = (left, operator, right) => Pattern({
type: "AssignmentExpression",
operator: operator,
left: left,
right: right
});
ident = (name) => Pattern({
type: "Identifier",
name: name
});
metaProperty = (meta, property) => Pattern({
type: "MetaProperty",
meta: meta,
property: property
});
memberExpression = (object, property) => Pattern({
type: "MemberExpression",
object: object,
property: property
});
function parseAsModule(source)
{
return Reflect.parse(source, {target: "module"});
}
program([
expressionStatement(
metaProperty(
ident("import"),
ident("meta")
)
)
]).assert(parseAsModule("import.meta;"));
program([
expressionStatement(
assignmentExpression(
ident("x"),
"=",
metaProperty(
ident("import"),
ident("meta")
)
)
)
]).assert(parseAsModule("x = import.meta;"));
program([
expressionStatement(
assignmentExpression(
memberExpression(
metaProperty(
ident("import"),
ident("meta")
),
ident("foo")
),
"=",
ident("x"),
)
)
]).assert(parseAsModule("import.meta.foo = x;"));
function assertModuleParseThrowsSyntaxError(source)
{
assertThrowsInstanceOf(() => parseAsModule(source), SyntaxError);
}
assertModuleParseThrowsSyntaxError("import");
assertModuleParseThrowsSyntaxError("import.");
assertModuleParseThrowsSyntaxError("import.met");
assertModuleParseThrowsSyntaxError("import.metaa");
assertModuleParseThrowsSyntaxError("x = import");
assertModuleParseThrowsSyntaxError("x = import.");
assertModuleParseThrowsSyntaxError("x = import.met");
assertModuleParseThrowsSyntaxError("x = import.metaa");
assertModuleParseThrowsSyntaxError("import.meta = x");
|