-
Notifications
You must be signed in to change notification settings - Fork 913
/
Copy pathtests-import-meta.js
132 lines (127 loc) · 3.42 KB
/
tests-import-meta.js
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Tests for ECMAScript 2020 `import.meta`
if (typeof exports !== "undefined") {
var test = require("./driver.js").test;
var testFail = require("./driver.js").testFail;
}
test(
"import.meta",
{
"type": "Program",
"start": 0,
"end": 11,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 11,
"expression": {
"type": "MetaProperty",
"start": 0,
"end": 11,
"meta": {
"type": "Identifier",
"start": 0,
"end": 6,
"name": "import"
},
"property": {
"type": "Identifier",
"start": 7,
"end": 11,
"name": "meta"
}
}
}
],
"sourceType": "module"
},
{ ecmaVersion: 11, sourceType: "module" }
);
test(
"import.meta",
{
"type": "Program",
"start": 0,
"end": 11,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 11,
"expression": {
"type": "MetaProperty",
"start": 0,
"end": 11,
"meta": {
"type": "Identifier",
"start": 0,
"end": 6,
"name": "import"
},
"property": {
"type": "Identifier",
"start": 7,
"end": 11,
"name": "meta"
}
}
}
],
"sourceType": "script"
},
{ ecmaVersion: 11, sourceType: "script", allowImportExportEverywhere: true }
);
test(
"import.meta.url",
{
"type": "Program",
"start": 0,
"end": 15,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 15,
"expression": {
"type": "MemberExpression",
"start": 0,
"end": 15,
"object": {
"type": "MetaProperty",
"start": 0,
"end": 11,
"meta": {
"type": "Identifier",
"start": 0,
"end": 6,
"name": "import"
},
"property": {
"type": "Identifier",
"start": 7,
"end": 11,
"name": "meta"
}
},
"property": {
"type": "Identifier",
"start": 12,
"end": 15,
"name": "url"
},
"computed": false
}
}
],
"sourceType": "module"
},
{ ecmaVersion: 11, sourceType: "module" }
);
testFail("import.meta", "Unexpected token (1:6)", { ecmaVersion: 10, sourceType: "module" });
testFail("import.meta", "Cannot use 'import.meta' outside a module (1:0)", { ecmaVersion: 11, sourceType: "script" });
testFail("import['meta']", "Unexpected token (1:6)", { ecmaVersion: 11, sourceType: "module" });
testFail("a = import['meta']", "Unexpected token (1:10)", { ecmaVersion: 11, sourceType: "module" });
testFail("import.target", "The only valid meta property for import is 'import.meta' (1:7)", { ecmaVersion: 11, sourceType: "module" });
testFail("new.meta", "The only valid meta property for new is 'new.target' (1:4)", { ecmaVersion: 11, sourceType: "module" });
testFail("im\\u0070ort.meta", "Escape sequence in keyword import (1:0)", { ecmaVersion: 11, sourceType: "module" });
testFail("import.\\u006d\\u0065\\u0074\\u0061", "'import.meta' must not contain escaped characters (1:0)", { ecmaVersion: 11, sourceType: "module" });