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
86fd4ea1
Commit
86fd4ea1
authored
Mar 05, 2026
by
Matt Mastracci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cargo fmt
parent
90c17993
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
201 deletions
+175
-201
builtin.rs
...opack/crates/turbopack-ecmascript/src/analyzer/builtin.rs
+10
-47
mod.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
+93
-83
well_known.rs
...ck/crates/turbopack-ecmascript/src/analyzer/well_known.rs
+3
-9
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+69
-62
No files found.
turbopack/crates/turbopack-ecmascript/src/analyzer/builtin.rs
View file @
86fd4ea1
...
@@ -73,12 +73,7 @@ pub fn early_replace_builtin(value: &mut JsValue) -> bool {
...
@@ -73,12 +73,7 @@ pub fn early_replace_builtin(value: &mut JsValue) -> bool {
}
}
// matching property access like `obj.prop` when we don't know what the obj is.
// matching property access like `obj.prop` when we don't know what the obj is.
// We can early return here
// We can early return here
JsValue
::
Member
(
_
,
obj
,
prop
)
JsValue
::
Member
(
_
,
obj
,
prop
)
if
matches!
(
obj
.as_ref
(),
JsValue
::
Unknown
{
..
})
=>
{
if
matches!
(
obj
.as_ref
(),
JsValue
::
Unknown
{
..
}
)
=>
{
let
JsValue
::
Unknown
{
let
JsValue
::
Unknown
{
has_side_effects
,
..
has_side_effects
,
..
}
=
obj
.as_ref
()
}
=
obj
.as_ref
()
...
@@ -140,10 +135,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -140,10 +135,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
prop
:
&
mut
Arc
<
JsValue
>
,
prop
:
&
mut
Arc
<
JsValue
>
,
)
->
JsValue
{
)
->
JsValue
{
items
.push
(
JsValue
::
unknown
(
items
.push
(
JsValue
::
unknown
(
JsValue
::
member
(
JsValue
::
member
(
Arc
::
new
(
JsValue
::
array
(
Vec
::
new
())),
take
(
prop
)),
Arc
::
new
(
JsValue
::
array
(
Vec
::
new
())),
take
(
prop
),
),
false
,
false
,
"unknown array prototype methods or values"
,
"unknown array prototype methods or values"
,
));
));
...
@@ -158,12 +150,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -158,12 +150,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
// Returns Some((item, mutable)) if found, None for invalid index,
// Returns Some((item, mutable)) if found, None for invalid index,
// or Some((default, false)) with separate handling for non-index
// or Some((default, false)) with separate handling for non-index
let
result
=
{
let
result
=
{
let
JsValue
::
Array
{
let
JsValue
::
Array
{
items
,
mutable
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
items
,
mutable
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
let
JsValue
::
Constant
(
ConstantValue
::
Num
(
num
@
ConstantNumber
(
_
)))
=
let
JsValue
::
Constant
(
ConstantValue
::
Num
(
num
@
ConstantNumber
(
_
)))
=
...
@@ -231,10 +218,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -231,10 +218,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
}
else
{
}
else
{
// otherwise we can say that this might gives an item of the array
// otherwise we can say that this might gives an item of the array
// but we also add an unknown value to the alternatives for other properties
// but we also add an unknown value to the alternatives for other properties
let
JsValue
::
Array
{
let
JsValue
::
Array
{
items
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
items
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
*
value
=
items_to_alternatives
(
items
,
prop
);
*
value
=
items_to_alternatives
(
items
,
prop
);
...
@@ -267,10 +251,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -267,10 +251,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
}
}
if
include_unknown
{
if
include_unknown
{
values
.push
(
JsValue
::
unknown
(
values
.push
(
JsValue
::
unknown
(
JsValue
::
member
(
JsValue
::
member
(
Arc
::
new
(
JsValue
::
object
(
Vec
::
new
())),
take
(
prop
)),
Arc
::
new
(
JsValue
::
object
(
Vec
::
new
())),
take
(
prop
),
),
true
,
true
,
"unknown object prototype methods or values"
,
"unknown object prototype methods or values"
,
));
));
...
@@ -316,12 +297,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -316,12 +297,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
// - Ok((new_value, mutable)) - replace *value with new_value
// - Ok((new_value, mutable)) - replace *value with new_value
// - Err(()) - call value.make_unknown for spread case
// - Err(()) - call value.make_unknown for spread case
let
result
:
Result
<
(
JsValue
,
bool
),
()
>
=
{
let
result
:
Result
<
(
JsValue
,
bool
),
()
>
=
{
let
JsValue
::
Object
{
let
JsValue
::
Object
{
parts
,
mutable
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
parts
,
mutable
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
let
mutable
=
*
mutable
;
let
mutable
=
*
mutable
;
...
@@ -418,10 +394,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -418,10 +394,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
);
);
true
true
}
else
{
}
else
{
let
JsValue
::
Object
{
let
JsValue
::
Object
{
parts
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
parts
,
..
}
=
Arc
::
make_mut
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
*
value
=
parts_to_alternatives
(
parts
,
prop
,
true
);
*
value
=
parts_to_alternatives
(
parts
,
prop
,
true
);
...
@@ -454,8 +427,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -454,8 +427,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
)
)
})
{
})
{
{
{
let
JsValue
::
Array
{
items
,
mutable
,
..
}
=
let
JsValue
::
Array
{
items
,
mutable
,
..
}
=
Arc
::
make_mut
(
obj
)
Arc
::
make_mut
(
obj
)
else
{
else
{
unreachable!
()
unreachable!
()
};
};
...
@@ -532,13 +504,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -532,13 +504,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
*
value
=
JsValue
::
alternatives
(
*
value
=
JsValue
::
alternatives
(
take
(
values
)
take
(
values
)
.into_iter
()
.into_iter
()
.map
(|
alt
|
{
.map
(|
alt
|
JsValue
::
member_call
(
Arc
::
new
(
alt
),
prop
.clone
(),
args
.clone
()))
JsValue
::
member_call
(
Arc
::
new
(
alt
),
prop
.clone
(),
args
.clone
(),
)
})
.collect
(),
.collect
(),
);
);
return
true
;
return
true
;
...
@@ -560,10 +526,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
...
@@ -560,10 +526,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
// without special handling, we convert it into a normal call like
// without special handling, we convert it into a normal call like
// `(obj.prop)(arg1, arg2, ...)`
// `(obj.prop)(arg1, arg2, ...)`
*
value
=
JsValue
::
call
(
*
value
=
JsValue
::
call
(
Arc
::
new
(
JsValue
::
member
(
take
(
obj
),
take
(
prop
))),
take
(
args
));
Arc
::
new
(
JsValue
::
member
(
take
(
obj
),
take
(
prop
))),
take
(
args
),
);
true
true
}
}
// match calls when the callee are multiple alternative functions like `(func1 |
// match calls when the callee are multiple alternative functions like `(func1 |
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
View file @
86fd4ea1
...
@@ -2321,11 +2321,10 @@ impl JsValue {
...
@@ -2321,11 +2321,10 @@ impl JsValue {
logical_property
:
_
,
logical_property
:
_
,
}
=>
merge_if_known
(
values
,
JsValue
::
is_string
),
}
=>
merge_if_known
(
values
,
JsValue
::
is_string
),
JsValue
::
Call
(
JsValue
::
Call
(
_
,
callee
,
_
)
_
,
if
matches!
(
callee
,
callee
.as_ref
(),
_
,
JsValue
::
WellKnownFunction
(
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireResolve
WellKnownFunctionKind
::
RequireResolve
|
WellKnownFunctionKind
::
PathJoin
|
WellKnownFunctionKind
::
PathJoin
|
WellKnownFunctionKind
::
PathResolve
(
..
)
|
WellKnownFunctionKind
::
PathResolve
(
..
)
...
@@ -2334,7 +2333,11 @@ impl JsValue {
...
@@ -2334,7 +2333,11 @@ impl JsValue {
|
WellKnownFunctionKind
::
PathDirname
|
WellKnownFunctionKind
::
PathDirname
|
WellKnownFunctionKind
::
PathToFileUrl
|
WellKnownFunctionKind
::
PathToFileUrl
|
WellKnownFunctionKind
::
ProcessCwd
,
|
WellKnownFunctionKind
::
ProcessCwd
,
))
=>
Some
(
true
),
)
)
=>
{
Some
(
true
)
}
JsValue
::
Awaited
(
_
,
operand
)
=>
match
&**
operand
{
JsValue
::
Awaited
(
_
,
operand
)
=>
match
&**
operand
{
JsValue
::
Promise
(
_
,
v
)
=>
v
.is_string
(),
JsValue
::
Promise
(
_
,
v
)
=>
v
.is_string
(),
...
@@ -3529,11 +3532,13 @@ pub mod test_utils {
...
@@ -3529,11 +3532,13 @@ pub mod test_utils {
)
->
Result
<
(
JsValue
,
bool
)
>
{
)
->
Result
<
(
JsValue
,
bool
)
>
{
let
ImportAttributes
{
ignore
,
..
}
=
*
attributes
;
let
ImportAttributes
{
ignore
,
..
}
=
*
attributes
;
let
mut
new_value
=
match
v
{
let
mut
new_value
=
match
v
{
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
Import
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
Import
))
=>
match
&
args
[
0
]
{
)
=>
{
match
&
args
[
0
]
{
JsValue
::
Constant
(
ConstantValue
::
Str
(
v
))
=>
{
JsValue
::
Constant
(
ConstantValue
::
Str
(
v
))
=>
{
JsValue
::
promise
(
JsValue
::
Module
(
ModuleValue
{
JsValue
::
promise
(
JsValue
::
Module
(
ModuleValue
{
module
:
v
.as_atom
()
.into_owned
()
.into
(),
module
:
v
.as_atom
()
.into_owned
()
.into
(),
...
@@ -3541,20 +3546,19 @@ pub mod test_utils {
...
@@ -3541,20 +3546,19 @@ pub mod test_utils {
}))
}))
}
}
_
=>
v
.into_unknown
(
true
,
"import() non constant"
),
_
=>
v
.into_unknown
(
true
,
"import() non constant"
),
},
}
JsValue
::
Call
(
}
_
,
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
ref
callee
,
if
matches!
(
ref
args
,
callee
.as_ref
(),
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
CreateRequire
))
=>
{
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
CreateRequire
)
if
let
[
)
=>
JsValue
::
Member
(
{
_
,
if
let
[
JsValue
::
Member
(
_
,
obj
,
prop
)]
=
&
args
[
..
]
obj
,
&&
matches!
(
prop
,
obj
.as_ref
(),
),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
)
]
=
&
args
[
..
]
)
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
))
&&
matches!
(
prop
.as_ref
(),
JsValue
::
Constant
(
ConstantValue
::
Str
(
p
))
if
p
.as_str
()
==
"url"
)
&&
matches!
(
prop
.as_ref
(),
JsValue
::
Constant
(
ConstantValue
::
Str
(
p
))
if
p
.as_str
()
==
"url"
)
{
{
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
Require
)
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
Require
)
...
@@ -3562,19 +3566,24 @@ pub mod test_utils {
...
@@ -3562,19 +3566,24 @@ pub mod test_utils {
v
.into_unknown
(
true
,
"createRequire() non constant"
)
v
.into_unknown
(
true
,
"createRequire() non constant"
)
}
}
}
}
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireResolve
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireResolve
))
=>
match
&
args
[
0
]
{
)
=>
{
match
&
args
[
0
]
{
JsValue
::
Constant
(
v
)
=>
(
v
.to_string
()
+
"/resolved/lib/index.js"
)
.into
(),
JsValue
::
Constant
(
v
)
=>
(
v
.to_string
()
+
"/resolved/lib/index.js"
)
.into
(),
_
=>
v
.into_unknown
(
true
,
"require.resolve non constant"
),
_
=>
v
.into_unknown
(
true
,
"require.resolve non constant"
),
},
}
JsValue
::
Call
(
}
_
,
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
ref
callee
,
if
matches!
(
ref
args
,
callee
.as_ref
(),
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireContext
))
=>
match
parse_require_context
(
args
)
{
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireContext
)
)
=>
{
match
parse_require_context
(
args
)
{
Ok
(
options
)
=>
{
Ok
(
options
)
=>
{
let
mut
map
=
FxIndexMap
::
default
();
let
mut
map
=
FxIndexMap
::
default
();
...
@@ -3596,21 +3605,22 @@ pub mod test_utils {
...
@@ -3596,21 +3605,22 @@ pub mod test_utils {
))
))
}
}
Err
(
err
)
=>
v
.into_unknown
(
true
,
PrettyPrintError
(
&
err
)
.to_string
()),
Err
(
err
)
=>
v
.into_unknown
(
true
,
PrettyPrintError
(
&
err
)
.to_string
()),
},
}
JsValue
::
New
(
}
_
,
JsValue
::
New
(
_
,
ref
callee
,
ref
args
)
ref
callee
,
if
matches!
(
ref
args
,
callee
.as_ref
(),
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
URLConstructor
))
=>
{
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
URLConstructor
)
)
=>
{
if
let
[
if
let
[
JsValue
::
Constant
(
ConstantValue
::
Str
(
url
)),
JsValue
::
Constant
(
ConstantValue
::
Str
(
url
)),
JsValue
::
Member
(
JsValue
::
Member
(
_
,
obj
,
prop
),
_
,
obj
,
prop
,
),
]
=
&
args
[
..
]
]
=
&
args
[
..
]
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
))
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
)
)
&&
matches!
(
prop
.as_ref
(),
JsValue
::
Constant
(
ConstantValue
::
Str
(
p
))
if
p
.as_str
()
==
"url"
)
&&
matches!
(
prop
.as_ref
(),
JsValue
::
Constant
(
ConstantValue
::
Str
(
p
))
if
p
.as_str
()
==
"url"
)
{
{
// TODO avoid clone
// TODO avoid clone
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/well_known.rs
View file @
86fd4ea1
...
@@ -46,25 +46,19 @@ pub async fn replace_well_known(
...
@@ -46,25 +46,19 @@ pub async fn replace_well_known(
}
}
(
JsValue
::
Call
(
usize
,
callee
,
args
),
false
)
(
JsValue
::
Call
(
usize
,
callee
,
args
),
false
)
}
}
JsValue
::
Member
(
_
,
obj
,
prop
)
JsValue
::
Member
(
_
,
obj
,
prop
)
if
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
..
))
=>
{
if
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
..
))
=>
{
let
JsValue
::
WellKnownObject
(
kind
)
=
Arc
::
unwrap_or_clone
(
obj
)
else
{
let
JsValue
::
WellKnownObject
(
kind
)
=
Arc
::
unwrap_or_clone
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
well_known_object_member
(
kind
,
Arc
::
unwrap_or_clone
(
prop
),
compile_time_info
)
.await
?
well_known_object_member
(
kind
,
Arc
::
unwrap_or_clone
(
prop
),
compile_time_info
)
.await
?
}
}
JsValue
::
Member
(
_
,
obj
,
prop
)
JsValue
::
Member
(
_
,
obj
,
prop
)
if
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownFunction
(
..
))
=>
{
if
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownFunction
(
..
))
=>
{
let
JsValue
::
WellKnownFunction
(
kind
)
=
Arc
::
unwrap_or_clone
(
obj
)
else
{
let
JsValue
::
WellKnownFunction
(
kind
)
=
Arc
::
unwrap_or_clone
(
obj
)
else
{
unreachable!
()
unreachable!
()
};
};
well_known_function_member
(
kind
,
Arc
::
unwrap_or_clone
(
prop
))
well_known_function_member
(
kind
,
Arc
::
unwrap_or_clone
(
prop
))
}
}
JsValue
::
Member
(
_
,
ref
obj
,
ref
prop
)
JsValue
::
Member
(
_
,
ref
obj
,
ref
prop
)
if
matches!
(
obj
.as_ref
(),
JsValue
::
Array
{
..
})
=>
{
if
matches!
(
obj
.as_ref
(),
JsValue
::
Array
{
..
})
=>
{
match
prop
.as_ref
()
.as_str
()
{
match
prop
.as_ref
()
.as_str
()
{
Some
(
"filter"
)
=>
(
Some
(
"filter"
)
=>
(
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
ArrayFilter
),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
ArrayFilter
),
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
86fd4ea1
...
@@ -1143,7 +1143,10 @@ async fn analyze_ecmascript_module_internal(
...
@@ -1143,7 +1143,10 @@ async fn analyze_ecmascript_module_internal(
let
condition_has_side_effects
=
condition
.has_side_effects
();
let
condition_has_side_effects
=
condition
.has_side_effects
();
let
condition
=
analysis_state
let
condition
=
analysis_state
.link_value
(
Arc
::
unwrap_or_clone
(
condition
),
ImportAttributes
::
empty_ref
())
.link_value
(
Arc
::
unwrap_or_clone
(
condition
),
ImportAttributes
::
empty_ref
(),
)
.await
?
;
.await
?
;
macro_rules!
inactive
{
macro_rules!
inactive
{
...
@@ -1306,7 +1309,10 @@ async fn analyze_ecmascript_module_internal(
...
@@ -1306,7 +1309,10 @@ async fn analyze_ecmascript_module_internal(
}
}
let
func
=
analysis_state
let
func
=
analysis_state
.link_value
(
Arc
::
unwrap_or_clone
(
func
),
eval_context
.imports
.get_attributes
(
span
))
.link_value
(
Arc
::
unwrap_or_clone
(
func
),
eval_context
.imports
.get_attributes
(
span
),
)
.await
?
;
.await
?
;
handle_call
(
handle_call
(
...
@@ -1386,7 +1392,10 @@ async fn analyze_ecmascript_module_internal(
...
@@ -1386,7 +1392,10 @@ async fn analyze_ecmascript_module_internal(
mutable
,
mutable
,
..
..
}
=
analysis_state
}
=
analysis_state
.link_value
(
Arc
::
unwrap_or_clone
(
obj
),
eval_context
.imports
.get_attributes
(
span
))
.link_value
(
Arc
::
unwrap_or_clone
(
obj
),
eval_context
.imports
.get_attributes
(
span
),
)
.await
?
.await
?
{
{
*
value
=
analysis_state
*
value
=
analysis_state
...
@@ -1477,7 +1486,8 @@ async fn analyze_ecmascript_module_internal(
...
@@ -1477,7 +1486,8 @@ async fn analyze_ecmascript_module_internal(
);
);
// 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
(
Arc
::
unwrap_or_clone
(
obj
),
ImportAttributes
::
empty_ref
());
let
obj
=
analysis_state
.link_value
(
Arc
::
unwrap_or_clone
(
obj
),
ImportAttributes
::
empty_ref
());
let
prop
=
analysis_state
let
prop
=
analysis_state
.link_value
(
Arc
::
unwrap_or_clone
(
prop
),
ImportAttributes
::
empty_ref
())
.link_value
(
Arc
::
unwrap_or_clone
(
prop
),
ImportAttributes
::
empty_ref
())
...
@@ -2041,16 +2051,13 @@ where
...
@@ -2041,16 +2051,13 @@ where
match
func
{
match
func
{
WellKnownFunctionKind
::
URLConstructor
=>
{
WellKnownFunctionKind
::
URLConstructor
=>
{
let
args
=
linked_args
()
.await
?
;
let
args
=
linked_args
()
.await
?
;
if
let
[
if
let
[
url
,
JsValue
::
Member
(
_
,
obj
,
prop
)]
=
&
args
[
..
]
url
,
&&
matches!
(
JsValue
::
Member
(
obj
.as_ref
(),
_
,
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
)
obj
,
)
prop
,
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
meta_prop
))
=
),
prop
.as_ref
()
]
=
&
args
[
..
]
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
))
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
meta_prop
))
=
prop
.as_ref
()
&&
meta_prop
.as_str
()
==
"url"
&&
meta_prop
.as_str
()
==
"url"
{
{
let
pat
=
js_value_to_pattern
(
url
);
let
pat
=
js_value_to_pattern
(
url
);
...
@@ -3404,32 +3411,32 @@ async fn value_visitor_inner(
...
@@ -3404,32 +3411,32 @@ async fn value_visitor_inner(
return
Ok
(((
&*
value
)
.try_into
()
?
,
true
));
return
Ok
(((
&*
value
)
.try_into
()
?
,
true
));
}
}
let
value
=
match
v
{
let
value
=
match
v
{
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireResolve
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireResolve
))
=>
{
)
=>
{
require_resolve_visitor
(
origin
,
args
.clone
())
.await
?
require_resolve_visitor
(
origin
,
args
.clone
())
.await
?
}
}
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireContext
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireContext
))
=>
{
)
=>
{
require_context_visitor
(
origin
,
args
.clone
())
.await
?
require_context_visitor
(
origin
,
args
.clone
())
.await
?
}
}
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
_
)
_
,
if
matches!
(
ref
callee
,
_
,
)
if
matches!
(
callee
.as_ref
(),
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
RequireContextRequire
(
..
)
WellKnownFunctionKind
::
RequireContextRequire
(
..
)
|
WellKnownFunctionKind
::
RequireContextRequireKeys
(
..
)
|
WellKnownFunctionKind
::
RequireContextRequireKeys
(
..
)
|
WellKnownFunctionKind
::
RequireContextRequireResolve
(
..
),
|
WellKnownFunctionKind
::
RequireContextRequireResolve
(
..
),
)
)
)
=>
{
)
=>
{
// TODO: figure out how to do static analysis without invalidating the whole
// TODO: figure out how to do static analysis without invalidating the whole
// analysis when a new file gets added
// analysis when a new file gets added
v
.into_unknown
(
v
.into_unknown
(
...
@@ -3437,20 +3444,18 @@ async fn value_visitor_inner(
...
@@ -3437,20 +3444,18 @@ async fn value_visitor_inner(
"require.context() static analysis is currently limited"
,
"require.context() static analysis is currently limited"
,
)
)
}
}
JsValue
::
Call
(
JsValue
::
Call
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
CreateRequire
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
CreateRequire
))
=>
{
)
=>
{
// Only support `createRequire(import.meta.url)` for now
// Only support `createRequire(import.meta.url)` for now
if
let
[
if
let
[
JsValue
::
Member
(
_
,
obj
,
prop
)]
=
&
args
[
..
]
JsValue
::
Member
(
&&
matches!
(
_
,
obj
.as_ref
(),
obj
,
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
)
prop
,
)
),
]
=
&
args
[
..
]
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
))
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
prop
))
=
prop
.as_ref
()
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
prop
))
=
prop
.as_ref
()
&&
prop
.as_str
()
==
"url"
&&
prop
.as_str
()
==
"url"
{
{
...
@@ -3459,20 +3464,20 @@ async fn value_visitor_inner(
...
@@ -3459,20 +3464,20 @@ async fn value_visitor_inner(
v
.into_unknown
(
true
,
"createRequire() non constant"
)
v
.into_unknown
(
true
,
"createRequire() non constant"
)
}
}
}
}
JsValue
::
New
(
JsValue
::
New
(
_
,
ref
callee
,
ref
args
)
_
,
if
matches!
(
ref
callee
,
callee
.as_ref
(),
ref
args
,
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
URLConstructor
)
)
if
matches!
(
callee
.as_ref
(),
JsValue
::
WellKnownFunction
(
WellKnownFunctionKind
::
URLConstructor
))
=>
{
)
=>
{
if
let
[
if
let
[
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
url
)),
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
url
)),
JsValue
::
Member
(
JsValue
::
Member
(
_
,
obj
,
prop
),
_
,
obj
,
prop
,
),
]
=
&
args
[
..
]
]
=
&
args
[
..
]
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
))
&&
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
ImportMeta
)
)
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
prop
))
=
prop
.as_ref
()
&&
let
JsValue
::
Constant
(
super
::
analyzer
::
ConstantValue
::
Str
(
prop
))
=
prop
.as_ref
()
{
{
if
prop
.as_str
()
==
"url"
{
if
prop
.as_str
()
==
"url"
{
...
@@ -4306,8 +4311,10 @@ fn is_invoking_node_process_eval(args: &[JsValue]) -> bool {
...
@@ -4306,8 +4311,10 @@ fn is_invoking_node_process_eval(args: &[JsValue]) -> bool {
if
let
JsValue
::
Member
(
_
,
obj
,
constant
)
=
&
args
[
0
]
{
if
let
JsValue
::
Member
(
_
,
obj
,
constant
)
=
&
args
[
0
]
{
// Is the first argument to spawn `process.argv[]`?
// Is the first argument to spawn `process.argv[]`?
if
matches!
(
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
NodeProcessArgv
))
if
matches!
(
&&
let
JsValue
::
Constant
(
JsConstantValue
::
Num
(
ConstantNumber
(
num
)))
=
constant
.as_ref
()
obj
.as_ref
(),
JsValue
::
WellKnownObject
(
WellKnownObjectKind
::
NodeProcessArgv
)
)
&&
let
JsValue
::
Constant
(
JsConstantValue
::
Num
(
ConstantNumber
(
num
)))
=
constant
.as_ref
()
{
{
// Is it specifically `process.argv[0]`?
// Is it specifically `process.argv[0]`?
if
num
.is_zero
()
if
num
.is_zero
()
...
...
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