这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(turbo-trace): check exports #9841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 33 additions & 17 deletions crates/turbo-trace/src/import_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,43 @@ impl ImportFinder {

impl Visit for ImportFinder {
fn visit_module_decl(&mut self, decl: &ModuleDecl) {
if let ModuleDecl::Import(import) = decl {
let import_type = if import.type_only {
ImportType::Type
} else {
ImportType::Value
};
match self.import_type {
ImportTraceType::All => {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
}
ImportTraceType::Types if import.type_only => {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
match decl {
ModuleDecl::Import(import) => {
let import_type = if import.type_only {
ImportType::Type
} else {
ImportType::Value
};
match self.import_type {
ImportTraceType::All => {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
}
ImportTraceType::Types if import.type_only => {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
}
ImportTraceType::Values if !import.type_only => {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
}
_ => {}
}
ImportTraceType::Values if !import.type_only => {
}
ModuleDecl::ExportNamed(named_export) => {
if let Some(decl) = &named_export.src {
self.imports
.push((import.src.value.to_string(), import.span, import_type));
.push((decl.value.to_string(), decl.span, ImportType::Value));
}
_ => {}
}
ModuleDecl::ExportAll(export_all) => {
self.imports.push((
export_all.src.value.to_string(),
export_all.span,
ImportType::Value,
));
}
_ => {}
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fn test_trace() -> Result<(), anyhow::Error> {
"get `import_value_and_type.ts` with type dependencies" => "query { file(path: \"import_value_and_type.ts\") { path dependencies(importType: TYPES) { files { items { path } } } } }",
"get `import_value_and_type.ts` with value dependencies" => "query { file(path: \"import_value_and_type.ts\") { path dependencies(importType: VALUES) { files { items { path } } } } }",
"get `incorrect_extension.mjs` with dependencies" => "query { file(path: \"incorrect_extension.mjs\") { path dependencies(depth: 1) { files { items { path } } } } }",
"get `export_all.js` with dependencies" => "query { file(path: \"export_all.js\") { path dependencies { files { items { path } } } } }",
"get `export_named.js` with dependencies" => "query { file(path: \"export_named.js\") { path dependencies { files { items { path } } } } }",
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: crates/turborepo/tests/query.rs
expression: query_output
---
{
"data": {
"file": {
"path": "export_all.js",
"dependencies": {
"files": {
"items": [
{
"path": "bar.js"
},
{
"path": "foo.js"
}
]
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: crates/turborepo/tests/query.rs
expression: query_output
---
{
"data": {
"file": {
"path": "export_named.js",
"dependencies": {
"files": {
"items": [
{
"path": "bar.js"
},
{
"path": "foo.js"
}
]
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./foo.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { foo } from "./foo.js";
Loading