Unverified Commit 66211372 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

turbopack: skip strict directives of referenced chunk item cells

Strict factories inside a strict chunk wrapper reference their code cell together with a factory-owned cell holding the directive's byte range. The CellRope applies it with Rope::skip when read, so chunk compositions stay independent of the directive's position.
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 4bd51aff
...@@ -50,7 +50,7 @@ use turbo_rcstr::RcStr; ...@@ -50,7 +50,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{NonLocalValue, ResolvedVc, ValueToString, Vc, turbobail, turbofmt}; use turbo_tasks::{NonLocalValue, ResolvedVc, ValueToString, Vc, turbobail, turbofmt};
pub use crate::{ pub use crate::{
cell_rope::{CellRope, CellRopeBuilder, CellRopePart}, cell_rope::{CellRope, CellRopeBuilder, CellRopePart, OptionByteRange},
content::{ content::{
File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent, File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent,
LinkTarget, Permissions, PersistedFileContent, WriteLinkContent, WriteLinkTargetType, LinkTarget, Permissions, PersistedFileContent, WriteLinkContent, WriteLinkTargetType,
......
...@@ -5,7 +5,7 @@ use turbo_rcstr::RcStr; ...@@ -5,7 +5,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, debug::ValueDebugFormat, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, debug::ValueDebugFormat,
}; };
use turbo_tasks_fs::rope::Rope; use turbo_tasks_fs::{OptionByteRange, rope::Rope};
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkItem, ChunkItemExt, MangleType, MinifyType, ModuleId}, chunk::{ChunkItem, ChunkItemExt, MangleType, MinifyType, ModuleId},
code_builder::CodeCells, code_builder::CodeCells,
...@@ -50,9 +50,11 @@ async fn code_module_id_and_path( ...@@ -50,9 +50,11 @@ async fn code_module_id_and_path(
} }
MinifyType::NoMinify => factory.code, MinifyType::NoMinify => factory.code,
}; };
let cells_value = cells.await?;
Ok(CodeModuleIdAndPath { Ok(CodeModuleIdAndPath {
id: item.chunk_item.id().await?, id: item.chunk_item.id().await?,
code: cells.await?.code(), code: cells_value.code(),
strict_directive: cells_value.strict_directive_range(),
cells, cells,
path: item.chunk_item.asset_ident().to_string().owned().await?, path: item.chunk_item.asset_ident().to_string().owned().await?,
strict: factory.strict, strict: factory.strict,
...@@ -86,6 +88,9 @@ pub struct CodeModuleIdAndPath { ...@@ -86,6 +88,9 @@ pub struct CodeModuleIdAndPath {
pub cells: ResolvedVc<CodeCells>, pub cells: ResolvedVc<CodeCells>,
/// The cell holding the factory's bytes ([`CodeCells::code`]). /// The cell holding the factory's bytes ([`CodeCells::code`]).
pub code: ResolvedVc<Rope>, pub code: ResolvedVc<Rope>,
/// The cell holding the byte range of the factory's strict directive
/// ([`CodeCells::strict_directive_range`]).
pub strict_directive: ResolvedVc<OptionByteRange>,
pub path: RcStr, pub path: RcStr,
pub strict: bool, pub strict: bool,
} }
......
...@@ -32,9 +32,17 @@ pub trait ModuleFactorySink<F>: Write + AddAssign<&'static str> { ...@@ -32,9 +32,17 @@ pub trait ModuleFactorySink<F>: Write + AddAssign<&'static str> {
/// References each factory's cells, so that the chunk's persisted representation doesn't copy /// References each factory's cells, so that the chunk's persisted representation doesn't copy
/// them, and doesn't depend on their bytes. /// them, and doesn't depend on their bytes.
impl ModuleFactorySink<CodeModuleIdAndPath> for CodeCompositionBuilder { impl ModuleFactorySink<CodeModuleIdAndPath> for CodeCompositionBuilder {
fn push_factory(&mut self, factory: &CodeModuleIdAndPath, _without_strict_directive: bool) { fn push_factory(&mut self, factory: &CodeModuleIdAndPath, without_strict_directive: bool) {
if without_strict_directive {
self.push_code_cells_without_strict_directive(
factory.cells,
factory.code,
factory.strict_directive,
);
} else {
self.push_code_cells(factory.cells, factory.code); self.push_code_cells(factory.cells, factory.code);
} }
}
} }
// The chunk scaffolding is written in minified form in every mode, so a chunk whose factories // The chunk scaffolding is written in minified form in every mode, so a chunk whose factories
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment