Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a2328a1
initial work for compile-time evaluation
sokra Jan 26, 2023
ab9eebe
add logical operations
sokra Jan 26, 2023
735fb2f
organize, comment, simplify
sokra Jan 27, 2023
91dd467
bugfixes and improvements
sokra Jan 27, 2023
1a5cc04
cleanup, review
sokra Jan 30, 2023
f557ee3
add react-dom test case
sokra Jan 30, 2023
49c65b4
fix test case
sokra Jan 30, 2023
7ba8e87
update snapshots
sokra Jan 30, 2023
a1df5d5
early evaluate operations besed on partial info for performance
sokra Jan 30, 2023
5afa09e
make alternatives duplication detection cheaper
sokra Jan 30, 2023
a5965d3
clippy, update snapshots
sokra Jan 30, 2023
33bc831
heavvy refactoring, fixes arguments problem, removes cache
sokra Jan 31, 2023
b199016
snapshot effects in analyzer tests
sokra Feb 1, 2023
f3dd2bd
refactor to use nested effects in closures
sokra Feb 1, 2023
5069bc8
add special behavior for array methods called with closures
sokra Feb 1, 2023
f32943a
fix test case
sokra Feb 1, 2023
d573980
remove println
sokra Feb 1, 2023
ab246b8
handle closures for unknown calls too
sokra Feb 1, 2023
641312a
more debug checks, fix node update
sokra Feb 1, 2023
7a27fef
clippy
sokra Feb 1, 2023
25d5d7a
function might implict return undefined
sokra Feb 1, 2023
4ce3efc
Merge branch 'main' into sokra/web-492-handle-if-statements
sokra Feb 2, 2023
e49eef1
Merge remote-tracking branch 'origin/main' into sokra/web-492-handle-…
sokra Feb 3, 2023
e731362
Merge remote-tracking branch 'origin/main' into sokra/web-492-handle-…
sokra Feb 3, 2023
7c1798f
clippy
sokra Feb 3, 2023
b986c17
review, bugfixes, comments
sokra Feb 3, 2023
f584071
fix fn name
sokra Feb 3, 2023
b593ef6
remove println
sokra Feb 3, 2023
0c4871b
add comment
sokra Feb 3, 2023
f985370
move test code into input folder
sokra Feb 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,82 @@
it("importing a not existing file should throw", () => {
// This is a check to make sure that the following tests would fail if they require("fail")
expect(() => {
require("./not-existing-file");
}).toThrow();
});

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");
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test that verifies the error case as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean with the error case?

I added a check if it runs through the "then" branch. Is that enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error case is when require("fail") or import("fail") fail to compile. Do we have a test case for this?


// it("should evaluate NODE_ENV", () => {
// if (process.env.NODE_ENV !== "development") {
// require("fail");
// import("fail");
// }
// });
Empty file.
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/reference_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Display;

// These enums list well known types, which we use internally. Plugins might add
// These enums list well-known types, which we use internally. Plugins might add
// custom types too.

// TODO when plugins are supported, replace u8 with a trait that defines the
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-create-test-app/src/test_app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl TestAppBuilder {
};

#[cfg(windows)]
let relative_effect = relative_effect.replace("\\", "/");
let relative_effect = relative_effect.replace('\\', "/");

formatdoc! {r#"
{SETUP_IMPORTS}
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-dev-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub async fn process_request_with_content_source(

let header_map = response.headers_mut().expect("headers must be defined");

for (header_name, header_value) in &*headers {
for (header_name, header_value) in headers {
header_map.append(
HeaderName::try_from(header_name.clone())?,
hyper::header::HeaderValue::try_from(header_value.as_str())?,
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-dev-server/src/source/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ pub async fn resolve_source_request(
ContentSourceResult::NeedData(needed) => {
current_source = needed.source.resolve().await?;
current_asset_path = needed.path.clone();
data = request_to_data(&mut request_overwrites, &needed.vary).await?;
data = request_to_data(&request_overwrites, &needed.vary).await?;
}
ContentSourceResult::Result { get_content, .. } => {
let content_vary = get_content.vary().await?;
let content_data = request_to_data(&mut request_overwrites, &content_vary).await?;
let content_data = request_to_data(&request_overwrites, &content_vary).await?;
let content = get_content.get(Value::new(content_data));
match &*content.await? {
ContentSourceContent::Rewrite(rewrite) => {
Expand Down
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,
&early_visitor,
&(|val| visitor(val, env)),
Default::default(),
)
.await
})
Expand Down
Loading