Skip to content

Commit

Permalink
Merge 4ce3efc into 028d6f9
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored Feb 2, 2023
2 parents 028d6f9 + 4ce3efc commit 1501f94
Show file tree
Hide file tree
Showing 117 changed files with 121,006 additions and 82,485 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ crates/next-core/js/src/compiled
crates/turbopack-node/js/src/compiled
crates/turbopack/bench.json
crates/turbopack/tests
crates/turbopack-ecmascript/tests/analyzer/graph
crates/next-transform-strip-page-exports/tests
crates/next-transform-dynamic/tests
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function maybeReturn(x) {
if (x) {
return true;
}
}

function func() {
if (false) {
require("fail");
import("fail");
}
if (true) {
require("./ok");
}
if (true) {
require("./ok");
} else {
require("fail");
import("fail");
}
if (false) {
require("fail");
import("fail");
} else {
require("./ok");
}
}

it("should not follow conditional references", () => {
func();

expect(func.toString()).not.toContain("import(");
});

it("should allow replacements in IIFEs", () => {
(function func() {
if (false) {
require("fail");
import("fail");
}
})();
});

it("should support functions that only sometimes return", () => {
let ok = false;
if (maybeReturn(true)) {
ok = true;
}
expect(ok).toBe(true);
});

it("should evaluate process.turbopack", () => {
let ok = false;
if (process.turbopack) {
ok = true;
} else {
require("fail");
import("fail");
}
expect(ok).toBe(true);
});

it("should evaluate !process.turbopack", () => {
if (!process.turbopack) {
require("fail");
import("fail");
}
});

// it("should evaluate NODE_ENV", () => {
// if (process.env.NODE_ENV !== "development") {
// require("fail");
// import("fail");
// }
// });
Empty file.
6 changes: 3 additions & 3 deletions crates/turbopack-ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ lazy_static = "1.4.0"
next-font = { path = "../next-font" }
next-transform-dynamic = { path = "../next-transform-dynamic" }
next-transform-strip-page-exports = { path = "../next-transform-strip-page-exports" }
num-bigint = "0.4"
num-traits = "0.2.15"
once_cell = "1.13.0"
parking_lot = "0.12.1"
pin-project-lite = "0.2.9"
regex = "1.5.4"
serde = "1.0.136"
Expand Down Expand Up @@ -58,9 +61,6 @@ swc_core = { workspace = true, features = [
"base",
] }

[dependencies.num-bigint]
version = "0.4"

[dev-dependencies]
criterion = { version = "0.3.5", features = ["async_tokio"] }
rstest = "0.12.0"
Expand Down
41 changes: 16 additions & 25 deletions crates/turbopack-ecmascript/benches/analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use std::{
fs,
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
use std::{fs, path::PathBuf, sync::Arc, time::Duration};

use criterion::{Bencher, BenchmarkId, Criterion};
use swc_core::{
Expand All @@ -23,8 +18,8 @@ use turbopack_core::{
};
use turbopack_ecmascript::analyzer::{
graph::{create_graph, EvalContext, VarGraph},
linker::{link, LinkCache},
test_utils::visitor,
linker::link,
test_utils::{early_visitor, visitor},
};

pub fn benchmark(c: &mut Criterion) {
Expand Down Expand Up @@ -95,28 +90,24 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) {
.unwrap();

b.to_async(rt).iter(|| async {
let cache = Mutex::new(LinkCache::new());
for val in input.var_graph.values.values() {
VcStorage::with(async {
let env = EnvironmentVc::new(
Value::new(ExecutionEnvironment::NodeJsLambda(
NodeJsEnvironment {
compile_target: CompileTargetVc::unknown(),
..Default::default()
}
.into(),
)),
Value::new(EnvironmentIntention::ServerRendering),
);
link(
&input.var_graph,
val.clone(),
&(|val| {
Box::pin(visitor(
val,
EnvironmentVc::new(
Value::new(ExecutionEnvironment::NodeJsLambda(
NodeJsEnvironment {
compile_target: CompileTargetVc::unknown(),
..Default::default()
}
.into(),
)),
Value::new(EnvironmentIntention::ServerRendering),
),
))
}),
&cache,
&(|val| early_visitor(val)),
&(|val| visitor(val, env)),
Default::default(),
)
.await
})
Expand Down
Loading

0 comments on commit 1501f94

Please sign in to comment.