-
-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (129 loc) · 2.35 KB
/
Copy pathindex.js
File metadata and controls
141 lines (129 loc) · 2.35 KB
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
133
134
135
136
137
138
139
140
141
const esm1 = require("./esm1");
expect(esm1.default).toBe("esm1");
it("Shouldn't eliminate hoisted function in current block scope", () => {
expect(() => {
funcDecl;
}).not.toThrow();
funcDecl();
if (true) return;
function funcDecl() {}
import("./esm3").then(() => {
expect(true).toBe(false);
});
});
it("Shouldn't eliminate hoisted variable", () => {
expect(() => {
varDecl;
}).not.toThrow();
try {
throw new Error();
} catch (e) {
return;
}
var varDecl = "foo";
expect(true).toBe(false);
import("./esm3").then(() => {
expect(true).toBe(false);
});
});
it("Shouldn't eliminate hoisted variable (more complex). From test/configCases/parsing/issue-4857/index.js", () => {
expect(() => {
a;
b;
c;
d;
e;
f;
g;
h;
i;
j;
k;
l;
m;
n;
o;
}).not.toThrow();
expect(() => {
withVar;
}).toThrow();
try {
} finally {
return;
}
expect(true).toBe(false);
var a,
[, , b] = [],
{ c, D: d, ["E"]: e = 2 } = {};
var [{ ["_"]: f }, ...g] = [];
do {
switch (g) {
default:
var h;
break;
}
loop: for (var i; ; ) for (var j in {}) for (var k of {}) break;
try {
var l;
} catch (e) {
var m;
} finally {
var n;
}
{
var o;
}
} while (true);
with (o) {
var withVar;
}
import("./esm3").then(() => {
expect(true).toBe(false);
});
});
it("Should eliminate hoisted function in strict mode", () => {
"use strict";
expect(() => {
funcDecl;
}).toThrow();
if (true) return;
{
function funcDecl() {}
expect(true).toBe(false);
}
});
it("Shouldn't eliminate hoisted function in sloppy mode", () => {
expect(() => {
funcDecl;
}).not.toThrow();
if (true) return;
{
function funcDecl() {}
expect(true).toBe(false);
}
});
it("Shouldn't hoist const/let from dead for-of/for-in branch", () => {
// Bug: const/let in for-of inside if(false) was incorrectly hoisted as var,
// causing a duplicate declaration with any outer let/const of the same name.
let output = "start";
if (false) {
for (const output of [1, 2, 3]) {
console.log(output);
}
}
expect(output).toBe("start");
});
it("Shouldn't hoist const/let from dead for-in branch", () => {
let key = "start";
if (false) {
for (const key in { a: 1 }) {
console.log(key);
}
}
expect(key).toBe("start");
});
if (true) {
return;
}
// We won't terminate in top level scope although it won't run.
require("./esm2");