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
a86d64d1
Commit
a86d64d1
authored
Aug 16, 2025
by
Luke Sandberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize re-export bindings
Fix an expr
parent
ceff818b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
294 additions
and
71 deletions
+294
-71
dynamic_module.rs
crates/next-core/src/next_dynamic/dynamic_module.rs
+1
-0
runtime-utils.ts
...rbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
+67
-11
base.rs
...ck/crates/turbopack-ecmascript/src/references/esm/base.rs
+28
-5
export.rs
.../crates/turbopack-ecmascript/src/references/esm/export.rs
+87
-28
53446_snapshot_intermediate-tree-shake_rename-side-effect-free-facade_input_cbcbaae7._.js
...-shake_rename-side-effect-free-facade_input_cbcbaae7._.js
+3
-1
[turbopack]_runtime.js
...ntime/default_build_runtime/output/[turbopack]_runtime.js
+49
-8
[turbopack]_runtime.js.map
...e/default_build_runtime/output/[turbopack]_runtime.js.map
+5
-5
5c1d0_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js
...pshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js
+49
-8
780ce_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js.map
...t_runtime_default_dev_runtime_input_index_c0f7e0b0.js.map
+5
-5
No files found.
crates/next-core/src/next_dynamic/dynamic_module.rs
View file @
a86d64d1
...
@@ -105,6 +105,7 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
...
@@ -105,6 +105,7 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
.to_resolved
()
.to_resolved
()
.await
?
,
.await
?
,
);
);
let
mut
exports
=
BTreeMap
::
new
();
let
mut
exports
=
BTreeMap
::
new
();
let
default
=
rcstr!
(
"default"
);
let
default
=
rcstr!
(
"default"
);
exports
.insert
(
exports
.insert
(
...
...
turbopack/crates/turbopack-ecmascript-runtime/js/src/shared/runtime-utils.ts
View file @
a86d64d1
...
@@ -105,9 +105,12 @@ function createModuleObject(id: ModuleId): Module {
...
@@ -105,9 +105,12 @@ function createModuleObject(id: ModuleId): Module {
}
}
}
}
type
BindingTag
=
0
type
BindingTag
=
0
|
1
|
2
|
3
|
4
const
BindingTag_Value
=
0
as
BindingTag
const
BindingTag_Value
=
0
as
BindingTag
const
BindingTag_ReExport
=
1
as
BindingTag
const
BindingTag_RenamedReexport
=
2
as
BindingTag
const
BindingTag_Mutable_ReExport
=
3
as
BindingTag
const
BindingTag_Mutable_RenamedReexport
=
4
as
BindingTag
// an arbitrary sequence of bindings as
// an arbitrary sequence of bindings as
// - a prop name
// - a prop name
// - BindingTag_Value, a value to be bound directly, or
// - BindingTag_Value, a value to be bound directly, or
...
@@ -127,15 +130,49 @@ function esm(exports: Exports, bindings: EsmBindings) {
...
@@ -127,15 +130,49 @@ function esm(exports: Exports, bindings: EsmBindings) {
const
propName
=
bindings
[
i
++
]
as
string
const
propName
=
bindings
[
i
++
]
as
string
const
tagOrFunction
=
bindings
[
i
++
]
const
tagOrFunction
=
bindings
[
i
++
]
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
tagOrFunction
===
BindingTag_Value
)
{
let
descriptor
:
PropertyDescriptor
defineProp
(
exports
,
propName
,
{
switch
(
tagOrFunction
)
{
case
BindingTag_Value
:
descriptor
=
{
value
:
bindings
[
i
++
],
value
:
bindings
[
i
++
],
enumerable
:
true
,
enumerable
:
true
,
writable
:
false
,
writable
:
false
,
})
}
}
else
{
break
case
BindingTag_ReExport
:
case
BindingTag_Mutable_ReExport
:
{
const
namespace
=
bindings
[
i
++
]
as
Record
<
string
,
any
>
// Note: in the common case we can just copy the descriptor this removes some indirection when
// accesing reexports however the propery may not exist if there is a cycle between a CJS file
// and an ESM module, in that case we just bind a getter and optional setter.
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
propName
)
??
makeReexportDescriptor
(
namespace
,
propName
,
tagOrFunction
===
BindingTag_Mutable_ReExport
)
}
break
case
BindingTag_RenamedReexport
:
case
BindingTag_Mutable_RenamedReexport
:
{
const
sourceName
=
bindings
[
i
++
]
as
string
const
namespace
=
bindings
[
i
++
]
as
Record
<
string
,
any
>
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
sourceName
)
??
makeReexportDescriptor
(
namespace
,
sourceName
,
tagOrFunction
===
BindingTag_Mutable_RenamedReexport
)
}
break
default
:
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
)
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
)
}
}
defineProp
(
exports
,
propName
,
descriptor
)
}
else
{
}
else
{
const
getterFn
=
tagOrFunction
as
()
=>
unknown
const
getterFn
=
tagOrFunction
as
()
=>
unknown
if
(
typeof
bindings
[
i
]
===
'function'
)
{
if
(
typeof
bindings
[
i
]
===
'function'
)
{
...
@@ -156,6 +193,21 @@ function esm(exports: Exports, bindings: EsmBindings) {
...
@@ -156,6 +193,21 @@ function esm(exports: Exports, bindings: EsmBindings) {
Object
.
seal
(
exports
)
Object
.
seal
(
exports
)
}
}
function
makeReexportDescriptor
(
namespace
:
Record
<
string
,
any
>
,
propName
:
string
,
mutable
:
boolean
):
PropertyDescriptor
{
const
descriptor
:
PropertyDescriptor
=
{
enumerable
:
true
,
get
:
createGetter
(
namespace
,
propName
),
}
if
(
mutable
)
{
descriptor
.
set
=
createSetter
(
namespace
,
propName
)
}
return
descriptor
}
/**
/**
* Makes the module an ESM with exports
* Makes the module an ESM with exports
*/
*/
...
@@ -275,7 +327,11 @@ contextPrototype.n = exportNamespace
...
@@ -275,7 +327,11 @@ contextPrototype.n = exportNamespace
function
createGetter
(
obj
:
Record
<
string
|
symbol
,
any
>
,
key
:
string
|
symbol
)
{
function
createGetter
(
obj
:
Record
<
string
|
symbol
,
any
>
,
key
:
string
|
symbol
)
{
return
()
=>
obj
[
key
]
return
()
=>
obj
[
key
]
}
}
function
createSetter
(
obj
:
Record
<
string
|
symbol
,
any
>
,
key
:
string
|
symbol
)
{
return
(
v
)
=>
{
obj
[
key
]
=
v
}
}
/**
/**
* @returns prototype of the object
* @returns prototype of the object
*/
*/
...
...
turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs
View file @
a86d64d1
...
@@ -41,6 +41,7 @@ use crate::{
...
@@ -41,6 +41,7 @@ use crate::{
analyzer
::
imports
::
ImportAnnotations
,
analyzer
::
imports
::
ImportAnnotations
,
chunk
::{
EcmascriptChunkPlaceable
,
EcmascriptExports
},
chunk
::{
EcmascriptChunkPlaceable
,
EcmascriptExports
},
code_gen
::{
CodeGeneration
,
CodeGenerationHoistedStmt
},
code_gen
::{
CodeGeneration
,
CodeGenerationHoistedStmt
},
export
::
Liveness
,
magic_identifier
,
magic_identifier
,
references
::{
references
::{
esm
::
EsmExport
,
esm
::
EsmExport
,
...
@@ -62,7 +63,11 @@ pub enum ReferencedAsset {
...
@@ -62,7 +63,11 @@ pub enum ReferencedAsset {
#[derive(Debug)]
#[derive(Debug)]
pub
enum
ReferencedAssetIdent
{
pub
enum
ReferencedAssetIdent
{
/// The given export (or namespace) is a local binding in the current scope hoisting group.
/// The given export (or namespace) is a local binding in the current scope hoisting group.
LocalBinding
{
ident
:
RcStr
,
ctxt
:
SyntaxContext
},
LocalBinding
{
ident
:
RcStr
,
ctxt
:
SyntaxContext
,
liveness
:
Liveness
,
},
/// The given export (or namespace) should be imported and will be assigned to a new variable.
/// The given export (or namespace) should be imported and will be assigned to a new variable.
Module
{
Module
{
namespace_ident
:
String
,
namespace_ident
:
String
,
...
@@ -82,16 +87,33 @@ impl ReferencedAssetIdent {
...
@@ -82,16 +87,33 @@ impl ReferencedAssetIdent {
ReferencedAssetIdent
::
LocalBinding
{
..
}
=>
None
,
ReferencedAssetIdent
::
LocalBinding
{
..
}
=>
None
,
}
}
}
}
pub
fn
as_module_namespace_expr
(
&
self
,
span
:
Span
)
->
Option
<
Expr
>
{
match
self
{
ReferencedAssetIdent
::
Module
{
namespace_ident
,
ctxt
,
..
}
=>
Some
(
Expr
::
Ident
(
Ident
::
new
(
namespace_ident
.as_str
()
.into
(),
span
,
ctxt
.unwrap_or_default
(),
))),
ReferencedAssetIdent
::
LocalBinding
{
..
}
=>
None
,
}
}
pub
fn
as_expr_individual
(
&
self
,
span
:
Span
)
->
Either
<
Ident
,
MemberExpr
>
{
pub
fn
as_expr_individual
(
&
self
,
span
:
Span
)
->
Either
<
Ident
,
MemberExpr
>
{
match
self
{
match
self
{
ReferencedAssetIdent
::
LocalBinding
{
ident
,
ctxt
}
=>
{
ReferencedAssetIdent
::
LocalBinding
{
Either
::
Left
(
Ident
::
new
(
ident
.as_str
()
.into
(),
span
,
*
ctxt
))
ident
,
}
ctxt
,
liveness
:
_
,
}
=>
Either
::
Left
(
Ident
::
new
(
ident
.as_str
()
.into
(),
span
,
*
ctxt
)),
ReferencedAssetIdent
::
Module
{
ReferencedAssetIdent
::
Module
{
namespace_ident
,
namespace_ident
,
ctxt
,
ctxt
,
export
,
export
,
..
}
=>
{
}
=>
{
if
let
Some
(
export
)
=
export
{
if
let
Some
(
export
)
=
export
{
Either
::
Right
(
MemberExpr
{
Either
::
Right
(
MemberExpr
{
...
@@ -172,13 +194,14 @@ impl ReferencedAsset {
...
@@ -172,13 +194,14 @@ impl ReferencedAsset {
let
exports
=
exports
.expand_exports
(
ModuleExportUsageInfo
::
all
())
.await
?
;
let
exports
=
exports
.expand_exports
(
ModuleExportUsageInfo
::
all
())
.await
?
;
let
esm_export
=
exports
.exports
.get
(
export
);
let
esm_export
=
exports
.exports
.get
(
export
);
match
esm_export
{
match
esm_export
{
Some
(
EsmExport
::
LocalBinding
(
_
,
_
))
=>
{
Some
(
EsmExport
::
LocalBinding
(
_
,
liveness
))
=>
{
// A local binding in a module that is merged in the same group. Use the
// A local binding in a module that is merged in the same group. Use the
// export name as identifier, it will be replaced with the actual
// export name as identifier, it will be replaced with the actual
// variable name during AST merging.
// variable name during AST merging.
return
Ok
(
Some
(
ReferencedAssetIdent
::
LocalBinding
{
return
Ok
(
Some
(
ReferencedAssetIdent
::
LocalBinding
{
ident
:
export
.clone
(),
ident
:
export
.clone
(),
ctxt
,
ctxt
,
liveness
:
*
liveness
,
}));
}));
}
}
Some
(
b
@
EsmExport
::
ImportedBinding
(
esm_ref
,
_
,
_
))
Some
(
b
@
EsmExport
::
ImportedBinding
(
esm_ref
,
_
,
_
))
...
...
turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs
View file @
a86d64d1
...
@@ -649,6 +649,8 @@ impl EsmExports {
...
@@ -649,6 +649,8 @@ impl EsmExports {
Getter
(
Expr
),
Getter
(
Expr
),
GetterSetter
(
Expr
,
Expr
),
GetterSetter
(
Expr
,
Expr
),
Value
(
Expr
),
Value
(
Expr
),
// The namespace expression and the export name
ReExport
(
Expr
,
bool
,
RcStr
),
None
,
None
,
}
}
...
@@ -686,9 +688,7 @@ impl EsmExports {
...
@@ -686,9 +688,7 @@ impl EsmExports {
let
local
=
Ident
::
new
(
local
.into
(),
DUMMY_SP
,
ctxt
);
let
local
=
Ident
::
new
(
local
.into
(),
DUMMY_SP
,
ctxt
);
match
(
liveness
,
export_usage_info
.is_circuit_breaker
)
{
match
(
liveness
,
export_usage_info
.is_circuit_breaker
)
{
(
Liveness
::
Constant
,
false
)
=>
{
(
Liveness
::
Constant
,
false
)
=>
ExportBinding
::
Value
(
Expr
::
Ident
(
local
)),
ExportBinding
::
Value
(
quote!
(
"$local"
as
Expr
,
local
=
local
))
}
// If the value might change or we are a circuit breaker we must bind a
// If the value might change or we are a circuit breaker we must bind a
// getter to avoid capturing the value at the wrong time.
// getter to avoid capturing the value at the wrong time.
(
Liveness
::
Live
,
_
)
|
(
Liveness
::
Constant
,
true
)
=>
{
(
Liveness
::
Live
,
_
)
|
(
Liveness
::
Constant
,
true
)
=>
{
...
@@ -713,9 +713,36 @@ impl EsmExports {
...
@@ -713,9 +713,36 @@ impl EsmExports {
.map
(|
ident
|
{
.map
(|
ident
|
{
let
expr
=
ident
.as_expr_individual
(
DUMMY_SP
);
let
expr
=
ident
.as_expr_individual
(
DUMMY_SP
);
let
read_expr
=
expr
.map_either
(
Expr
::
from
,
Expr
::
from
)
.into_inner
();
let
read_expr
=
expr
.map_either
(
Expr
::
from
,
Expr
::
from
)
.into_inner
();
// For imported bindings we could simply export the 'import' and have the runtime hook the bindings together.
use
crate
::
references
::
esm
::
base
::
ReferencedAssetIdent
;
// This would be cute, slightly smaller codegen but efficiency is an open question. In fact we could even
match
&
ident
{
// perform the 'liveness' check at runtime by querying the property descriptor.
ReferencedAssetIdent
::
LocalBinding
{
ctxt
,
liveness
,
..
}
=>
{
debug_assert!
(
*
mutable
==
(
*
liveness
==
Liveness
::
Mutable
),
"If the re-export is mutable, the merged local must be too"
);
// If we are re-exporting something but got merged with it we can treat it like a local export
match
(
liveness
,
export_usage_info
.is_circuit_breaker
)
{
(
Liveness
::
Constant
,
false
)
=>
{
ExportBinding
::
Value
(
read_expr
)
}
// If the value might change or we are a circuit breaker we must bind a
// getter to avoid capturing the value at the wrong time.
(
Liveness
::
Live
,
_
)
|
(
Liveness
::
Constant
,
true
)
=>
{
ExportBinding
::
Getter
(
quote!
(
"() => $local"
as
Expr
,
local
:
Expr
=
read_expr
))
}
(
Liveness
::
Mutable
,
_
)
=>
ExportBinding
::
GetterSetter
(
quote!
(
"() => $local"
as
Expr
,
local
:
Expr
=
read_expr
.clone
()),
quote!
(
"($new) => $lhs = $new"
as
Expr
,
lhs
:
AssignTarget
=
AssignTarget
::
Simple
(
ident
.as_expr_individual
(
DUMMY_SP
)
.map_either
(|
i
|
SimpleAssignTarget
::
Ident
(
i
.into
()),
SimpleAssignTarget
::
Member
)
.into_inner
()),
new
=
Ident
::
new
(
format!
(
"new_{name}"
)
.into
(),
DUMMY_SP
,
*
ctxt
),
),
),
}
},
ReferencedAssetIdent
::
Module
{
namespace_ident
:
_
,
ctxt
:
_
,
export
}
=>
{
if
export_usage_info
.is_circuit_breaker
{
// Instead of a function we could pass a module-id up and have the runtime bind a getter that retrieves it from the modulecache
let
getter
=
quote!
(
let
getter
=
quote!
(
"() => $expr"
as
Expr
,
"() => $expr"
as
Expr
,
expr
:
Expr
=
read_expr
,
expr
:
Expr
=
read_expr
,
...
@@ -732,12 +759,21 @@ impl EsmExports {
...
@@ -732,12 +759,21 @@ impl EsmExports {
DUMMY_SP
,
DUMMY_SP
,
Default
::
default
()
Default
::
default
()
),
),
)
))
)
}
else
{
}
else
{
ExportBinding
::
Getter
(
getter
)
ExportBinding
::
Getter
(
getter
)
}
}
})
.unwrap_or
(
ExportBinding
::
None
)
}
else
{
let
namespace_expr
=
ident
.as_module_namespace_expr
(
DUMMY_SP
)
.unwrap
();
if
let
Some
(
export
)
=
export
{
ExportBinding
::
ReExport
(
namespace_expr
,
*
mutable
,
export
.clone
())
}
else
{
ExportBinding
::
Value
(
namespace_expr
)
}
}
}
}})
.unwrap_or
(
ExportBinding
::
None
)
}
}
EsmExport
::
ImportedNamespace
(
esm_ref
)
=>
{
EsmExport
::
ImportedNamespace
(
esm_ref
)
=>
{
let
referenced_asset
=
let
referenced_asset
=
...
@@ -748,6 +784,10 @@ impl EsmExports {
...
@@ -748,6 +784,10 @@ impl EsmExports {
.map
(|
ident
|
{
.map
(|
ident
|
{
let
imported
=
ident
.as_expr
(
DUMMY_SP
,
false
);
let
imported
=
ident
.as_expr
(
DUMMY_SP
,
false
);
if
export_usage_info
.is_circuit_breaker
{
if
export_usage_info
.is_circuit_breaker
{
// In theory we could just pass the target module id up and the
// runtime could do the import when binding the export.
// This would almost work but could change evaluation order unless
// we create some way to look-up a module without loading it.
ExportBinding
::
Getter
(
quote!
(
ExportBinding
::
Getter
(
quote!
(
"(() => $imported)"
as
Expr
,
"(() => $imported)"
as
Expr
,
imported
:
Expr
=
imported
imported
:
Expr
=
imported
...
@@ -783,6 +823,25 @@ impl EsmExports {
...
@@ -783,6 +823,25 @@ impl EsmExports {
getters
.push
(
Some
(
value
.into
()));
getters
.push
(
Some
(
value
.into
()));
}
}
ExportBinding
::
None
=>
{}
ExportBinding
::
None
=>
{}
ExportBinding
::
ReExport
(
namespace
,
mutable
,
export
)
=>
{
let
offset
=
if
mutable
{
2
}
else
{
0
};
if
&
export
==
exported
{
getters
.push
(
Some
(
Expr
::
Lit
(
Lit
::
Num
(
Number
::
from
(
1
+
offset
)))
.into
()));
}
else
{
getters
.push
(
Some
(
Expr
::
Lit
(
Lit
::
Num
(
Number
::
from
(
2
+
offset
)))
.into
()));
getters
.push
(
Some
(
Expr
::
Lit
(
Lit
::
Str
(
Str
{
span
:
DUMMY_SP
,
value
:
export
.as_str
()
.into
(),
raw
:
None
,
}))
.into
(),
))
}
getters
.push
(
Some
(
namespace
.into
()));
}
};
};
}
}
}
}
...
...
turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/rename-side-effect-free-facade/output/53446_snapshot_intermediate-tree-shake_rename-side-effect-free-facade_input_cbcbaae7._.js
View file @
a86d64d1
...
@@ -24,7 +24,9 @@ __turbopack_context__.s([
...
@@ -24,7 +24,9 @@ __turbopack_context__.s([
var
__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$rename$2d$side$2d$effect$2d$free$2d$facade$2f$input$2f$node_modules$2f$lib$2f$a$2e$js__$5b$test$5d$__$28$ecmascript$29$__
=
__turbopack_context__
.
i
(
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/rename-side-effect-free-facade/input/node_modules/lib/a.js [test] (ecmascript)"
);
var
__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$rename$2d$side$2d$effect$2d$free$2d$facade$2f$input$2f$node_modules$2f$lib$2f$a$2e$js__$5b$test$5d$__$28$ecmascript$29$__
=
__turbopack_context__
.
i
(
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/intermediate-tree-shake/rename-side-effect-free-facade/input/node_modules/lib/a.js [test] (ecmascript)"
);
__turbopack_context__
.
s
([
__turbopack_context__
.
s
([
"a0"
,
"a0"
,
()
=>
__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$rename$2d$side$2d$effect$2d$free$2d$facade$2f$input$2f$node_modules$2f$lib$2f$a$2e$js__$5b$test$5d$__$28$ecmascript$29$__
[
"a"
]
2
,
"a"
,
__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$intermediate$2d$tree$2d$shake$2f$rename$2d$side$2d$effect$2d$free$2d$facade$2f$input$2f$node_modules$2f$lib$2f$a$2e$js__$5b$test$5d$__$28$ecmascript$29$__
]);
]);
}),
}),
]);
]);
...
...
turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js
View file @
a86d64d1
...
@@ -48,6 +48,10 @@ function getOverwrittenModule(moduleCache, id) {
...
@@ -48,6 +48,10 @@ function getOverwrittenModule(moduleCache, id) {
};
};
}
}
const
BindingTag_Value
=
0
;
const
BindingTag_Value
=
0
;
const
BindingTag_ReExport
=
1
;
const
BindingTag_RenamedReexport
=
2
;
const
BindingTag_Mutable_ReExport
=
3
;
const
BindingTag_Mutable_RenamedReexport
=
4
;
/**
/**
* Adds the getters to the exports object.
* Adds the getters to the exports object.
*/
function
esm
(
exports
,
bindings
)
{
*/
function
esm
(
exports
,
bindings
)
{
...
@@ -62,15 +66,37 @@ const BindingTag_Value = 0;
...
@@ -62,15 +66,37 @@ const BindingTag_Value = 0;
const
propName
=
bindings
[
i
++
];
const
propName
=
bindings
[
i
++
];
const
tagOrFunction
=
bindings
[
i
++
];
const
tagOrFunction
=
bindings
[
i
++
];
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
tagOrFunction
===
BindingTag_Value
)
{
let
descriptor
;
defineProp
(
exports
,
propName
,
{
switch
(
tagOrFunction
){
case
BindingTag_Value
:
descriptor
=
{
value
:
bindings
[
i
++
],
value
:
bindings
[
i
++
],
enumerable
:
true
,
enumerable
:
true
,
writable
:
false
writable
:
false
});
};
}
else
{
break
;
case
BindingTag_ReExport
:
case
BindingTag_Mutable_ReExport
:
{
const
namespace
=
bindings
[
i
++
];
// Note: in the common case we can just copy the descriptor this removes some indirection when
// accesing reexports however the propery may not exist if there is a cycle between a CJS file
// and an ESM module, in that case we just bind a getter and optional setter.
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
propName
)
??
makeReexportDescriptor
(
namespace
,
propName
,
tagOrFunction
===
BindingTag_Mutable_ReExport
);
}
break
;
case
BindingTag_RenamedReexport
:
case
BindingTag_Mutable_RenamedReexport
:
{
const
sourceName
=
bindings
[
i
++
];
const
namespace
=
bindings
[
i
++
];
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
sourceName
)
??
makeReexportDescriptor
(
namespace
,
sourceName
,
tagOrFunction
===
BindingTag_Mutable_RenamedReexport
);
}
break
;
default
:
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
);
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
);
}
}
defineProp
(
exports
,
propName
,
descriptor
);
}
else
{
}
else
{
const
getterFn
=
tagOrFunction
;
const
getterFn
=
tagOrFunction
;
if
(
typeof
bindings
[
i
]
===
'function'
)
{
if
(
typeof
bindings
[
i
]
===
'function'
)
{
...
@@ -90,6 +116,16 @@ const BindingTag_Value = 0;
...
@@ -90,6 +116,16 @@ const BindingTag_Value = 0;
}
}
Object
.
seal
(
exports
);
Object
.
seal
(
exports
);
}
}
function
makeReexportDescriptor
(
namespace
,
propName
,
mutable
)
{
const
descriptor
=
{
enumerable
:
true
,
get
:
createGetter
(
namespace
,
propName
)
};
if
(
mutable
)
{
descriptor
.
set
=
createSetter
(
namespace
,
propName
);
}
return
descriptor
;
}
/**
/**
* Makes the module an ESM with exports
* Makes the module an ESM with exports
*/
function
esmExport
(
bindings
,
id
)
{
*/
function
esmExport
(
bindings
,
id
)
{
...
@@ -175,6 +211,11 @@ contextPrototype.n = exportNamespace;
...
@@ -175,6 +211,11 @@ contextPrototype.n = exportNamespace;
function
createGetter
(
obj
,
key
)
{
function
createGetter
(
obj
,
key
)
{
return
()
=>
obj
[
key
];
return
()
=>
obj
[
key
];
}
}
function
createSetter
(
obj
,
key
)
{
return
(
v
)
=>
{
obj
[
key
]
=
v
;
};
}
/**
/**
* @returns prototype of the object
* @returns prototype of the object
*/
const
getProto
=
Object
.
getPrototypeOf
?
(
obj
)
=>
Object
.
getPrototypeOf
(
obj
)
:
(
obj
)
=>
obj
.
__proto__
;
*/
const
getProto
=
Object
.
getPrototypeOf
?
(
obj
)
=>
Object
.
getPrototypeOf
(
obj
)
:
(
obj
)
=>
obj
.
__proto__
;
...
...
turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_build_runtime/output/[turbopack]_runtime.js.map
View file @
a86d64d1
This diff is collapsed.
Click to expand it.
turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_dev_runtime/output/5c1d0_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js
View file @
a86d64d1
...
@@ -58,6 +58,10 @@ function getOverwrittenModule(moduleCache, id) {
...
@@ -58,6 +58,10 @@ function getOverwrittenModule(moduleCache, id) {
};
};
}
}
const
BindingTag_Value
=
0
;
const
BindingTag_Value
=
0
;
const
BindingTag_ReExport
=
1
;
const
BindingTag_RenamedReexport
=
2
;
const
BindingTag_Mutable_ReExport
=
3
;
const
BindingTag_Mutable_RenamedReexport
=
4
;
/**
/**
* Adds the getters to the exports object.
* Adds the getters to the exports object.
*/
function
esm
(
exports
,
bindings
)
{
*/
function
esm
(
exports
,
bindings
)
{
...
@@ -72,15 +76,37 @@ const BindingTag_Value = 0;
...
@@ -72,15 +76,37 @@ const BindingTag_Value = 0;
const
propName
=
bindings
[
i
++
];
const
propName
=
bindings
[
i
++
];
const
tagOrFunction
=
bindings
[
i
++
];
const
tagOrFunction
=
bindings
[
i
++
];
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
typeof
tagOrFunction
===
'number'
)
{
if
(
tagOrFunction
===
BindingTag_Value
)
{
let
descriptor
;
defineProp
(
exports
,
propName
,
{
switch
(
tagOrFunction
){
case
BindingTag_Value
:
descriptor
=
{
value
:
bindings
[
i
++
],
value
:
bindings
[
i
++
],
enumerable
:
true
,
enumerable
:
true
,
writable
:
false
writable
:
false
});
};
}
else
{
break
;
case
BindingTag_ReExport
:
case
BindingTag_Mutable_ReExport
:
{
const
namespace
=
bindings
[
i
++
];
// Note: in the common case we can just copy the descriptor this removes some indirection when
// accesing reexports however the propery may not exist if there is a cycle between a CJS file
// and an ESM module, in that case we just bind a getter and optional setter.
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
propName
)
??
makeReexportDescriptor
(
namespace
,
propName
,
tagOrFunction
===
BindingTag_Mutable_ReExport
);
}
break
;
case
BindingTag_RenamedReexport
:
case
BindingTag_Mutable_RenamedReexport
:
{
const
sourceName
=
bindings
[
i
++
];
const
namespace
=
bindings
[
i
++
];
descriptor
=
Object
.
getOwnPropertyDescriptor
(
namespace
,
sourceName
)
??
makeReexportDescriptor
(
namespace
,
sourceName
,
tagOrFunction
===
BindingTag_Mutable_RenamedReexport
);
}
break
;
default
:
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
);
throw
new
Error
(
`unexpected tag:
${
tagOrFunction
}
`
);
}
}
defineProp
(
exports
,
propName
,
descriptor
);
}
else
{
}
else
{
const
getterFn
=
tagOrFunction
;
const
getterFn
=
tagOrFunction
;
if
(
typeof
bindings
[
i
]
===
'function'
)
{
if
(
typeof
bindings
[
i
]
===
'function'
)
{
...
@@ -100,6 +126,16 @@ const BindingTag_Value = 0;
...
@@ -100,6 +126,16 @@ const BindingTag_Value = 0;
}
}
Object
.
seal
(
exports
);
Object
.
seal
(
exports
);
}
}
function
makeReexportDescriptor
(
namespace
,
propName
,
mutable
)
{
const
descriptor
=
{
enumerable
:
true
,
get
:
createGetter
(
namespace
,
propName
)
};
if
(
mutable
)
{
descriptor
.
set
=
createSetter
(
namespace
,
propName
);
}
return
descriptor
;
}
/**
/**
* Makes the module an ESM with exports
* Makes the module an ESM with exports
*/
function
esmExport
(
bindings
,
id
)
{
*/
function
esmExport
(
bindings
,
id
)
{
...
@@ -185,6 +221,11 @@ contextPrototype.n = exportNamespace;
...
@@ -185,6 +221,11 @@ contextPrototype.n = exportNamespace;
function
createGetter
(
obj
,
key
)
{
function
createGetter
(
obj
,
key
)
{
return
()
=>
obj
[
key
];
return
()
=>
obj
[
key
];
}
}
function
createSetter
(
obj
,
key
)
{
return
(
v
)
=>
{
obj
[
key
]
=
v
;
};
}
/**
/**
* @returns prototype of the object
* @returns prototype of the object
*/
const
getProto
=
Object
.
getPrototypeOf
?
(
obj
)
=>
Object
.
getPrototypeOf
(
obj
)
:
(
obj
)
=>
obj
.
__proto__
;
*/
const
getProto
=
Object
.
getPrototypeOf
?
(
obj
)
=>
Object
.
getPrototypeOf
(
obj
)
:
(
obj
)
=>
obj
.
__proto__
;
...
...
turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_dev_runtime/output/780ce_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js.map
View file @
a86d64d1
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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