Unverified Commit cbc4888b authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[turbopack] Consider `ignoreList` of 3rd party sourcemaps in Redbox (#90317)

parent 9b6e563f
...@@ -2128,6 +2128,7 @@ pub fn project_compilation_events_subscribe( ...@@ -2128,6 +2128,7 @@ pub fn project_compilation_events_subscribe(
pub struct StackFrame { pub struct StackFrame {
pub is_server: bool, pub is_server: bool,
pub is_internal: Option<bool>, pub is_internal: Option<bool>,
pub is_ignored: Option<bool>,
pub original_file: Option<RcStr>, pub original_file: Option<RcStr>,
pub file: RcStr, pub file: RcStr,
/// 1-indexed, unlike source map tokens /// 1-indexed, unlike source map tokens
...@@ -2235,7 +2236,7 @@ pub async fn project_trace_source_operation( ...@@ -2235,7 +2236,7 @@ pub async fn project_trace_source_operation(
frame.column.unwrap_or(1).saturating_sub(1), frame.column.unwrap_or(1).saturating_sub(1),
); );
let (original_file, line, column, method_name) = match token { let (original_file, line, column, method_name, is_ignored) = match token {
Token::Original(token) => ( Token::Original(token) => (
match urlencoding::decode(&token.original_file)? { match urlencoding::decode(&token.original_file)? {
Cow::Borrowed(_) => token.original_file, Cow::Borrowed(_) => token.original_file,
...@@ -2245,12 +2246,13 @@ pub async fn project_trace_source_operation( ...@@ -2245,12 +2246,13 @@ pub async fn project_trace_source_operation(
Some(token.original_line + 1), Some(token.original_line + 1),
Some(token.original_column + 1), Some(token.original_column + 1),
token.name, token.name,
token.is_ignored,
), ),
Token::Synthetic(token) => { Token::Synthetic(token) => {
let Some(original_file) = token.guessed_original_file else { let Some(original_file) = token.guessed_original_file else {
return Ok(Vc::cell(None)); return Ok(Vc::cell(None));
}; };
(original_file, None, None, None) (original_file, None, None, None, false)
} }
}; };
...@@ -2303,6 +2305,7 @@ pub async fn project_trace_source_operation( ...@@ -2303,6 +2305,7 @@ pub async fn project_trace_source_operation(
column, column,
is_server: frame.is_server, is_server: frame.is_server,
is_internal: Some(is_internal), is_internal: Some(is_internal),
is_ignored: Some(is_ignored),
}))) })))
} }
......
...@@ -363,6 +363,7 @@ export declare function projectCompilationEventsSubscribe( ...@@ -363,6 +363,7 @@ export declare function projectCompilationEventsSubscribe(
export interface StackFrame { export interface StackFrame {
isServer: boolean isServer: boolean
isInternal?: boolean isInternal?: boolean
isIgnored?: boolean
originalFile?: RcStr originalFile?: RcStr
file: RcStr file: RcStr
/** 1-indexed, unlike source map tokens */ /** 1-indexed, unlike source map tokens */
......
...@@ -230,6 +230,7 @@ export interface HmrChunkNames { ...@@ -230,6 +230,7 @@ export interface HmrChunkNames {
export interface TurbopackStackFrame { export interface TurbopackStackFrame {
isServer: boolean isServer: boolean
isInternal?: boolean isInternal?: boolean
isIgnored?: boolean
file: string file: string
originalFile?: string originalFile?: string
/** 1-indexed, unlike source map tokens */ /** 1-indexed, unlike source map tokens */
......
...@@ -87,6 +87,8 @@ async function batchedTraceSource( ...@@ -87,6 +87,8 @@ async function batchedTraceSource(
// Don't look up source for node_modules or internals. These can often be large bundled files. // Don't look up source for node_modules or internals. These can often be large bundled files.
const ignored = const ignored =
// Check the sourcemap's ignoreList (e.g. from 3rd party packages)
!!sourceFrame.isIgnored ||
shouldIgnorePath(originalFile ?? sourceFrame.file) || shouldIgnorePath(originalFile ?? sourceFrame.file) ||
// isInternal means resource starts with turbopack:///[turbopack] // isInternal means resource starts with turbopack:///[turbopack]
!!sourceFrame.isInternal !!sourceFrame.isInternal
...@@ -104,7 +106,6 @@ async function batchedTraceSource( ...@@ -104,7 +106,6 @@ async function batchedTraceSource(
source = await sourcePromise source = await sourcePromise
} }
// TODO: get ignoredList from turbopack source map
const ignorableFrame: IgnorableStackFrame = { const ignorableFrame: IgnorableStackFrame = {
file: sourceFrame.file, file: sourceFrame.file,
line1: sourceFrame.line ?? null, line1: sourceFrame.line ?? null,
......
...@@ -318,7 +318,6 @@ describe('app-dir - server source maps', () => { ...@@ -318,7 +318,6 @@ describe('app-dir - server source maps', () => {
) )
if (isTurbopack) { if (isTurbopack) {
// TODO(veil): Turbopack errors because it thinks the sources are not part of the project. // TODO(veil): Turbopack errors because it thinks the sources are not part of the project.
// TODO(veil-NDX-910): Turbopack's sourcemap loader drops `ignoreList` in browser sourcemaps.
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"description": "ssr-error-log-ignore-listed", "description": "ssr-error-log-ignore-listed",
...@@ -330,7 +329,6 @@ describe('app-dir - server source maps', () => { ...@@ -330,7 +329,6 @@ describe('app-dir - server source maps', () => {
"stack": [ "stack": [
"logError app/ssr-error-log-ignore-listed/page.js (9:17)", "logError app/ssr-error-log-ignore-listed/page.js (9:17)",
"runWithInternalIgnored app/ssr-error-log-ignore-listed/page.js (19:13)", "runWithInternalIgnored app/ssr-error-log-ignore-listed/page.js (19:13)",
"runInternalIgnored internal-pkg/ignored.ts (6:10)",
"runWithExternalSourceMapped app/ssr-error-log-ignore-listed/page.js (18:29)", "runWithExternalSourceMapped app/ssr-error-log-ignore-listed/page.js (18:29)",
"runWithExternal app/ssr-error-log-ignore-listed/page.js (17:32)", "runWithExternal app/ssr-error-log-ignore-listed/page.js (17:32)",
"runWithInternalSourceMapped app/ssr-error-log-ignore-listed/page.js (16:18)", "runWithInternalSourceMapped app/ssr-error-log-ignore-listed/page.js (16:18)",
......
...@@ -129,6 +129,8 @@ pub struct OriginalToken { ...@@ -129,6 +129,8 @@ pub struct OriginalToken {
pub original_line: u32, pub original_line: u32,
pub original_column: u32, pub original_column: u32,
pub name: Option<RcStr>, pub name: Option<RcStr>,
/// Whether this token's source is in the sourcemap's `ignoreList`.
pub is_ignored: bool,
} }
impl Token { impl Token {
...@@ -159,6 +161,7 @@ impl Token { ...@@ -159,6 +161,7 @@ impl Token {
original_line: t.original_line, original_line: t.original_line,
original_column: t.original_column, original_column: t.original_column,
name: t.name.clone(), name: t.name.clone(),
is_ignored: t.is_ignored,
}), }),
Self::Synthetic(t) => Self::Synthetic(SyntheticToken { Self::Synthetic(t) => Self::Synthetic(SyntheticToken {
generated_line: t.generated_line + line_offset, generated_line: t.generated_line + line_offset,
...@@ -187,6 +190,10 @@ impl From<swc_sourcemap::Token<'_>> for Token { ...@@ -187,6 +190,10 @@ impl From<swc_sourcemap::Token<'_>> for Token {
original_line: t.get_src_line(), original_line: t.get_src_line(),
original_column: t.get_src_col(), original_column: t.get_src_col(),
name: t.get_name().cloned().map(RcStr::from), name: t.get_name().cloned().map(RcStr::from),
// Set to false initially; will be updated by
// lookup_token_and_source_internal which has access to the full
// source map's ignoreList.
is_ignored: false,
}) })
} else { } else {
Token::Synthetic(SyntheticToken { Token::Synthetic(SyntheticToken {
...@@ -546,22 +553,32 @@ impl SourceMap { ...@@ -546,22 +553,32 @@ impl SourceMap {
*guessed_original_file = Some(RcStr::from(source)); *guessed_original_file = Some(RcStr::from(source));
} }
if need_source_content // Check ignoreList and resolve source content using the regular
&& content.is_none() // (possibly flattened) source map. For Index maps,
&& let Some(map) = map.as_regular_source_map() // SourceMapIndex::flatten() correctly transfers ignoreList entries
{ // from each section into the flattened map.
content = tok.and_then(|tok| { if let Some(flat_map) = map.as_regular_source_map() {
let src_id = tok.get_src_id(); if let Token::Original(ref mut orig) = token
&& let Some(source_name) = tok.and_then(|t| t.get_source().cloned())
let name = map.get_source(src_id); && let Some(idx) = flat_map.sources().position(|s| *s == *source_name)
let content = map.get_source_contents(src_id); {
orig.is_ignored = flat_map.ignore_list().any(|id| *id == idx as u32);
let (name, content) = name.zip(content)?; }
Some(sourcemap_content_source(
name.clone().into(), if need_source_content && content.is_none() {
content.clone().into(), content = tok.and_then(|tok| {
)) let src_id = tok.get_src_id();
});
let name = flat_map.get_source(src_id);
let content = flat_map.get_source_contents(src_id);
let (name, content) = name.zip(content)?;
Some(sourcemap_content_source(
name.clone().into(),
content.clone().into(),
))
});
}
} }
token token
......
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