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;
use turbo_tasks::{NonLocalValue, ResolvedVc, ValueToString, Vc, turbobail, turbofmt};
pub use crate::{
cell_rope::{CellRope, CellRopeBuilder, CellRopePart},
cell_rope::{CellRope, CellRopeBuilder, CellRopePart, OptionByteRange},
content::{
File, FileContent, FileJsonContent, FileLine, FileLinesContent, FileMeta, LinkContent,
LinkTarget, Permissions, PersistedFileContent, WriteLinkContent, WriteLinkTargetType,
......
......@@ -5,7 +5,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{
NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, debug::ValueDebugFormat,
};
use turbo_tasks_fs::rope::Rope;
use turbo_tasks_fs::{OptionByteRange, rope::Rope};
use turbopack_core::{
chunk::{ChunkItem, ChunkItemExt, MangleType, MinifyType, ModuleId},
code_builder::CodeCells,
......@@ -50,9 +50,11 @@ async fn code_module_id_and_path(
}
MinifyType::NoMinify => factory.code,
};
let cells_value = cells.await?;
Ok(CodeModuleIdAndPath {
id: item.chunk_item.id().await?,
code: cells.await?.code(),
code: cells_value.code(),
strict_directive: cells_value.strict_directive_range(),
cells,
path: item.chunk_item.asset_ident().to_string().owned().await?,
strict: factory.strict,
......@@ -86,6 +88,9 @@ pub struct CodeModuleIdAndPath {
pub cells: ResolvedVc<CodeCells>,
/// The cell holding the factory's bytes ([`CodeCells::code`]).
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 strict: bool,
}
......
......@@ -32,8 +32,16 @@ pub trait ModuleFactorySink<F>: Write + AddAssign<&'static str> {
/// References each factory's cells, so that the chunk's persisted representation doesn't copy
/// them, and doesn't depend on their bytes.
impl ModuleFactorySink<CodeModuleIdAndPath> for CodeCompositionBuilder {
fn push_factory(&mut self, factory: &CodeModuleIdAndPath, _without_strict_directive: bool) {
self.push_code_cells(factory.cells, factory.code);
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);
}
}
}
......
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