Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Aug 2, 2024
1 parent e99be01 commit 2481cfb
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 41 deletions.
1 change: 1 addition & 0 deletions turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl RuntimeEntry {
request,
None,
IssueSeverity::Error.cell(),
false,
)
.resolve()
.await?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl ImportAnnotations {
map.insert(key.into(), value.value.as_str().into());
}

println!("ANNOTATIONS {:?}", map);

ImportAnnotations { map }
}

Expand Down Expand Up @@ -470,7 +472,6 @@ impl Visit for Analyzer<'_> {
.flatten()
.rev()
.filter_map(|comment| {
println!("{:?}", comment);
let (directive, value) = comment.text.trim().split_once(':')?;
// support whitespace between the colon
match (directive.trim(), value.trim()) {
Expand Down
2 changes: 2 additions & 0 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3733,6 +3733,8 @@ mod tests {

let mut var_graph = create_graph(&m, &eval_context);

println!("GRAPH {:#?}", var_graph);

let mut named_values = var_graph
.values
.clone()
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl EcmascriptModuleAsset {

#[turbo_tasks::function]
pub fn analyze(self: Vc<Self>) -> Vc<AnalyzeEcmascriptModuleResult> {
analyse_ecmascript_module(self, None)
analyse_ecmascript_module(self, None, None)
}

#[turbo_tasks::function]
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-ecmascript/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn parse_internal(
FileContent::Content(file) => match file.content().to_str() {
Ok(string) => {
let transforms = &*transforms.await?;
match parse_content(
match parse_file_content(
string.into_owned(),
fs_path_vc,
fs_path,
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn parse_internal(
})
}

async fn parse_content(
async fn parse_file_content(
string: String,
fs_path_vc: Vc<FileSystemPath>,
fs_path: &FileSystemPath,
Expand Down Expand Up @@ -433,7 +433,7 @@ async fn parse_content(
&parsed_program,
unresolved_mark,
top_level_mark,
None, // TODO(arlyon): pass comments
Some(&comments),
Some(source),
);

Expand Down
2 changes: 2 additions & 0 deletions turbopack/crates/turbopack-ecmascript/src/references/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl ModuleReference for AmdDefineAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
/* ignore */ false,
)
}
}
Expand Down Expand Up @@ -160,6 +161,7 @@ impl CodeGenerateable for AmdDefineWithDependenciesCodeGen {
*request,
Some(self.issue_source),
try_to_severity(self.in_try),
false,
),
Value::new(ChunkItem),
)
Expand Down
11 changes: 11 additions & 0 deletions turbopack/crates/turbopack-ecmascript/src/references/cjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ModuleReference for CjsAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
false,
)
}
}
Expand All @@ -81,6 +82,7 @@ pub struct CjsRequireAssetReference {
pub path: Vc<AstPath>,
pub issue_source: Vc<IssueSource>,
pub in_try: bool,
pub ignore_import: bool,
}

#[turbo_tasks::value_impl]
Expand All @@ -92,13 +94,15 @@ impl CjsRequireAssetReference {
path: Vc<AstPath>,
issue_source: Vc<IssueSource>,
in_try: bool,
ignore_import: bool,
) -> Vc<Self> {
Self::cell(CjsRequireAssetReference {
origin,
request,
path,
issue_source,
in_try,
ignore_import,
})
}
}
Expand All @@ -112,6 +116,7 @@ impl ModuleReference for CjsRequireAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
self.ignore_import,
)
}
}
Expand Down Expand Up @@ -145,6 +150,7 @@ impl CodeGenerateable for CjsRequireAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
false,
),
Value::new(ChunkItem),
)
Expand Down Expand Up @@ -188,6 +194,7 @@ pub struct CjsRequireResolveAssetReference {
pub path: Vc<AstPath>,
pub issue_source: Vc<IssueSource>,
pub in_try: bool,
pub ignore: bool,
}

