Skip to content
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

fix imports in default arguments in functions #3292

Merged
merged 2 commits into from
Jan 12, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { named } from "./module.js";

function Fun({ value = named }) {
return value;
}

it("support imports in default arguments", () => {
expect(Fun({})).toBe("named");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const named = "named";
3 changes: 2 additions & 1 deletion crates/turbopack-ecmascript/src/analyzer/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ impl VisitAstPath for Analyzer<'_> {
let value = self.current_value.take();
for (index, p) in n.iter().enumerate() {
self.current_value = Some(JsValue::Argument(index));
p.visit_children_with_path(self, ast_path);
ast_path.with_index(index, |ast_path| p.visit_children_with_path(self, ast_path));
}
self.current_value = value;
}
Expand Down Expand Up @@ -1102,6 +1102,7 @@ impl VisitAstPath for Analyzer<'_> {
match &value {
Some(current_value) => {
self.visit_pat_with_value(pat, obj, current_value, ast_path);

// We should not call visit_children_with
return;
}
Expand Down
4 changes: 4 additions & 0 deletions crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,7 @@ mod tests {
crate::register();
let graph_snapshot_path = input.with_file_name("graph.snapshot");
let graph_explained_snapshot_path = input.with_file_name("graph-explained.snapshot");
let graph_effects_snapshot_path = input.with_file_name("graph-effects.snapshot");
let resolved_explained_snapshot_path = input.with_file_name("resolved-explained.snapshot");

run_test(false, |cm, handler| {
Expand Down Expand Up @@ -2065,6 +2066,9 @@ mod tests {
NormalizedOutput::from(explain_all(&named_values))
.compare_to_file(&graph_explained_snapshot_path)
.unwrap();
NormalizedOutput::from(format!("{:#?}", var_graph.effects))
.compare_to_file(&graph_effects_snapshot_path)
.unwrap();
}

{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
Call {
func: FreeVar(
Require,
),
args: [
Variable(
(
Atom('x' type=static),
#1,
),
),
],
ast_path: [
Program(
Module,
),
Module(
Body(
2,
),
),
ModuleItem(
ModuleDecl,
),
ModuleDecl(
ExportDecl,
),
ExportDecl(
Decl,
),
Decl(
Fn,
),
FnDecl(
Function,
),
Function(
Body,
),
BlockStmt(
Stmts(
0,
),
),
Stmt(
Expr,
),
ExprStmt(
Expr,
),
Expr(
Call,
),
],
span: Span {
lo: BytePos(
54,
),
hi: BytePos(
64,
),
ctxt: #0,
},
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading