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
1155db53
Commit
1155db53
authored
Sep 18, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
skip odd members
parent
5e478e9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
10 deletions
+76
-10
well_known.rs
...ck/crates/turbopack-ecmascript/src/analyzer/well_known.rs
+49
-0
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+27
-10
No files found.
turbopack/crates/turbopack-ecmascript/src/analyzer/well_known.rs
View file @
1155db53
...
@@ -12,6 +12,55 @@ use super::{
...
@@ -12,6 +12,55 @@ use super::{
};
};
use
crate
::
analyzer
::
RequireContextValue
;
use
crate
::
analyzer
::
RequireContextValue
;
pub
fn
is_well_known_function_prop
(
value
:
&
str
)
->
bool
{
// TODO this separate list is very brittle
matches!
(
value
,
"arch"
|
"argv"
|
"assign"
|
"cache"
|
"context"
|
"createReadStream"
|
"cwd"
|
"default"
|
"dirname"
|
"endianness"
|
"env"
|
"execFile"
|
"execFileSync"
|
"exists"
|
"existsSync"
|
"filter"
|
"find"
|
"forEach"
|
"fork"
|
"join"
|
"keys"
|
"load"
|
"loadSync"
|
"map"
|
"meta"
|
"open"
|
"openSync"
|
"pathToFileURL"
|
"platform"
|
"promises"
|
"readFile"
|
"readFileSync"
|
"realpath"
|
"realpathSync"
|
"resolve"
|
"set"
|
"SetRootDir"
|
"silent"
|
"spawn"
|
"spawnSync"
|
"stat"
|
"statSync"
)
}
pub
async
fn
replace_well_known
(
pub
async
fn
replace_well_known
(
value
:
JsValue
,
value
:
JsValue
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
1155db53
...
@@ -138,6 +138,7 @@ use crate::{
...
@@ -138,6 +138,7 @@ use crate::{
imports
::{
ImportAnnotations
,
ImportAttributes
,
ImportedSymbol
,
Reexport
},
imports
::{
ImportAnnotations
,
ImportAttributes
,
ImportedSymbol
,
Reexport
},
parse_require_context
,
parse_require_context
,
top_level_await
::
has_top_level_await
,
top_level_await
::
has_top_level_await
,
well_known
::
is_well_known_function_prop
,
},
},
chunk
::
EcmascriptExports
,
chunk
::
EcmascriptExports
,
code_gen
::{
CodeGen
,
CodeGens
,
IntoCodeGenReference
},
code_gen
::{
CodeGen
,
CodeGens
,
IntoCodeGenReference
},
...
@@ -475,7 +476,7 @@ impl AnalysisState<'_> {
...
@@ -475,7 +476,7 @@ impl AnalysisState<'_> {
value
:
JsValue
,
value
:
JsValue
,
attributes
:
&
ImportAttributes
,
attributes
:
&
ImportAttributes
,
earliest_toplevel_visitor
:
&
impl
Fn
(
JsValue
)
->
JsValue
,
earliest_toplevel_visitor
:
&
impl
Fn
(
JsValue
)
->
JsValue
,
)
->
Result
<
JsValue
>
{
)
->
Result
<
(
JsValue
,
u32
)
>
{
link
(
link
(
self
.var_graph
,
self
.var_graph
,
value
,
value
,
...
@@ -495,8 +496,7 @@ impl AnalysisState<'_> {
...
@@ -495,8 +496,7 @@ impl AnalysisState<'_> {
&
self
.fun_args_values
,
&
self
.fun_args_values
,
&
self
.var_cache
,
&
self
.var_cache
,
)
)
.await
?
.await
.
0
)
}
}
async
fn
link_truthy
(
&
self
,
value
:
JsValue
,
attributes
:
&
ImportAttributes
)
->
Result
<
JsValue
>
{
async
fn
link_truthy
(
&
self
,
value
:
JsValue
,
attributes
:
&
ImportAttributes
)
->
Result
<
JsValue
>
{
...
@@ -509,17 +509,30 @@ impl AnalysisState<'_> {
...
@@ -509,17 +509,30 @@ impl AnalysisState<'_> {
attributes
:
&
ImportAttributes
,
attributes
:
&
ImportAttributes
,
)
->
Result
<
Vec
<
WellKnownFunctionKind
>>
{
)
->
Result
<
Vec
<
WellKnownFunctionKind
>>
{
// We are only interested in well-known functions, the only JsValues that can evaluated to
// We are only interested in well-known functions, the only JsValues that can evaluated to
// that are WellKnownFunction-s, and Variables that point to them. Anything else can be
// that are WellKnownFunctions, FreeVars and Members, (and Variables) that point to them.
// short circuited.
// Everything else can be short circuited.
// let original = value.clone();
let
value
=
self
let
value
=
self
.unsafe_link_value_shallow
(
value
,
attributes
,
&
|
v
|
match
v
{
.unsafe_link_value_shallow
(
value
,
attributes
,
&
|
v
|
match
v
{
JsValue
::
Alternatives
{
..
}
|
JsValue
::
FreeVar
{
..
}
|
JsValue
::
Member
{
..
}
=>
{
JsValue
::
Alternatives
{
..
}
v
|
JsValue
::
WellKnownFunction
{
..
}
|
JsValue
::
FreeVar
{
..
}
=>
v
,
JsValue
::
Member
(
_
,
_
,
ref
prop
)
=>
{
// Filter out `potentially_hugely_complex_value.startsWith`
// This is unsafe because you could do `{foo: require}.foo("./file")` and this
// skipping would miss it.
if
let
Some
(
prop
)
=
prop
.as_str
()
&&
!
is_well_known_function_prop
(
prop
)
{
v
.into_unknown
(
false
,
"earliest visitor well known function"
)
}
else
{
v
}
}
}
_
=>
JsValue
::
unknown
(
v
,
false
,
"earliest visitor well known function"
),
_
=>
v
.into_unknown
(
false
,
"earliest visitor well known function"
),
})
})
.await
?
;
.await
?
;
Ok
(
match
value
{
Ok
(
match
value
.
0
{
JsValue
::
WellKnownFunction
(
kind
)
=>
vec!
[
kind
],
JsValue
::
WellKnownFunction
(
kind
)
=>
vec!
[
kind
],
JsValue
::
Alternatives
{
values
,
..
}
=>
values
JsValue
::
Alternatives
{
values
,
..
}
=>
values
.into_iter
()
.into_iter
()
...
@@ -528,7 +541,11 @@ impl AnalysisState<'_> {
...
@@ -528,7 +541,11 @@ impl AnalysisState<'_> {
_
=>
None
,
_
=>
None
,
})
})
.collect
(),
.collect
(),
_
=>
vec!
[],
JsValue
::
Unknown
{
..
}
=>
vec!
[],
_
=>
{
// println!(" {:04} {:?} {:?}", value.1, value.0, original);
vec!
[]
}
})
})
}
}
}
}
...
...
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