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
1d0ed883
Unverified
Commit
1d0ed883
authored
Oct 26, 2026
by
vercel-fleet-prod[bot]
Committed by
GitHub
Oct 26, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Turbopack constant export inlining
Co-authored-by:
Tobias Koppers
<
1365881+sokra@users.noreply.github.com
>
parent
c8e811ee
Hide whitespace changes
Inline
Side-by-side
Showing
54 changed files
with
535 additions
and
37 deletions
+535
-37
context.rs
crates/next-core/src/next_client/context.rs
+1
-0
next_config.rs
crates/next-core/src/next_config.rs
+12
-1
context.rs
crates/next-core/src/next_server/context.rs
+1
-0
config-schema.ts
packages/next/src/server/config-schema.ts
+1
-0
config-shared.ts
packages/next/src/server/config-shared.ts
+8
-0
lib.rs
turbopack/crates/turbopack-ecmascript/src/lib.rs
+5
-1
cross_module_constants.rs
...opack-ecmascript/src/references/cross_module_constants.rs
+110
-33
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+33
-1
execution.rs
turbopack/crates/turbopack-tests/tests/execution.rs
+4
-0
a.js
...pack/optimization/codegen-inline-exports-cycle/input/a.js
+6
-0
b.js
...pack/optimization/codegen-inline-exports-cycle/input/b.js
+5
-0
index.js
.../optimization/codegen-inline-exports-cycle/input/index.js
+14
-0
options.json
...ck/optimization/codegen-inline-exports-cycle/options.json
+6
-0
index.js
...timization/codegen-inline-exports-disabled/input/index.js
+15
-0
index.js
...s-disabled/input/node_modules/disabled-constants/index.js
+1
-0
package.json
...sabled/input/node_modules/disabled-constants/package.json
+3
-0
options.json
...optimization/codegen-inline-exports-disabled/options.json
+6
-0
analysis-marker.js
...egen-inline-exports-interactions/input/analysis-marker.js
+1
-0
annotation-off-marker.js
...nline-exports-interactions/input/annotation-off-marker.js
+1
-0
forced-marker.js
...odegen-inline-exports-interactions/input/forced-marker.js
+1
-0
index.js
...zation/codegen-inline-exports-interactions/input/index.js
+43
-0
late-marker.js
.../codegen-inline-exports-interactions/input/late-marker.js
+1
-0
index.js
...ts-interactions/input/node_modules/inline-values/index.js
+4
-0
package.json
...nteractions/input/node_modules/inline-values/package.json
+3
-0
options.json
...mization/codegen-inline-exports-interactions/options.json
+6
-0
a.js
...ack/optimization/codegen-inline-exports-mutual/input/a.js
+7
-0
b.js
...ack/optimization/codegen-inline-exports-mutual/input/b.js
+7
-0
index.js
...optimization/codegen-inline-exports-mutual/input/index.js
+18
-0
options.json
...k/optimization/codegen-inline-exports-mutual/options.json
+6
-0
index.js
...bopack/optimization/codegen-inline-exports/input/index.js
+139
-0
marker.js
...opack/optimization/codegen-inline-exports/input/marker.js
+1
-0
index.js
...ine-exports/input/node_modules/analysis-constant/index.js
+1
-0
package.json
...exports/input/node_modules/analysis-constant/package.json
+3
-0
index.js
...nline-exports/input/node_modules/effect-constant/index.js
+2
-0
package.json
...e-exports/input/node_modules/effect-constant/package.json
+3
-0
index.js
...nline-exports/input/node_modules/identity-values/index.js
+1
-0
package.json
...e-exports/input/node_modules/identity-values/package.json
+3
-0
index.js
...n-inline-exports/input/node_modules/long-default/index.js
+1
-0
package.json
...line-exports/input/node_modules/long-default/package.json
+3
-0
index.js
...en-inline-exports/input/node_modules/long-values/index.js
+4
-0
package.json
...nline-exports/input/node_modules/long-values/package.json
+3
-0
index.js
...line-exports/input/node_modules/namespace-escape/index.js
+1
-0
package.json
...-exports/input/node_modules/namespace-escape/package.json
+3
-0
index.js
...line-exports/input/node_modules/namespace-static/index.js
+1
-0
package.json
...-exports/input/node_modules/namespace-static/package.json
+3
-0
index.js
...ne-exports/input/node_modules/reassigned-binding/index.js
+2
-0
package.json
...xports/input/node_modules/reassigned-binding/package.json
+3
-0
index.js
...nline-exports/input/node_modules/short-constants/index.js
+8
-0
package.json
...e-exports/input/node_modules/short-constants/package.json
+3
-0
index.js
...-inline-exports/input/node_modules/short-default/index.js
+1
-0
package.json
...ine-exports/input/node_modules/short-default/package.json
+3
-0
options.json
...urbopack/optimization/codegen-inline-exports/options.json
+6
-0
mod.rs
turbopack/crates/turbopack/src/module_options/mod.rs
+2
-0
module_options_context.rs
...es/turbopack/src/module_options/module_options_context.rs
+6
-1
No files found.
crates/next-core/src/next_client/context.rs
View file @
1d0ed883
...
@@ -379,6 +379,7 @@ pub async fn get_client_module_options_context(
...
@@ -379,6 +379,7 @@ pub async fn get_client_module_options_context(
.await
?
,
.await
?
,
cjs_scope_hoisting
:
*
next_config
.turbopack_cjs_scope_hoisting
()
.await
?
,
cjs_scope_hoisting
:
*
next_config
.turbopack_cjs_scope_hoisting
()
.await
?
,
cross_module_constants
:
*
next_config
.turbopack_cross_module_constants
()
.await
?
,
cross_module_constants
:
*
next_config
.turbopack_cross_module_constants
()
.await
?
,
inline_constant_exports
:
*
next_config
.turbopack_inline_constant_exports
()
.await
?
,
lazy_compilation
:
*
next_config
lazy_compilation
:
*
next_config
.turbopack_lazy_dynamic_imports
(
*
next_mode
)
.turbopack_lazy_dynamic_imports
(
*
next_mode
)
.await
?
,
.await
?
,
...
...
crates/next-core/src/next_config.rs
View file @
1d0ed883
...
@@ -1243,8 +1243,10 @@ pub struct ExperimentalConfig {
...
@@ -1243,8 +1243,10 @@ pub struct ExperimentalConfig {
turbopack_mangle_via_materialized_namespace_object
:
Option
<
bool
>
,
turbopack_mangle_via_materialized_namespace_object
:
Option
<
bool
>
,
/// Enable scope hoisting of static CommonJS modules. Defaults to false.
/// Enable scope hoisting of static CommonJS modules. Defaults to false.
turbopack_cjs_scope_hoisting
:
Option
<
bool
>
,
turbopack_cjs_scope_hoisting
:
Option
<
bool
>
,
/// Enable cross-module constant inlining. Defaults to false.
/// Enable
analyzer-aware
cross-module constant inlining. Defaults to false.
turbopack_cross_module_constants
:
Option
<
bool
>
,
turbopack_cross_module_constants
:
Option
<
bool
>
,
/// Inline short constant exports during code generation. Defaults to false.
turbopack_inline_constant_exports
:
Option
<
bool
>
,
/// Devtool option for the segment explorer.
/// Devtool option for the segment explorer.
devtool_segment_explorer
:
Option
<
bool
>
,
devtool_segment_explorer
:
Option
<
bool
>
,
/// Whether to report inlined system environment variables as warnings or errors.
/// Whether to report inlined system environment variables as warnings or errors.
...
@@ -2403,6 +2405,15 @@ impl NextConfig {
...
@@ -2403,6 +2405,15 @@ impl NextConfig {
)
)
}
}
#[turbo_tasks
::
function]
pub
fn
turbopack_inline_constant_exports
(
&
self
)
->
Vc
<
bool
>
{
Vc
::
cell
(
self
.experimental
.turbopack_inline_constant_exports
.unwrap_or
(
false
),
)
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
fn
turbopack_plugin_runtime_strategy
(
&
self
)
->
Vc
<
TurbopackPluginRuntimeStrategy
>
{
pub
fn
turbopack_plugin_runtime_strategy
(
&
self
)
->
Vc
<
TurbopackPluginRuntimeStrategy
>
{
// Child processes cannot be spawned from inside wasm, so worker threads are the only
// Child processes cannot be spawned from inside wasm, so worker threads are the only
...
...
crates/next-core/src/next_server/context.rs
View file @
1d0ed883
...
@@ -552,6 +552,7 @@ pub async fn get_server_module_options_context(
...
@@ -552,6 +552,7 @@ pub async fn get_server_module_options_context(
.await
?
,
.await
?
,
cjs_scope_hoisting
:
*
next_config
.turbopack_cjs_scope_hoisting
()
.await
?
,
cjs_scope_hoisting
:
*
next_config
.turbopack_cjs_scope_hoisting
()
.await
?
,
cross_module_constants
:
*
next_config
.turbopack_cross_module_constants
()
.await
?
,
cross_module_constants
:
*
next_config
.turbopack_cross_module_constants
()
.await
?
,
inline_constant_exports
:
*
next_config
.turbopack_inline_constant_exports
()
.await
?
,
..
Default
::
default
()
..
Default
::
default
()
},
},
execution_context
:
Some
(
execution_context
),
execution_context
:
Some
(
execution_context
),
...
...
packages/next/src/server/config-schema.ts
View file @
1d0ed883
...
@@ -461,6 +461,7 @@ export const experimentalSchema = {
...
@@ -461,6 +461,7 @@ export const experimentalSchema = {
turbopackMangleViaMaterializedNamespaceObject
:
z
.
boolean
().
optional
(),
turbopackMangleViaMaterializedNamespaceObject
:
z
.
boolean
().
optional
(),
turbopackCjsScopeHoisting
:
z
.
boolean
().
optional
(),
turbopackCjsScopeHoisting
:
z
.
boolean
().
optional
(),
turbopackCrossModuleConstants
:
z
.
boolean
().
optional
(),
turbopackCrossModuleConstants
:
z
.
boolean
().
optional
(),
turbopackInlineConstantExports
:
z
.
boolean
().
optional
(),
turbopackServerFastRefresh
:
z
.
boolean
().
optional
(),
turbopackServerFastRefresh
:
z
.
boolean
().
optional
(),
optimizePackageImports
:
z
.
array
(
z
.
string
()).
optional
(),
optimizePackageImports
:
z
.
array
(
z
.
string
()).
optional
(),
optimizeServerReact
:
z
.
boolean
().
optional
(),
optimizeServerReact
:
z
.
boolean
().
optional
(),
...
...
packages/next/src/server/config-shared.ts
View file @
1d0ed883
...
@@ -1127,6 +1127,14 @@ export interface ExperimentalConfig {
...
@@ -1127,6 +1127,14 @@ export interface ExperimentalConfig {
*/
*/
turbopackCrossModuleConstants
?:
boolean
turbopackCrossModuleConstants
?:
boolean
/**
* Inline short, identity-free constant exports during Turbopack code generation without using
* their values for compile-time analysis.
*
* Defaults to `false`
*/
turbopackInlineConstantExports
?:
boolean
/**
/**
* Set this to `false` to disable the automatic configuration of the babel loader when a Babel
* Set this to `false` to disable the automatic configuration of the babel loader when a Babel
* configuration file is present. This option is enabled by default.
* configuration file is present. This option is enabled by default.
...
...
turbopack/crates/turbopack-ecmascript/src/lib.rs
View file @
1d0ed883
...
@@ -257,8 +257,12 @@ pub struct EcmascriptOptions {
...
@@ -257,8 +257,12 @@ pub struct EcmascriptOptions {
pub
mangle_via_materialized_namespace_object
:
bool
,
pub
mangle_via_materialized_namespace_object
:
bool
,
/// Whether to scope hoist static CommonJS modules. Defaults to false.
/// Whether to scope hoist static CommonJS modules. Defaults to false.
pub
cjs_scope_hoisting
:
bool
,
pub
cjs_scope_hoisting
:
bool
,
/// Whether to enable cross-module constant inlining. Defaults to false.
/// Whether to use cross-module constants during analysis and code generation. Defaults to
/// false.
pub
cross_module_constants
:
bool
,
pub
cross_module_constants
:
bool
,
/// Whether to inline short, identity-free constant exports only during code generation.
/// Defaults to false.
pub
inline_constant_exports
:
bool
,
/// Whether dynamic import targets are compiled after their runtime proxy is activated.
/// Whether dynamic import targets are compiled after their runtime proxy is activated.
pub
lazy_compilation
:
bool
,
pub
lazy_compilation
:
bool
,
}
}
...
...
turbopack/crates/turbopack-ecmascript/src/references/cross_module_constants.rs
View file @
1d0ed883
...
@@ -6,14 +6,17 @@ use bincode::{Decode, Encode};
...
@@ -6,14 +6,17 @@ use bincode::{Decode, Encode};
use
num_bigint
::
BigInt
;
use
num_bigint
::
BigInt
;
use
parking_lot
::
Mutex
;
use
parking_lot
::
Mutex
;
use
rustc_hash
::
FxHashMap
;
use
rustc_hash
::
FxHashMap
;
use
swc_core
::
common
::{
GLOBALS
,
source_map
::
SmallPos
};
use
swc_core
::{
common
::{
GLOBALS
,
source_map
::
SmallPos
},
ecma
::
ast
::{
ModuleDecl
,
ModuleItem
,
Program
},
};
use
thread_local
::
ThreadLocal
;
use
thread_local
::
ThreadLocal
;
use
tracing
::
instrument
;
use
tracing
::
instrument
;
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
NonLocalValue
,
ResolvedVc
,
TryJoinIterExt
,
Vc
};
use
turbo_tasks
::{
NonLocalValue
,
ResolvedVc
,
TryJoinIterExt
,
Vc
};
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbopack_core
::{
use
turbopack_core
::{
compile_time_info
::
CompileTimeInfo
,
compile_time_info
::
{
CompileTimeDefineValue
,
CompileTimeInfo
}
,
issue
::{
Issue
,
IssueExt
,
IssueSeverity
,
IssueSource
,
IssueStage
,
StyledString
},
issue
::{
Issue
,
IssueExt
,
IssueSeverity
,
IssueSource
,
IssueStage
,
StyledString
},
module
::
Module
,
module
::
Module
,
reference
::
ModuleReference
,
reference
::
ModuleReference
,
...
@@ -35,6 +38,38 @@ const STRING_INLINE_THRESHOLD: usize = 6;
...
@@ -35,6 +38,38 @@ const STRING_INLINE_THRESHOLD: usize = 6;
const
NUMBER_INLINE_THRESHOLD
:
f64
=
1
_000_000
.
0
;
const
NUMBER_INLINE_THRESHOLD
:
f64
=
1
_000_000
.
0
;
const
BIGINT_INLINE_THRESHOLD
:
i64
=
1
_000_000
;
const
BIGINT_INLINE_THRESHOLD
:
i64
=
1
_000_000
;
#[derive(Clone,
Copy)]
enum
AutomaticInlineStatus
{
Inline
,
TooLong
,
HasIdentity
,
}
fn
automatic_inline_status
(
value
:
&
ConstantValue
)
->
AutomaticInlineStatus
{
match
value
{
ConstantValue
::
Str
(
s
)
if
s
.as_str
()
.len
()
>
STRING_INLINE_THRESHOLD
=>
{
AutomaticInlineStatus
::
TooLong
}
ConstantValue
::
Num
(
n
)
if
n
.
0
.abs
()
>
NUMBER_INLINE_THRESHOLD
=>
{
AutomaticInlineStatus
::
TooLong
}
ConstantValue
::
BigInt
(
n
)
if
**
n
>
BigInt
::
from
(
BIGINT_INLINE_THRESHOLD
)
||
**
n
<
BigInt
::
from
(
-
BIGINT_INLINE_THRESHOLD
)
=>
{
AutomaticInlineStatus
::
TooLong
}
ConstantValue
::
Regex
(
_
)
=>
AutomaticInlineStatus
::
HasIdentity
,
ConstantValue
::
Undefined
|
ConstantValue
::
Null
|
ConstantValue
::
True
|
ConstantValue
::
False
|
ConstantValue
::
Num
(
_
)
|
ConstantValue
::
BigInt
(
_
)
|
ConstantValue
::
Str
(
_
)
=>
AutomaticInlineStatus
::
Inline
,
}
}
/// Import names that are all-uppercase and contain at least one letter are eligible for automatic
/// Import names that are all-uppercase and contain at least one letter are eligible for automatic
/// constant inlining, even without an import attribute.
/// constant inlining, even without an import attribute.
pub
fn
is_import_name_eligible_for_exports
(
name
:
&
str
)
->
bool
{
pub
fn
is_import_name_eligible_for_exports
(
name
:
&
str
)
->
bool
{
...
@@ -126,42 +161,21 @@ impl ConstantsModule {
...
@@ -126,42 +161,21 @@ impl ConstantsModule {
match
value
{
match
value
{
ConstantsModuleExport
::
Constant
(
value
)
=>
{
ConstantsModuleExport
::
Constant
(
value
)
=>
{
if
!
has_opt_in
{
if
!
has_opt_in
{
// when not having opt in, only inline short literals
// when not having opt in, only inline short primitive values
match
&
value
.
0
{
match
automatic_inline_status
(
&
value
.
0
)
{
ConstantValue
::
Str
(
s
)
AutomaticInlineStatus
::
Inline
=>
{
if
s
.as_str
()
.len
()
>
STRING_INLINE_THRESHOLD
=>
JsValue
::
Constant
(
value
.
0
.clone
())
{
JsValue
::
unknown_empty
(
false
,
rcstr!
(
"constant too long"
),
)
}
}
ConstantValue
::
Num
(
n
)
AutomaticInlineStatus
::
TooLong
=>
JsValue
::
unknown_empty
(
if
n
.
0
.abs
()
>
NUMBER_INLINE_THRESHOLD
=>
false
,
{
rcstr!
(
"constant too long"
),
JsValue
::
unknown_empty
(
),
false
,
AutomaticInlineStatus
::
HasIdentity
=>
{
rcstr!
(
"constant too long"
),
)
}
ConstantValue
::
BigInt
(
n
)
if
**
n
>
BigInt
::
from
(
BIGINT_INLINE_THRESHOLD
)
||
**
n
<
BigInt
::
from
(
-
BIGINT_INLINE_THRESHOLD
)
=>
{
JsValue
::
unknown_empty
(
false
,
rcstr!
(
"constant too long"
),
)
}
ConstantValue
::
Regex
(
_
)
=>
{
// Regexes are literals, but they are also objects, so
// have identity and aren't inlined without opt in.
JsValue
::
unknown_empty
(
JsValue
::
unknown_empty
(
false
,
false
,
rcstr!
(
"regex not inlined"
),
rcstr!
(
"regex not inlined"
),
)
)
}
}
v
=>
JsValue
::
Constant
(
v
.clone
()),
}
}
}
else
{
}
else
{
JsValue
::
Constant
(
value
.
0
.clone
())
JsValue
::
Constant
(
value
.
0
.clone
())
...
@@ -189,10 +203,53 @@ impl ConstantsModule {
...
@@ -189,10 +203,53 @@ impl ConstantsModule {
}
}
}
}
pub
async
fn
get_inline_export
(
import_reference
:
ResolvedVc
<
EsmAssetReference
>
,
export
:
&
str
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
)
->
Result
<
Option
<
CompileTimeDefineValue
>>
{
let
resolved
=
import_reference
.resolve_reference
()
.await
?
;
let
Some
(
module
)
=
resolved
.first_module
()
.await
?
else
{
return
Ok
(
None
);
};
let
constants
=
get_inline_constants
(
*
module
,
compile_time_info
)
.await
?
;
let
Some
(
constants
)
=
constants
.as_ref
()
else
{
return
Ok
(
None
);
};
let
Some
((
_
,
ConstantsModuleExport
::
Constant
(
value
)))
=
constants
.exports
.iter
()
.find
(|(
name
,
_
)|
name
==
export
)
else
{
return
Ok
(
None
);
};
if
!
matches!
(
automatic_inline_status
(
&
value
.
0
),
AutomaticInlineStatus
::
Inline
)
{
return
Ok
(
None
);
}
Ok
(
CompileTimeDefineValue
::
try_from
(
&
value
.
0
)
.ok
())
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
get_constants
(
pub
async
fn
get_constants
(
module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
)
->
Result
<
Vc
<
OptionConstantsModule
>>
{
get_constants_internal
(
module
,
compile_time_info
,
false
)
.await
}
#[turbo_tasks
::
function]
async
fn
get_inline_constants
(
module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
)
->
Result
<
Vc
<
OptionConstantsModule
>>
{
get_constants_internal
(
module
,
compile_time_info
,
true
)
.await
}
async
fn
get_constants_internal
(
module
:
ResolvedVc
<
Box
<
dyn
Module
>>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
include_default_expression
:
bool
,
)
->
Result
<
Vc
<
OptionConstantsModule
>>
{
)
->
Result
<
Vc
<
OptionConstantsModule
>>
{
let
Some
(
parseable
)
=
ResolvedVc
::
try_sidecast
::
<
Box
<
dyn
EcmascriptParsable
>>
(
module
)
else
{
let
Some
(
parseable
)
=
ResolvedVc
::
try_sidecast
::
<
Box
<
dyn
EcmascriptParsable
>>
(
module
)
else
{
// should never actually happen, there should be a "imported module is not chunkable" error
// should never actually happen, there should be a "imported module is not chunkable" error
...
@@ -216,6 +273,20 @@ pub async fn get_constants(
...
@@ -216,6 +273,20 @@ pub async fn get_constants(
let
arena
=
ThreadLocal
::
new
();
let
arena
=
ThreadLocal
::
new
();
let
default_export_value
=
if
include_default_expression
&&
let
Program
::
Module
(
module
)
=
program
{
module
.body
.iter
()
.find_map
(|
item
|
match
item
{
ModuleItem
::
ModuleDecl
(
ModuleDecl
::
ExportDefaultExpr
(
export
))
=>
{
Some
(
GLOBALS
.set
(
globals
,
||
{
eval_context
.eval
(
arena
.get_or_default
(),
&
export
.expr
)
}))
}
_
=>
None
,
})
}
else
{
None
};
let
var_graph
=
{
let
var_graph
=
{
let
supports_block_scoping
=
*
compile_time_info
let
supports_block_scoping
=
*
compile_time_info
.environment
()
.environment
()
...
@@ -251,7 +322,13 @@ pub async fn get_constants(
...
@@ -251,7 +322,13 @@ pub async fn get_constants(
.iter
()
.iter
()
.map
(
async
|(
export_name
,
(
binding
,
span
))|
{
.map
(
async
|(
export_name
,
(
binding
,
span
))|
{
let
value
=
GLOBALS
.set
(
globals
,
||
{
let
value
=
GLOBALS
.set
(
globals
,
||
{
eval_context
.eval_id
(
arena
.get_or_default
(),
binding
.clone
())
if
export_name
.as_str
()
==
"default"
&&
let
Some
(
value
)
=
&
default_export_value
{
value
.clone_in
(
arena
.get_or_default
())
}
else
{
eval_context
.eval_id
(
arena
.get_or_default
(),
binding
.clone
())
}
});
});
let
linked_value
=
link
(
let
linked_value
=
link
(
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
1d0ed883
...
@@ -126,7 +126,8 @@ use crate::{
...
@@ -126,7 +126,8 @@ use crate::{
async_module
::{
AsyncModule
,
OptionAsyncModule
},
async_module
::{
AsyncModule
,
OptionAsyncModule
},
cjs
::{
CjsAssetReference
,
CjsRequireAssetReference
,
CjsRequireResolveAssetReference
},
cjs
::{
CjsAssetReference
,
CjsRequireAssetReference
,
CjsRequireResolveAssetReference
},
cross_module_constants
::{
cross_module_constants
::{
is_import_name_eligible_for_exports
,
module_value_to_constants_module
,
get_inline_export
,
is_import_name_eligible_for_exports
,
module_value_to_constants_module
,
},
},
dynamic_expression
::
DynamicExpression
,
dynamic_expression
::
DynamicExpression
,
emit_collect
::{
CollectReference
,
EmitReference
},
emit_collect
::{
CollectReference
,
EmitReference
},
...
@@ -552,6 +553,8 @@ struct AnalysisState<'a> {
...
@@ -552,6 +553,8 @@ struct AnalysisState<'a> {
var_cache
:
Mutex
<
FxHashMap
<
Id
,
JsValue
<
'a
>>>
,
var_cache
:
Mutex
<
FxHashMap
<
Id
,
JsValue
<
'a
>>>
,
/// A cache for the linked value of imported constants.
/// A cache for the linked value of imported constants.
constants_cache
:
Mutex
<
FxHashMap
<
ModuleValue
,
Option
<
JsValue
<
'a
>>>>
,
constants_cache
:
Mutex
<
FxHashMap
<
ModuleValue
,
Option
<
JsValue
<
'a
>>>>
,
/// A cache for constants used only during export inlining code generation.
inline_exports_cache
:
Mutex
<
FxHashMap
<
(
usize
,
RcStr
),
Option
<
CompileTimeDefineValue
>>>
,
// There can be many references to import.meta, but only the first should hoist
// There can be many references to import.meta, but only the first should hoist
// the object allocation.
// the object allocation.
first_import_meta
:
bool
,
first_import_meta
:
bool
,
...
@@ -582,6 +585,24 @@ struct AnalysisState<'a> {
...
@@ -582,6 +585,24 @@ struct AnalysisState<'a> {
}
}
impl
<
'a
>
AnalysisState
<
'a
>
{
impl
<
'a
>
AnalysisState
<
'a
>
{
/// Gets a short constant export for code-generation-only inlining.
async
fn
get_inline_export
(
&
self
,
reference_idx
:
usize
,
export
:
RcStr
,
)
->
Result
<
Option
<
CompileTimeDefineValue
>>
{
let
key
=
(
reference_idx
,
export
.clone
());
if
let
Some
(
value
)
=
self
.inline_exports_cache
.lock
()
.get
(
&
key
)
{
return
Ok
(
value
.clone
());
}
let
Some
(
reference
)
=
self
.import_references
.get
(
reference_idx
)
else
{
bail!
(
"couldn't find import reference at index {reference_idx}"
);
};
let
value
=
get_inline_export
(
*
reference
,
&
export
,
*
self
.compile_time_info
)
.await
?
;
self
.inline_exports_cache
.lock
()
.insert
(
key
,
value
.clone
());
Ok
(
value
)
}
/// Links a value to the graph, returning the linked value.
/// Links a value to the graph, returning the linked value.
async
fn
link_value
(
async
fn
link_value
(
&
self
,
&
self
,
...
@@ -929,6 +950,7 @@ async fn analyze_ecmascript_module_internal(
...
@@ -929,6 +950,7 @@ async fn analyze_ecmascript_module_internal(
fun_args_values
:
Default
::
default
(),
fun_args_values
:
Default
::
default
(),
var_cache
:
Default
::
default
(),
var_cache
:
Default
::
default
(),
constants_cache
:
Default
::
default
(),
constants_cache
:
Default
::
default
(),
inline_exports_cache
:
Default
::
default
(),
first_import_meta
:
true
,
first_import_meta
:
true
,
first_webpack_exports_info
:
true
,
first_webpack_exports_info
:
true
,
module_fragments_enabled
:
options
.module_fragments_enabled
,
module_fragments_enabled
:
options
.module_fragments_enabled
,
...
@@ -1457,6 +1479,16 @@ async fn analyze_ecmascript_module_internal(
...
@@ -1457,6 +1479,16 @@ async fn analyze_ecmascript_module_internal(
c
,
c
,
analysis
.intern_path
(
&
ast_path
),
analysis
.intern_path
(
&
ast_path
),
));
));
}
else
if
options
.inline_constant_exports
&&
let
Some
(
export
)
=
export
.as_ref
()
&&
let
Some
(
c
)
=
analysis_state
.get_inline_export
(
esm_reference_index
,
export
.clone
())
.await
?
{
analysis
.add_code_gen
(
ConstantValueCodeGen
::
new_inline_export
(
c
,
analysis
.intern_path
(
&
ast_path
),
));
}
else
if
let
Some
(
"__turbopack_module_id__"
)
=
export
.as_deref
()
{
}
else
if
let
Some
(
"__turbopack_module_id__"
)
=
export
.as_deref
()
{
let
chunking_type
=
r
.await
?
.chunking_type
();
let
chunking_type
=
r
.await
?
.chunking_type
();
analysis
.add_reference_code_gen
(
analysis
.add_reference_code_gen
(
...
...
turbopack/crates/turbopack-tests/tests/execution.rs
View file @
1d0ed883
...
@@ -292,6 +292,8 @@ struct TestOptions {
...
@@ -292,6 +292,8 @@ struct TestOptions {
#[serde(default
=
"default_true"
)]
#[serde(default
=
"default_true"
)]
cross_module_constants
:
bool
,
cross_module_constants
:
bool
,
#[serde(default)]
#[serde(default)]
inline_constant_exports
:
bool
,
#[serde(default)]
cjs_scope_hoisting
:
bool
,
cjs_scope_hoisting
:
bool
,
#[serde(default)]
#[serde(default)]
minify
:
bool
,
minify
:
bool
,
...
@@ -331,6 +333,7 @@ impl Default for TestOptions {
...
@@ -331,6 +333,7 @@ impl Default for TestOptions {
mangle_via_materialized_namespace_object
:
default_true
(),
mangle_via_materialized_namespace_object
:
default_true
(),
cjs_scope_hoisting
:
false
,
cjs_scope_hoisting
:
false
,
cross_module_constants
:
true
,
cross_module_constants
:
true
,
inline_constant_exports
:
false
,
infer_module_side_effects
:
default_true
(),
infer_module_side_effects
:
default_true
(),
minify
:
false
,
minify
:
false
,
production_chunking
:
false
,
production_chunking
:
false
,
...
@@ -513,6 +516,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
...
@@ -513,6 +516,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
.mangle_via_materialized_namespace_object
,
.mangle_via_materialized_namespace_object
,
cjs_scope_hoisting
:
options
.cjs_scope_hoisting
,
cjs_scope_hoisting
:
options
.cjs_scope_hoisting
,
cross_module_constants
:
options
.cross_module_constants
,
cross_module_constants
:
options
.cross_module_constants
,
inline_constant_exports
:
options
.inline_constant_exports
,
infer_module_side_effects
:
options
.infer_module_side_effects
,
infer_module_side_effects
:
options
.infer_module_side_effects
,
..
Default
::
default
()
..
Default
::
default
()
},
},
...
...
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-cycle/input/a.js
0 → 100644
View file @
1d0ed883
import
{
readA
}
from
'./b'
export
const
value
=
'a'
export
function
completeCycle
()
{
return
readA
()
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-cycle/input/b.js
0 → 100644
View file @
1d0ed883
import
{
value
}
from
'./a'
export
function
readA
()
{
return
value
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-cycle/input/index.js
0 → 100644
View file @
1d0ed883
import
{
readA
}
from
'./b'
it
(
'inlines across an import cycle without retaining the constants module'
,
()
=>
{
expect
(
readA
()).
toBe
(
'a'
)
const
source
=
readA
.
toString
()
expect
(
source
).
toContain
(
'"a"'
)
expect
(
source
).
not
.
toContain
(
'TURBOPACK compile-time value'
)
expect
(
source
).
not
.
toContain
(
'value'
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
b
\.
js/
))
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/input
\/
a
\.
js/
))
})
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-cycle/options.json
0 → 100644
View file @
1d0ed883
{
"scopeHoisting"
:
false
,
"mangleExportNames"
:
false
,
"crossModuleConstants"
:
false
,
"inlineConstantExports"
:
true
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-disabled/input/index.js
0 → 100644
View file @
1d0ed883
import
{
value
}
from
'disabled-constants'
function
readValue
()
{
return
value
}
it
(
'keeps runtime bindings when both constant features are disabled'
,
()
=>
{
expect
(
readValue
()).
toBe
(
'dev'
)
expect
(
readValue
.
toString
()).
toContain
(
'["value"]'
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
disabled-constants
\/
index
\.
js/
)
)
})
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-disabled/input/node_modules/disabled-constants/index.js
0 → 100644
View file @
1d0ed883
export
const
value
=
'dev'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-disabled/input/node_modules/disabled-constants/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-disabled/options.json
0 → 100644
View file @
1d0ed883
{
"scopeHoisting"
:
false
,
"mangleExportNames"
:
false
,
"crossModuleConstants"
:
false
,
"inlineConstantExports"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/analysis-marker.js
0 → 100644
View file @
1d0ed883
export
const
marker
=
'ANALYSIS_MARKER'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/annotation-off-marker.js
0 → 100644
View file @
1d0ed883
export
const
marker
=
'ANNOTATION_OFF_MARKER'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/forced-marker.js
0 → 100644
View file @
1d0ed883
export
const
marker
=
'FORCED_MARKER'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/index.js
0 → 100644
View file @
1d0ed883
import
{
ANALYZED
,
late
}
from
'inline-values'
import
{
forced
}
from
'inline-values'
with
{
turbopackConstants
:
'true'
}
import
{
annotationOff
}
from
'inline-values'
with
{
turbopackConstants
:
'false'
}
if
(
ANALYZED
)
require
(
'./analysis-marker'
)
if
(
forced
)
require
(
'./forced-marker'
)
if
(
late
!==
'dev'
)
require
(
'./late-marker'
)
if
(
annotationOff
!==
'off'
)
require
(
'./annotation-off-marker'
)
function
readAnalyzed
()
{
return
ANALYZED
}
function
readLate
()
{
return
late
}
function
readAnnotationOff
()
{
return
annotationOff
}
it
(
'preserves analyzer-aware precedence and falls back to codegen-only inlining'
,
()
=>
{
expect
(
readAnalyzed
()).
toBe
(
false
)
expect
(
readLate
()).
toBe
(
'dev'
)
expect
(
readAnnotationOff
()).
toBe
(
'off'
)
expect
(
readAnalyzed
.
toString
()).
toContain
(
'TURBOPACK compile-time value'
)
expect
(
readLate
.
toString
()).
not
.
toContain
(
'TURBOPACK compile-time value'
)
expect
(
readLate
.
toString
()).
not
.
toContain
(
'late'
)
expect
(
readAnnotationOff
.
toString
()).
not
.
toContain
(
'annotationOff'
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/input
\/
analysis-marker
\.
js/
)
)
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/input
\/
forced-marker
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
late-marker
\.
js/
))
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
annotation-off-marker
\.
js/
)
)
})
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/late-marker.js
0 → 100644
View file @
1d0ed883
export
const
marker
=
'LATE_MARKER'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/node_modules/inline-values/index.js
0 → 100644
View file @
1d0ed883
export
const
ANALYZED
=
false
export
const
forced
=
false
export
const
late
=
'dev'
export
const
annotationOff
=
'off'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/input/node_modules/inline-values/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-interactions/options.json
0 → 100644
View file @
1d0ed883
{
"scopeHoisting"
:
false
,
"mangleExportNames"
:
false
,
"crossModuleConstants"
:
true
,
"inlineConstantExports"
:
true
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-mutual/input/a.js
0 → 100644
View file @
1d0ed883
import
{
bValue
}
from
'./b'
globalThis
.
mutualAEvaluations
=
(
globalThis
.
mutualAEvaluations
??
0
)
+
1
export
const
aValue
=
'a'
export
function
readB
()
{
return
bValue
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-mutual/input/b.js
0 → 100644
View file @
1d0ed883
import
{
aValue
}
from
'./a'
globalThis
.
mutualBEvaluations
=
(
globalThis
.
mutualBEvaluations
??
0
)
+
1
export
const
bValue
=
'b'
export
function
readA
()
{
return
aValue
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-mutual/input/index.js
0 → 100644
View file @
1d0ed883
import
{
readB
}
from
'./a'
import
{
readA
}
from
'./b'
it
(
'supports two retained modules importing constants from each other'
,
()
=>
{
expect
(
readB
()).
toBe
(
'b'
)
expect
(
readA
()).
toBe
(
'a'
)
expect
(
globalThis
.
mutualAEvaluations
).
toBe
(
1
)
expect
(
globalThis
.
mutualBEvaluations
).
toBe
(
1
)
expect
(
readB
.
toString
()).
toContain
(
'"b"'
)
expect
(
readB
.
toString
()).
not
.
toContain
(
'bValue'
)
expect
(
readA
.
toString
()).
toContain
(
'"a"'
)
expect
(
readA
.
toString
()).
not
.
toContain
(
'aValue'
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
a
\.
js/
))
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
b
\.
js/
))
})
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports-mutual/options.json
0 → 100644
View file @
1d0ed883
{
"scopeHoisting"
:
false
,
"mangleExportNames"
:
false
,
"crossModuleConstants"
:
false
,
"inlineConstantExports"
:
true
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/index.js
0 → 100644
View file @
1d0ed883
import
{
shortString
,
smallNumber
,
smallBigInt
,
booleanFalse
,
nil
,
undef
,
stableLet
,
stableVar
,
}
from
'short-constants'
import
{
regex
}
from
'identity-values'
import
{
longString
,
nan
,
positiveInfinity
,
negativeInfinity
,
}
from
'long-values'
import
shortDefault
from
'short-default'
import
longDefault
from
'long-default'
import
{
mode
}
from
'analysis-constant'
import
{
effectValue
}
from
'effect-constant'
import
{
reassigned
}
from
'reassigned-binding'
import
*
as
staticNamespace
from
'namespace-static'
import
*
as
escapingNamespace
from
'namespace-escape'
const
escapedNamespace
=
escapingNamespace
if
(
mode
!==
'dev'
)
{
require
(
'./marker'
)
}
function
readShortValues
()
{
return
[
shortString
,
smallNumber
,
smallBigInt
,
booleanFalse
,
nil
,
undef
,
stableLet
,
stableVar
,
]
}
function
readMode
()
{
return
mode
}
function
readStaticNamespace
()
{
return
staticNamespace
.
short
}
function
readShortDefault
()
{
return
shortDefault
}
it
(
'inlines short primitive exports during code generation'
,
()
=>
{
expect
(
readShortValues
()).
toEqual
([
'dev'
,
1
,
1
n
,
false
,
null
,
undefined
,
'let'
,
'var'
,
])
expect
(
readMode
()).
toBe
(
'dev'
)
expect
(
readStaticNamespace
()).
toBe
(
'ns'
)
expect
(
readShortDefault
()).
toBe
(
'def'
)
const
source
=
readShortValues
.
toString
()
expect
(
source
).
toContain
(
'"dev"'
)
expect
(
source
).
toContain
(
'1n'
)
expect
(
source
).
toContain
(
'false'
)
expect
(
source
).
toContain
(
'null'
)
expect
(
source
).
toContain
(
'void 0'
)
expect
(
source
).
not
.
toContain
(
'TURBOPACK compile-time value'
)
expect
(
source
).
not
.
toContain
(
'shortString'
)
expect
(
source
).
not
.
toContain
(
'smallNumber'
)
expect
(
readStaticNamespace
.
toString
()).
not
.
toContain
(
'staticNamespace'
)
expect
(
readShortDefault
.
toString
()).
toContain
(
'"def"'
)
expect
(
readShortDefault
.
toString
()).
not
.
toContain
(
'shortDefault'
)
})
it
(
'omits inlined export modules without using values for analysis'
,
()
=>
{
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
short-constants
\/
index
\.
js/
)
)
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
analysis-constant
\/
index
\.
js/
)
)
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
namespace-static
\/
index
\.
js/
)
)
expect
(
modules
).
not
.
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
short-default
\/
index
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/input
\/
marker
\.
js/
))
})
it
(
'preserves evaluation references for side-effectful modules'
,
()
=>
{
expect
(
effectValue
).
toBe
(
'ok'
)
expect
(
globalThis
.
inlineExportSideEffect
).
toBe
(
1
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
effect-constant
\/
index
\.
js/
)
)
})
it
(
'does not inline reassigned bindings, identity values, long values, or escaping namespaces'
,
()
=>
{
expect
(
reassigned
).
toBe
(
'b'
)
expect
(
escapedNamespace
.
short
).
toBe
(
'ns'
)
expect
(
regex
).
toBe
(
regex
)
expect
(
longString
).
toBe
(
'this value is deliberately too long'
)
expect
(
nan
).
toBeNaN
()
expect
(
positiveInfinity
).
toBe
(
Infinity
)
expect
(
negativeInfinity
).
toBe
(
-
Infinity
)
expect
(
longDefault
).
toBe
(
'this default value is too long'
)
const
modules
=
Array
.
from
(
__turbopack_modules__
.
keys
())
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
reassigned-binding
\/
index
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
namespace-escape
\/
index
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
identity-values
\/
index
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
long-values
\/
index
\.
js/
)
)
expect
(
modules
).
toContainEqual
(
expect
.
stringMatching
(
/node_modules
\/
long-default
\/
index
\.
js/
)
)
})
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/marker.js
0 → 100644
View file @
1d0ed883
export
const
marker
=
'ANALYSIS_REFERENCE_RETAINED'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/analysis-constant/index.js
0 → 100644
View file @
1d0ed883
export
const
mode
=
'dev'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/analysis-constant/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/effect-constant/index.js
0 → 100644
View file @
1d0ed883
globalThis
.
inlineExportSideEffect
=
(
globalThis
.
inlineExportSideEffect
??
0
)
+
1
export
const
effectValue
=
'ok'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/effect-constant/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
true
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/identity-values/index.js
0 → 100644
View file @
1d0ed883
export
const
regex
=
/a/
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/identity-values/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/long-default/index.js
0 → 100644
View file @
1d0ed883
export
default
'this default value is too long'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/long-default/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/long-values/index.js
0 → 100644
View file @
1d0ed883
export
const
longString
=
'this value is deliberately too long'
export
const
nan
=
NaN
export
const
positiveInfinity
=
Infinity
export
const
negativeInfinity
=
-
Infinity
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/long-values/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/namespace-escape/index.js
0 → 100644
View file @
1d0ed883
export
const
short
=
'ns'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/namespace-escape/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/namespace-static/index.js
0 → 100644
View file @
1d0ed883
export
const
short
=
'ns'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/namespace-static/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/reassigned-binding/index.js
0 → 100644
View file @
1d0ed883
export
let
reassigned
=
'a'
reassigned
=
'b'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/reassigned-binding/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/short-constants/index.js
0 → 100644
View file @
1d0ed883
export
const
shortString
=
'dev'
export
const
smallNumber
=
1
export
const
smallBigInt
=
1
n
export
const
booleanFalse
=
false
export
const
nil
=
null
export
const
undef
=
undefined
export
let
stableLet
=
'let'
export
var
stableVar
=
'var'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/short-constants/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/short-default/index.js
0 → 100644
View file @
1d0ed883
export
default
'def'
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/input/node_modules/short-default/package.json
0 → 100644
View file @
1d0ed883
{
"sideEffects"
:
false
}
turbopack/crates/turbopack-tests/tests/execution/turbopack/optimization/codegen-inline-exports/options.json
0 → 100644
View file @
1d0ed883
{
"scopeHoisting"
:
false
,
"mangleExportNames"
:
false
,
"crossModuleConstants"
:
false
,
"inlineConstantExports"
:
true
}
turbopack/crates/turbopack/src/module_options/mod.rs
View file @
1d0ed883
...
@@ -250,6 +250,7 @@ impl ModuleOptions {
...
@@ -250,6 +250,7 @@ impl ModuleOptions {
mangle_via_materialized_namespace_object
,
mangle_via_materialized_namespace_object
,
cjs_scope_hoisting
,
cjs_scope_hoisting
,
cross_module_constants
,
cross_module_constants
,
inline_constant_exports
,
lazy_compilation
,
lazy_compilation
,
ref
preset_env_config
,
ref
preset_env_config
,
..
..
...
@@ -349,6 +350,7 @@ impl ModuleOptions {
...
@@ -349,6 +350,7 @@ impl ModuleOptions {
mangle_via_materialized_namespace_object
,
mangle_via_materialized_namespace_object
,
cjs_scope_hoisting
,
cjs_scope_hoisting
,
cross_module_constants
,
cross_module_constants
,
inline_constant_exports
,
lazy_compilation
,
lazy_compilation
,
..
Default
::
default
()
..
Default
::
default
()
};
};
...
...
turbopack/crates/turbopack/src/module_options/module_options_context.rs
View file @
1d0ed883
...
@@ -298,11 +298,16 @@ pub struct EcmascriptOptionsContext {
...
@@ -298,11 +298,16 @@ pub struct EcmascriptOptionsContext {
/// Whether to scope-hoist static CommonJS modules. Defaults to false.
/// Whether to scope-hoist static CommonJS modules. Defaults to false.
pub
cjs_scope_hoisting
:
bool
,
pub
cjs_scope_hoisting
:
bool
,
/// Whether to enable cross-module constant inlining. Defaults to false.
/// Whether to use cross-module constants during analysis and code generation. Defaults to
/// false.
pub
cross_module_constants
:
bool
,
pub
cross_module_constants
:
bool
,
/// Whether dynamic import targets are compiled after their runtime proxy is activated.
/// Whether dynamic import targets are compiled after their runtime proxy is activated.
pub
lazy_compilation
:
bool
,
pub
lazy_compilation
:
bool
,
/// Whether to inline short, identity-free constant exports only during code generation.
/// Defaults to false.
pub
inline_constant_exports
:
bool
,
/// Additional SWC preset-env options (mode, coreJs, include, exclude, etc.).
/// Additional SWC preset-env options (mode, coreJs, include, exclude, etc.).
pub
preset_env_config
:
Option
<
ResolvedVc
<
PresetEnvConfig
>>
,
pub
preset_env_config
:
Option
<
ResolvedVc
<
PresetEnvConfig
>>
,
...
...
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