#[turbo_tasks::value_impl]
Expand All @@ -199,13 +206,15 @@ impl CjsRequireResolveAssetReference {
path: Vc<AstPath>,
issue_source: Vc<IssueSource>,
in_try: bool,
ignore: bool,
) -> Vc<Self> {
Self::cell(CjsRequireResolveAssetReference {
origin,
request,
path,
issue_source,
in_try,
ignore,
})
}
}
Expand All @@ -219,6 +228,7 @@ impl ModuleReference for CjsRequireResolveAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
self.ignore,
)
}
}
Expand Down Expand Up @@ -252,6 +262,7 @@ impl CodeGenerateable for CjsRequireResolveAssetReference {
self.request,
Some(self.issue_source),
try_to_severity(self.in_try),
self.ignore,
),
Value::new(ChunkItem),
)
Expand Down
12 changes: 11 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/references/esm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub struct EsmAssetReference {
pub origin: Vc<Box<dyn ResolveOrigin>>,
pub request: Vc<Request>,
pub annotations: ImportAnnotations,
/// True if the import should be ignored
/// This can happen for example when the webpackIgnore or turbopackIgnore
/// directives are present
pub ignore: bool,
pub issue_source: Option<Vc<IssueSource>>,
pub export_name: Option<Vc<ModulePart>>,
pub import_externals: bool,
Expand Down Expand Up @@ -124,20 +128,22 @@ impl EsmAssetReference {
export_name: Option<Vc<ModulePart>>,
special_exports: Vc<Vec<RcStr>>,
import_externals: bool,
ignore: bool,
) -> Vc<Self> {
Self::cell(EsmAssetReference {
origin,
request,
issue_source,
annotations: annotations.into_value(),
ignore,
export_name,
import_externals,
special_exports,
})
}

#[turbo_tasks::function]
pub(crate) fn get_referenced_asset(self: Vc<Self>) -> Vc<ReferencedAsset> {
pub(crate) async fn get_referenced_asset(self: Vc<Self>) -> Vc<ReferencedAsset> {
ReferencedAsset::from_resolve_result(self.resolve_reference())
}
}
Expand All @@ -146,6 +152,9 @@ impl EsmAssetReference {
impl ModuleReference for EsmAssetReference {
#[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
if self.ignore {
return Ok(ModuleResolveResult::ignored().cell());
}
let ty = if matches!(self.annotations.module_type(), Some("json")) {
EcmaScriptModulesReferenceSubType::ImportWithType(ImportWithType::Json)
} else if let Some(part) = &self.export_name {
Expand Down Expand Up @@ -178,6 +187,7 @@ impl ModuleReference for EsmAssetReference {
Value::new(ty),
IssueSeverity::Error.cell(),
self.issue_source,
self.ignore,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct EsmAsyncAssetReference {
pub issue_source: Vc<IssueSource>,
pub in_try: bool,
pub import_externals: bool,
pub ignore: bool,
}

#[turbo_tasks::value_impl]
Expand All @@ -43,6 +44,7 @@ impl EsmAsyncAssetReference {
issue_source: Vc<IssueSource>,
in_try: bool,
import_externals: bool,
ignore: bool,
) -> Vc<Self> {
Self::cell(EsmAsyncAssetReference {
origin,
Expand All @@ -51,6 +53,7 @@ impl EsmAsyncAssetReference {
issue_source,
in_try,
import_externals,
ignore,
})
}
}
Expand All @@ -59,12 +62,14 @@ impl EsmAsyncAssetReference {
impl ModuleReference for EsmAsyncAssetReference {
#[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> {
// TODO: solve here
esm_resolve(
self.origin,
self.request,
Value::new(EcmaScriptModulesReferenceSubType::DynamicImport),
try_to_severity(self.in_try),
Some(self.issue_source),
self.ignore,
)
}
}
Expand Down Expand Up @@ -104,6 +109,7 @@ impl CodeGenerateable for EsmAsyncAssetReference {
Value::new(EcmaScriptModulesReferenceSubType::DynamicImport),
try_to_severity(self.in_try),
Some(self.issue_source),
self.ignore,
),
if matches!(
*chunking_context.environment().chunk_loading().await?,
Expand Down
Loading

0 comments on commit 2481cfb

Please sign in to comment.