Skip to content

Commit ecd6823

Browse files
authored
Merge 4662e23 into 169f943
2 parents 169f943 + 4662e23 commit ecd6823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+64880
-57799
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ crates/next-core/js/src/compiled
2121
crates/turbopack-node/js/src/compiled
2222
crates/turbopack/bench.json
2323
crates/turbopack/tests
24+
crates/turbopack-ecmascript/tests/analyzer/graph
2425
crates/next-transform-strip-page-exports/tests
2526
crates/next-transform-dynamic/tests

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
function func() {
2+
if (false) {
3+
require("fail");
4+
import("fail");
5+
}
6+
if (true) {
7+
require("./ok");
8+
}
9+
if (true) {
10+
require("./ok");
11+
} else {
12+
require("fail");
13+
import("fail");
14+
}
15+
if (false) {
16+
require("fail");
17+
import("fail");
18+
} else {
19+
require("./ok");
20+
}
21+
}
22+
23+
it("should not follow conditional references", () => {
24+
func();
25+
26+
expect(func.toString()).not.toContain("import(");
27+
});
28+
29+
it("should allow replacements in IIFEs", () => {
30+
(function func() {
31+
if (false) {
32+
require("fail");
33+
import("fail");
34+
}
35+
})();
36+
});
37+
38+
it("should evaluate process.turbopack", () => {
39+
let ok = false;
40+
if (process.turbopack) {
41+
ok = true;
42+
} else {
43+
require("fail");
44+
import("fail");
45+
}
46+
expect(ok).toBe(true);
47+
});
48+
49+
it("should evaluate !process.turbopack", () => {
50+
if (!process.turbopack) {
51+
require("fail");
52+
import("fail");
53+
}
54+
});
55+
56+
// it("should evaluate NODE_ENV", () => {
57+
// if (process.env.NODE_ENV !== "development") {
58+
// require("fail");
59+
// import("fail");
60+
// }
61+
// });

crates/next-dev-tests/tests/integration/turbopack/basic/comptime/ok.js

Whitespace-only changes.

crates/turbopack-ecmascript/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ lazy_static = "1.4.0"
2020
next-font = { path = "../next-font" }
2121
next-transform-dynamic = { path = "../next-transform-dynamic" }
2222
next-transform-strip-page-exports = { path = "../next-transform-strip-page-exports" }
23+
num-bigint = "0.4"
24+
num-traits = "0.2.15"
2325
once_cell = "1.13.0"
2426
pin-project-lite = "0.2.9"
2527
regex = "1.5.4"
@@ -58,9 +60,6 @@ swc_core = { workspace = true, features = [
5860
"base",
5961
] }
6062

61-
[dependencies.num-bigint]
62-
version = "0.4"
63-
6463
[dev-dependencies]
6564
criterion = { version = "0.3.5", features = ["async_tokio"] }
6665
rstest = "0.12.0"

crates/turbopack-ecmascript/benches/analyzer.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use turbopack_core::{
2424
use turbopack_ecmascript::analyzer::{
2525
graph::{create_graph, EvalContext, VarGraph},
2626
linker::{link, LinkCache},
27-
test_utils::visitor,
27+
test_utils::{early_visitor, visitor},
2828
};
2929

3030
pub fn benchmark(c: &mut Criterion) {
@@ -98,24 +98,21 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) {
9898
let cache = Mutex::new(LinkCache::new());
9999
for val in input.var_graph.values.values() {
100100
VcStorage::with(async {
101+
let env = EnvironmentVc::new(
102+
Value::new(ExecutionEnvironment::NodeJsLambda(
103+
NodeJsEnvironment {
104+
compile_target: CompileTargetVc::unknown(),
105+
..Default::default()
106+
}
107+
.into(),
108+
)),
109+
Value::new(EnvironmentIntention::ServerRendering),
110+
);
101111
link(
102112
&input.var_graph,
103113
val.clone(),
104-
&(|val| {
105-
Box::pin(visitor(
106-
val,
107-
EnvironmentVc::new(
108-
Value::new(ExecutionEnvironment::NodeJsLambda(
109-
NodeJsEnvironment {
110-
compile_target: CompileTargetVc::unknown(),
111-
..Default::default()
112-
}
113-
.into(),
114-
)),
115-
Value::new(EnvironmentIntention::ServerRendering),
116-
),
117-
))
118-
}),
114+
&(|val| early_visitor(val)),
115+
&(|val| visitor(val, env)),
119116
&cache,
120117
)
121118
.await

0 commit comments

Comments
 (0)