Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5c9525be
Commit
5c9525be
authored
Aug 01, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tracing
parent
6d318d61
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
444 additions
and
267 deletions
+444
-267
graph.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/graph.rs
+80
-0
linker.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
+15
-8
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+349
-259
No files found.
turbopack/crates/turbopack-ecmascript/src/analyzer/graph.rs
View file @
5c9525be
...
...
@@ -245,6 +245,86 @@ impl Effect {
Effect
::
Unreachable
{
..
}
=>
{}
}
}
/// Returns all JsValues referened by this effect. (Intended for debugging purposes.)
pub
fn
values
(
&
self
)
->
Vec
<&
JsValue
>
{
match
self
{
Effect
::
Call
{
func
,
args
,
..
}
=>
{
let
mut
result
=
vec!
[
&**
func
];
result
.extend
(
args
.iter
()
.flat_map
(|
arg
|
{
match
arg
{
EffectArg
::
Value
(
val
)
=>
vec!
[
val
],
EffectArg
::
Closure
(
func
,
block
)
=>
std
::
iter
::
once
(
func
)
.chain
(
block
.effects
.iter
()
.flat_map
(|
e
|
e
.values
()))
.collect
(),
EffectArg
::
Spread
=>
vec!
[],
}
}));
result
}
Effect
::
MemberCall
{
obj
,
prop
,
args
,
..
}
=>
{
let
mut
result
=
vec!
[
&**
obj
,
&**
prop
];
result
.extend
(
args
.iter
()
.flat_map
(|
arg
|
{
match
arg
{
EffectArg
::
Value
(
val
)
=>
vec!
[
val
],
EffectArg
::
Closure
(
func
,
block
)
=>
std
::
iter
::
once
(
func
)
.chain
(
block
.effects
.iter
()
.flat_map
(|
e
|
e
.values
()))
.collect
(),
EffectArg
::
Spread
=>
vec!
[],
}
}));
result
}
Effect
::
Conditional
{
condition
,
kind
,
..
}
=>
{
let
mut
result
=
vec!
[
&**
condition
];
match
&**
kind
{
ConditionalKind
::
If
{
then
:
block
}
|
ConditionalKind
::
Else
{
r
#
else
:
block
}
|
ConditionalKind
::
And
{
expr
:
block
,
..
}
|
ConditionalKind
::
Or
{
expr
:
block
,
..
}
|
ConditionalKind
::
NullishCoalescing
{
expr
:
block
,
..
}
|
ConditionalKind
::
Labeled
{
body
:
block
}
=>
{
result
.extend
(
block
.effects
.iter
()
.flat_map
(|
e
|
e
.values
()));
}
ConditionalKind
::
IfElse
{
then
,
r
#
else
,
..
}
|
ConditionalKind
::
Ternary
{
then
,
r
#
else
,
..
}
=>
{
result
.extend
(
then
.effects
.iter
()
.chain
(
r
#
else
.effects
.iter
())
.flat_map
(|
e
|
e
.values
()),
);
}
ConditionalKind
::
IfElseMultiple
{
then
,
r
#
else
,
..
}
=>
{
result
.extend
(
then
.iter
()
.flat_map
(|
b
|
b
.effects
.iter
()
.flat_map
(|
e
|
e
.values
()))
.chain
(
r
#
else
.iter
()
.flat_map
(|
b
|
b
.effects
.iter
()
.flat_map
(|
e
|
e
.values
())),
),
);
}
};
result
}
Effect
::
Member
{
obj
,
prop
,
..
}
=>
{
vec!
[
obj
,
prop
]
}
Effect
::
TypeOf
{
arg
,
..
}
=>
{
vec!
[
arg
]
}
Effect
::
FreeVar
{
..
}
|
Effect
::
ImportedBinding
{
..
}
|
Effect
::
ImportMeta
{
..
}
|
Effect
::
Unreachable
{
..
}
=>
vec!
[],
}
}
}
pub
enum
AssignmentScope
{
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
View file @
5c9525be
...
...
@@ -22,16 +22,23 @@ where
RF
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
F
:
'a
+
Fn
(
JsValue
)
->
RF
+
Sync
,
{
// use tracing::Instrument;
// let span = tracing::trace_span!("link", steps = tracing::field::Empty);
val
.normalize
();
let
(
val
,
steps
)
=
link_internal_iterative
(
graph
,
val
,
early_visitor
,
visitor
,
fun_args_values
,
var_cache
,
)
let
(
val
,
steps
)
=
async
{
link_internal_iterative
(
graph
,
val
,
early_visitor
,
visitor
,
fun_args_values
,
var_cache
,
)
.await
}
// .instrument(span.clone())
.await
?
;
// span.record("steps", steps);
Ok
((
val
,
steps
))
}
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
5c9525be
...
...
@@ -964,7 +964,69 @@ async fn analyze_ecmascript_module_internal(
.instrument
(
span
)
.await
?
;
let
span
=
tracing
::
trace_span!
(
"effects processing"
);
#[cfg(debug_assertions)]
{
static
HISTOGRAM
:
once_cell
::
sync
::
Lazy
<
Option
<
String
>>
=
once_cell
::
sync
::
Lazy
::
new
(||
std
::
env
::
var
(
"TURBOPACK_JSVALUE_HISTOGRAM"
)
.ok
());
if
let
Some
(
p
)
=
HISTOGRAM
.as_ref
()
&&
path
.path
.ends_with
(
p
)
{
let
mut
histogram
=
vec!
[];
let
mut
add
=
|
v
:
u32
|
{
let
scaled
=
(
v
/
10
)
as
usize
;
if
histogram
.len
()
<
scaled
+
1
{
histogram
.resize
(
scaled
+
1
,
0
);
}
histogram
[
scaled
]
+=
1u
size
;
};
for
(
name
,
v
)
in
&
var_graph
.values
{
let
size
=
v
.value
.total_nodes
();
add
(
size
);
if
size
>
100
{
println!
(
"big jsvalue {name:?} {size} {}"
,
v
.value
)
}
}
for
effect
in
&
var_graph
.effects
{
for
v
in
effect
.values
()
{
let
size
=
v
.total_nodes
();
add
(
size
);
if
size
>
100
{
println!
(
"big jsvalue in effect {size} {v}"
)
}
}
}
if
!
histogram
.is_empty
()
{
let
scale
=
150f32
/
(
*
histogram
.iter
()
.max
()
.unwrap
()
as
f32
);
for
(
i
,
count
)
in
histogram
.into_iter
()
.enumerate
()
{
let
bar
=
"*"
.repeat
((
count
as
f32
*
scale
)
as
usize
);
println!
(
"{i:3}: {bar} ({count})"
);
}
}
}
}
let
emit_effect_spans
=
if
cfg!
(
debug_assertions
)
{
static
PRINT_CHUNK_GROUP_INFO
:
Lazy
<
bool
>
=
Lazy
::
new
(||
match
std
::
env
::
var_os
(
"TURBOPACK_TRACE_EFFECTS"
)
{
Some
(
v
)
=>
v
==
"1"
,
None
=>
false
,
});
*
PRINT_CHUNK_GROUP_INFO
}
else
{
false
};
macro_rules!
effect_trace_span
{
(
$
(
$args:tt
)
*
)
=>
{
if
emit_effect_spans
{
tracing
::
trace_span!
(
$
(
$args
)
*
)
}
else
{
tracing
::
Span
::
none
()
}
};
}
let
span
=
tracing
::
trace_span!
(
"effects processing"
,
count
=
var_graph
.effects
.len
());
async
{
let
effects
=
take
(
&
mut
var_graph
.effects
);
...
...
@@ -1018,12 +1080,15 @@ async fn analyze_ecmascript_module_internal(
Action
::
Effect
(
effect
)
=>
effect
,
};
let
add_actions
=
|
actions
:
Vec
<
Action
>
|
queue_stack
.lock
()
.extend
(
actions
.into_iter
()
.rev
());
let
add_effects
=
|
effects
:
Vec
<
Effect
>
|
{
queue_stack
.lock
()
.extend
(
effects
.into_iter
()
.map
(
Action
::
Effect
)
.rev
())
add_actions
(
effects
.into_iter
()
.map
(
Action
::
Effect
)
.collect
())
};
let
analysis
=
&
mut
analysis
;
let
analysis_state
=
&
mut
analysis_state
;
match
effect
{
Effect
::
Unreachable
{
start_ast_path
}
=>
{
debug_assert!
(
...
...
@@ -1031,6 +1096,7 @@ async fn analyze_ecmascript_module_internal(
"unexpected Effect::Unreachable in tracing mode"
);
let
_tracing_span
=
effect_trace_span!
(
"handle unreachable"
)
.entered
();
analysis
.add_code_gen
(
Unreachable
::
new
(
AstPathRange
::
StartAfter
(
start_ast_path
)));
}
...
...
@@ -1040,158 +1106,163 @@ async fn analyze_ecmascript_module_internal(
ast_path
:
condition_ast_path
,
span
:
_
,
}
=>
{
// Don't replace condition with it's truth-y value, if it has side effects
// (e.g. function calls)
let
condition_has_side_effects
=
condition
.has_side_effects
();
async
{
// Don't replace condition with it's truth-y value, if it has side effects
// (e.g. function calls)
let
condition_has_side_effects
=
condition
.has_side_effects
();
let
condition
=
analysis_state
.link_value
(
*
condition
,
ImportAttributes
::
empty_ref
())
.await
?
;
let
condition
=
analysis_state
.link_value
(
*
condition
,
ImportAttributes
::
empty_ref
())
.await
?
;
macro_rules!
inactive
{
(
$block:ident
)
=>
{
if
analyze_mode
.is_code_gen
()
{
analysis
.add_code_gen
(
Unreachable
::
new
(
$block
.range
.clone
()));
}
};
}
macro_rules!
condition
{
(
$expr:expr
)
=>
{
if
analyze_mode
.is_code_gen
()
&&
!
condition_has_side_effects
{
analysis
.add_code_gen
(
ConstantConditionCodeGen
::
new
(
$expr
,
condition_ast_path
.to_vec
()
.into
(),
));
}
};
}
macro_rules!
active
{
(
$block:ident
)
=>
{
queue_stack
.get_mut
()
.extend
(
$block
.effects
.into_iter
()
.map
(
Action
::
Effect
)
.rev
())
};
}
match
*
kind
{
ConditionalKind
::
If
{
then
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
active!
(
then
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
inactive!
(
then
);
}
None
=>
{
active!
(
then
);
}
},
ConditionalKind
::
Else
{
r
#
else
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
inactive!
(
r
#
else
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
active!
(
r
#
else
);
}
None
=>
{
active!
(
r
#
else
);
}
},
ConditionalKind
::
IfElse
{
then
,
r
#
else
}
|
ConditionalKind
::
Ternary
{
then
,
r
#
else
}
=>
{
match
condition
.is_truthy
()
{
macro_rules!
inactive
{
(
$block:ident
)
=>
{
if
analyze_mode
.is_code_gen
()
{
analysis
.add_code_gen
(
Unreachable
::
new
(
$block
.range
.clone
()));
}
};
}
macro_rules!
condition
{
(
$expr:expr
)
=>
{
if
analyze_mode
.is_code_gen
()
&&
!
condition_has_side_effects
{
analysis
.add_code_gen
(
ConstantConditionCodeGen
::
new
(
$expr
,
condition_ast_path
.to_vec
()
.into
(),
));
}
};
}
macro_rules!
active
{
(
$block:ident
)
=>
{
queue_stack
.get_mut
()
.extend
(
$block
.effects
.into_iter
()
.map
(
Action
::
Effect
)
.rev
())
};
}
match
*
kind
{
ConditionalKind
::
If
{
then
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
active!
(
then
);
inactive!
(
r
#
else
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
active!
(
r
#
else
);
inactive!
(
then
);
}
None
=>
{
active!
(
then
);
active!
(
r
#
else
);
}
}
}
ConditionalKind
::
IfElseMultiple
{
then
,
r
#
else
}
=>
{
match
condition
.is_truthy
()
{
},
ConditionalKind
::
Else
{
r
#
else
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
for
then
in
then
{
active!
(
then
);
}
for
r
#
else
in
r
#
else
{
inactive!
(
r
#
else
);
}
inactive!
(
r
#
else
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
for
then
in
then
{
inactive!
(
then
);
}
for
r
#
else
in
r
#
else
{
active!
(
r
#
else
);
}
active!
(
r
#
else
);
}
None
=>
{
for
then
in
then
{
active!
(
r
#
else
);
}
},
ConditionalKind
::
IfElse
{
then
,
r
#
else
}
|
ConditionalKind
::
Ternary
{
then
,
r
#
else
}
=>
{
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
active!
(
then
);
inactive!
(
r
#
else
);
}
for
r
#
else
in
r
#
else
{
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
active!
(
r
#
else
);
inactive!
(
then
);
}
None
=>
{
active!
(
then
);
active!
(
r
#
else
);
}
}
}
}
ConditionalKind
::
And
{
expr
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
active!
(
expr
);
}
Some
(
false
)
=>
{
// The condition value needs to stay since it's used
inactive!
(
expr
);
}
None
=>
{
active!
(
expr
);
}
},
ConditionalKind
::
Or
{
expr
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
// The condition value needs to stay since it's used
inactive!
(
expr
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
active!
(
expr
);
}
None
=>
{
active!
(
expr
);
ConditionalKind
::
IfElseMultiple
{
then
,
r
#
else
}
=>
{
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Truthy
);
for
then
in
then
{
active!
(
then
);
}
for
r
#
else
in
r
#
else
{
inactive!
(
r
#
else
);
}
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
for
then
in
then
{
inactive!
(
then
);
}
for
r
#
else
in
r
#
else
{
active!
(
r
#
else
);
}
}
None
=>
{
for
then
in
then
{
active!
(
then
);
}
for
r
#
else
in
r
#
else
{
active!
(
r
#
else
);
}
}
}
}
},
ConditionalKind
::
NullishCoalescing
{
expr
}
=>
{
match
condition
.is_nullish
()
{
ConditionalKind
::
And
{
expr
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Nullish
);
condition!
(
ConstantConditionValue
::
Truthy
);
active!
(
expr
);
}
Some
(
false
)
=>
{
// The condition value needs to stay since it's used
inactive!
(
expr
);
}
None
=>
{
active!
(
expr
);
}
},
ConditionalKind
::
Or
{
expr
}
=>
match
condition
.is_truthy
()
{
Some
(
true
)
=>
{
// The condition value needs to stay since it's used
inactive!
(
expr
);
}
Some
(
false
)
=>
{
condition!
(
ConstantConditionValue
::
Falsy
);
active!
(
expr
);
}
None
=>
{
active!
(
expr
);
}
},
ConditionalKind
::
NullishCoalescing
{
expr
}
=>
{
match
condition
.is_nullish
()
{
Some
(
true
)
=>
{
condition!
(
ConstantConditionValue
::
Nullish
);
active!
(
expr
);
}
Some
(
false
)
=>
{
inactive!
(
expr
);
}
None
=>
{
active!
(
expr
);
}
}
}
ConditionalKind
::
Labeled
{
body
}
=>
{
active!
(
body
);
}
}
ConditionalKind
::
Labeled
{
body
}
=>
{
active!
(
body
);
}
anyhow
::
Ok
(())
}
.instrument
(
effect_trace_span!
(
"handle conditional"
))
.await
?
;
}
Effect
::
Call
{
func
,
...
...
@@ -1207,21 +1278,25 @@ async fn analyze_ecmascript_module_internal(
continue
;
}
let
func
=
analysis_state
.link_value
(
*
func
,
eval_context
.imports
.get_attributes
(
span
))
.await
?
;
async
move
{
let
func
=
analysis_state
.link_value
(
*
func
,
eval_context
.imports
.get_attributes
(
span
))
.await
?
;
handle_call
(
&
ast_path
,
span
,
func
,
args
,
&
analysis_state
,
&
add_effects
,
&
mut
analysis
,
in_try
,
new
,
)
handle_call
(
&
ast_path
,
span
,
func
,
args
,
analysis_state
,
&
add_effects
,
analysis
,
in_try
,
new
,
)
.await
}
.instrument
(
effect_trace_span!
(
"handle call"
))
.await
?
;
}
Effect
::
MemberCall
{
...
...
@@ -1239,35 +1314,36 @@ async fn analyze_ecmascript_module_internal(
continue
;
}
let
func
=
analysis_state
.link_value
(
JsValue
::
member
(
obj
.clone
(),
prop
),
eval_context
.imports
.get_attributes
(
span
),
)
.await
?
;
if
!
new
&&
matches!
(
func
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
ArrayFilter
|
WellKnownFunctionKind
::
ArrayForEach
|
WellKnownFunctionKind
::
ArrayMap
async
move
{
let
func
=
analysis_state
.link_value
(
JsValue
::
member
(
obj
.clone
(),
prop
),
eval_context
.imports
.get_attributes
(
span
),
)
)
&&
let
[
EffectArg
::
Closure
(
value
,
block
)]
=
&
mut
args
[
..
]
&&
let
JsValue
::
Array
{
items
:
ref
mut
values
,
mutable
,
..
}
=
analysis_state
.link_value
(
*
obj
,
eval_context
.imports
.get_attributes
(
span
))
.await
?
{
*
value
=
analysis_state
.link_value
(
take
(
value
),
ImportAttributes
::
empty_ref
())
.await
?
;
if
let
JsValue
::
Function
(
_
,
func_ident
,
_
)
=
value
{
if
!
new
&&
matches!
(
func
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
ArrayFilter
|
WellKnownFunctionKind
::
ArrayForEach
|
WellKnownFunctionKind
::
ArrayMap
)
)
&&
let
[
EffectArg
::
Closure
(
value
,
block
)]
=
&
mut
args
[
..
]
&&
let
JsValue
::
Array
{
items
:
ref
mut
values
,
mutable
,
..
}
=
analysis_state
.link_value
(
*
obj
,
eval_context
.imports
.get_attributes
(
span
))
.await
?
&&
let
_
=
(
*
value
=
analysis_state
.link_value
(
take
(
value
),
ImportAttributes
::
empty_ref
())
.await
?
)
&&
let
JsValue
::
Function
(
_
,
func_ident
,
_
)
=
value
{
let
mut
closure_arg
=
JsValue
::
alternatives
(
take
(
values
));
if
mutable
{
closure_arg
.add_unknown_mutations
(
true
);
...
...
@@ -1276,28 +1352,25 @@ async fn analyze_ecmascript_module_internal(
.fun_args_values
.get_mut
()
.insert
(
*
func_ident
,
vec!
[
closure_arg
]);
queue_stack
.get_mut
()
.push
(
Action
::
LeaveScope
(
*
func_ident
));
queue_stack
.get_mut
()
.extend
(
take
(
&
mut
block
.effects
)
.into_iter
()
.map
(
Action
::
Effect
)
.rev
(),
);
continue
;
add_actions
(
vec!
[
Action
::
LeaveScope
(
*
func_ident
)]);
add_effects
(
take
(
&
mut
block
.effects
));
}
else
{
handle_call
(
&
ast_path
,
span
,
func
,
args
,
analysis_state
,
&
add_effects
,
analysis
,
in_try
,
new
,
)
.await
?
;
}
anyhow
::
Ok
(())
}
handle_call
(
&
ast_path
,
span
,
func
,
args
,
&
analysis_state
,
&
add_effects
,
&
mut
analysis
,
in_try
,
new
,
)
.instrument
(
effect_trace_span!
(
"handle member call"
))
.await
?
;
}
Effect
::
FreeVar
{
...
...
@@ -1309,26 +1382,30 @@ async fn analyze_ecmascript_module_internal(
analyze_mode
.is_code_gen
(),
"unexpected Effect::FreeVar in tracing mode"
);
// FreeVar("require") might be turbopackIgnore-d
if
!
analysis_state
.link_value
(
JsValue
::
FreeVar
(
var
.clone
()),
eval_context
.imports
.get_attributes
(
span
),
)
.await
?
.is_unknown
()
{
// Call handle free var
handle_free_var
(
&
ast_path
,
JsValue
::
FreeVar
(
var
),
span
,
&
analysis_state
,
&
mut
analysis
,
)
.await
?
;
async
move
{
// FreeVar("require") might be turbopackIgnore-d
if
!
analysis_state
.link_value
(
JsValue
::
FreeVar
(
var
.clone
()),
eval_context
.imports
.get_attributes
(
span
),
)
.await
?
.is_unknown
()
{
// Call handle free var
handle_free_var
(
&
ast_path
,
JsValue
::
FreeVar
(
var
),
span
,
analysis_state
,
analysis
,
)
.await
?
;
}
anyhow
::
Ok
(())
}
.instrument
(
effect_trace_span!
(
"handle free var"
))
.await
?
;
}
Effect
::
Member
{
obj
,
...
...
@@ -1340,16 +1417,21 @@ async fn analyze_ecmascript_module_internal(
analyze_mode
.is_code_gen
(),
"unexpected Effect::Member in tracing mode"
);
async
move
{
// Intentionally not awaited because `handle_member` reads this only when
// needed
// Intentionally not awaited because `handle_member` reads this only when
// needed
let
obj
=
analysis_state
.link_value
(
*
obj
,
ImportAttributes
::
empty_ref
());
let
prop
=
analysis_state
.link_value
(
*
prop
,
ImportAttributes
::
empty_ref
())
.await
?
;
// Intentionally not awaited because `handle_member` reads this only when needed
let
obj
=
analysis_state
.link_value
(
*
obj
,
ImportAttributes
::
empty_ref
());
let
prop
=
analysis_state
.link_value
(
*
prop
,
ImportAttributes
::
empty_ref
())
.await
?
;
handle_member
(
&
ast_path
,
obj
,
prop
,
span
,
&
analysis_state
,
&
mut
analysis
)
.await
?
;
handle_member
(
&
ast_path
,
obj
,
prop
,
span
,
analysis_state
,
analysis
)
.await
}
.instrument
(
effect_trace_span!
(
"handle member"
))
.await
?
;
}
Effect
::
ImportedBinding
{
esm_reference_index
,
...
...
@@ -1361,51 +1443,50 @@ async fn analyze_ecmascript_module_internal(
continue
;
};
if
let
Some
(
"__turbopack_module_id__"
)
=
export
.as_deref
()
{
analysis
.add_reference_code_gen
(
EsmModuleIdAssetReference
::
new
(
*
r
),
ast_path
.into
(),
)
}
else
{
if
matches!
(
options
.tree_shaking_mode
,
Some
(
TreeShakingMode
::
ReexportsOnly
)
)
{
let
original_reference
=
r
.await
?
;
if
original_reference
.export_name
.is_none
()
&&
export
.is_some
()
&&
let
Some
(
export
)
=
export
{
// Rewrite `import * as ns from 'foo'; foo.bar()` to behave like
// `import {bar} from 'foo'; bar()` for tree shaking purposes.
let
named_reference
=
analysis
.add_esm_reference_namespace_resolved
(
esm_reference_index
,
export
.clone
(),
||
{
EsmAssetReference
::
new
(
original_reference
.origin
,
original_reference
.request
.clone
(),
original_reference
.issue_source
,
original_reference
.annotations
.clone
(),
Some
(
ModulePart
::
export
(
export
.clone
())),
original_reference
.import_externals
,
)
.resolved_cell
()
},
);
analysis
.add_code_gen
(
EsmBinding
::
new_keep_this
(
named_reference
,
Some
(
export
),
ast_path
.into
(),
));
continue
;
}
let
tree_shaking_mode
=
options
.tree_shaking_mode
;
async
move
{
if
let
Some
(
"__turbopack_module_id__"
)
=
export
.as_deref
()
{
analysis
.add_reference_code_gen
(
EsmModuleIdAssetReference
::
new
(
*
r
),
ast_path
.into
(),
)
}
else
if
matches!
(
tree_shaking_mode
,
Some
(
TreeShakingMode
::
ReexportsOnly
))
&&
let
original_reference
=
r
.await
?
&&
original_reference
.export_name
.is_none
()
&&
export
.is_some
()
&&
let
Some
(
export
)
=
export
{
// Rewrite `import * as ns from 'foo'; foo.bar()` to behave like
// `import {bar} from 'foo'; bar()` for tree shaking purposes.
let
named_reference
=
analysis
.add_esm_reference_namespace_resolved
(
esm_reference_index
,
export
.clone
(),
||
{
EsmAssetReference
::
new
(
original_reference
.origin
,
original_reference
.request
.clone
(),
original_reference
.issue_source
,
original_reference
.annotations
.clone
(),
Some
(
ModulePart
::
export
(
export
.clone
())),
original_reference
.import_externals
,
)
.resolved_cell
()
},
);
analysis
.add_code_gen
(
EsmBinding
::
new_keep_this
(
named_reference
,
Some
(
export
),
ast_path
.into
(),
));
}
else
{
analysis
.add_esm_reference
(
esm_reference_index
);
analysis
.add_code_gen
(
EsmBinding
::
new
(
*
r
,
export
,
ast_path
.into
()));
}
analysis
.add_esm_reference
(
esm_reference_index
);
analysis
.add_code_gen
(
EsmBinding
::
new
(
*
r
,
export
,
ast_path
.into
()));
anyhow
::
Ok
(())
}
.instrument
(
effect_trace_span!
(
"handle imported binding"
))
.await
?
;
}
Effect
::
TypeOf
{
arg
,
...
...
@@ -1416,24 +1497,33 @@ async fn analyze_ecmascript_module_internal(
analyze_mode
.is_code_gen
(),
"unexpected Effect::TypeOf in tracing mode"
);
let
arg
=
analysis_state
.link_value
(
*
arg
,
ImportAttributes
::
empty_ref
())
.await
?
;
handle_typeof
(
&
ast_path
,
arg
,
span
,
&
analysis_state
,
&
mut
analysis
)
.await
?
;
async
move
{
let
arg
=
analysis_state
.link_value
(
*
arg
,
ImportAttributes
::
empty_ref
())
.await
?
;
handle_typeof
(
&
ast_path
,
arg
,
span
,
analysis_state
,
analysis
)
.await
}
.instrument
(
effect_trace_span!
(
"handle typeof"
))
.await
?
;
}
Effect
::
ImportMeta
{
ast_path
,
span
:
_
}
=>
{
debug_assert!
(
analyze_mode
.is_code_gen
(),
"unexpected Effect::ImportMeta in tracing mode"
);
if
analysis_state
.first_import_meta
{
analysis_state
.first_import_meta
=
false
;
analysis
.add_code_gen
(
ImportMetaBinding
::
new
(
source
.ident
()
.path
()
.owned
()
.await
?
,
));
}
async
move
{
if
analysis_state
.first_import_meta
{
analysis_state
.first_import_meta
=
false
;
analysis
.add_code_gen
(
ImportMetaBinding
::
new
(
source
.ident
()
.path
()
.owned
()
.await
?
,
));
}
analysis
.add_code_gen
(
ImportMetaRef
::
new
(
ast_path
.into
()));
analysis
.add_code_gen
(
ImportMetaRef
::
new
(
ast_path
.into
()));
anyhow
::
Ok
(())
}
.instrument
(
effect_trace_span!
(
"handle import meta"
))
.await
?
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment