Unverified Commit 30ce5d4b authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

feat(turbopack): Use source map while reporting CSS parsing error (#68648)

### What?

Improve error messages about invalid CSS files.

### Why?

Currently, `sass-loader` compiles CSS as a single line, and as the issue
emitter prints the whole line, the error message is not good.

### How?

Closes PACK-3187
Fixes #68311

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent a5bd4709
...@@ -219,7 +219,7 @@ impl Issue for NextSegmentConfigParsingIssue { ...@@ -219,7 +219,7 @@ impl Issue for NextSegmentConfigParsingIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn source(&self) -> Vc<OptionIssueSource> { fn source(&self) -> Vc<OptionIssueSource> {
Vc::cell(Some(self.source)) Vc::cell(Some(self.source.resolve_source_map(self.ident.path())))
} }
} }
......
...@@ -50,7 +50,7 @@ pub async fn maybe_add_sass_loader( ...@@ -50,7 +50,7 @@ pub async fn maybe_add_sass_loader(
options: take( options: take(
serde_json::json!({ serde_json::json!({
//https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191 //https://github.com/vercel/turbo/blob/d527eb54be384a4658243304cecd547d09c05c6b/crates/turbopack-node/src/transforms/webpack.rs#L191
"sourceMap": false "sourceMap": true
}) })
.as_object_mut() .as_object_mut()
.unwrap(), .unwrap(),
......
:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}
@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}
body {
font-family: monospace;
color: white;
background-color: #0e0f0f;
@media (max-width: 1200px) {
font-size: 16px;
}
@media (max-width: 992px) {
font-size: 14px;
}
}
input.defaultCheckbox {
color: white;
}
input.defaultCheckbox::before {
content: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6.66662 10.115L12.7946 3.98633L13.7379 4.92899L6.66662 12.0003L2.42395 7.75766L3.36662 6.81499L6.66662 10.115Z' fill='white'/%3E%3C/svg%3E%0A");
fill: currentColor;
opacity: 0;
height: 16px;
width: 16px;
top: -2px;
position: absolute;
left: 50%;
transform: translate(-50%, 0px);
}
input.defaultCheckbox::before path {
fill: currentColor;
}
input:checked.defaultCheckbox::before {
opacity: 1;
}
.slide {
animation: slide_anim 0.5s;
}
@keyframes slide_anim {
from {
transform: translateX(50px);
opacity: 0.4;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.animation-opacity {
animation: opacity_anim 0.5s;
}
@keyframes opacity_anim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
'use client'
import './global.scss'
export default function Layout({ children }) {
return <>{children}</>
}
'use client'
export default function Page() {
return (
<>
<div></div>
</>
)
}
import { nextTestSetup } from 'e2e-utils'
import { getRedboxSource } from 'next-test-utils'
describe('app dir - css', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: {
sass: 'latest',
},
})
if (skipped) {
return
}
describe('sass support', () => {
;(process.env.TURBOPACK ? describe : describe.skip)(
'error handling',
() => {
it('should use original source points for sass errors', async () => {
const browser = await next.browser('/sass-error')
const source = await getRedboxSource(browser)
// css-loader does not report an error for this case
expect(source).toMatchInlineSnapshot(`
"./app/global.scss.css:45:1
Parsing css source code failed
43 | }
44 |
> 45 | input.defaultCheckbox::before path {
| ^
46 | fill: currentColor;
47 | }
48 |
Pseudo-elements like '::before' or '::after' can't be followed by selectors like 'Ident("path")' at [project]/app/global.scss.css:0:884"
`)
})
}
)
})
})
...@@ -57,6 +57,9 @@ impl Issue for AnalyzeIssue { ...@@ -57,6 +57,9 @@ impl Issue for AnalyzeIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn source(&self) -> Vc<OptionIssueSource> { fn source(&self) -> Vc<OptionIssueSource> {
Vc::cell(self.source) Vc::cell(
self.source
.map(|s| s.resolve_source_map(self.source_ident.path())),
)
} }
} }
...@@ -21,6 +21,7 @@ use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher}; ...@@ -21,6 +21,7 @@ use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher};
use crate::{ use crate::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
source::Source, source::Source,
source_map::{convert_to_turbopack_source_map, GenerateSourceMap, TokenWithSource},
source_pos::SourcePos, source_pos::SourcePos,
}; };
...@@ -159,6 +160,7 @@ pub trait Issue { ...@@ -159,6 +160,7 @@ pub trait Issue {
Some(detail) => Some((*detail.await?).clone()), Some(detail) => Some((*detail.await?).clone()),
None => None, None => None,
}; };
Ok(PlainIssue { Ok(PlainIssue {
severity: *self.severity().await?, severity: *self.severity().await?,
file_path: self.file_path().to_string().await?.clone_value(), file_path: self.file_path().to_string().await?.clone_value(),
...@@ -463,6 +465,42 @@ impl IssueSource { ...@@ -463,6 +465,42 @@ impl IssueSource {
}) })
} }
#[turbo_tasks::function]
pub async fn resolve_source_map(
self: Vc<Self>,
origin: Vc<FileSystemPath>,
) -> Result<Vc<Self>> {
let this = self.await?;
if let Some(range) = this.range {
let (start, end) = match &*range.await? {
SourceRange::LineColumn(start, end) => (*start, *end),
SourceRange::ByteOffset(start, end) => {
if let FileLinesContent::Lines(lines) = &*this.source.content().lines().await? {
let start = find_line_and_column(lines.as_ref(), *start);
let end = find_line_and_column(lines.as_ref(), *end);
(start, end)
} else {
return Ok(self);
}
}
};
// If we have a source map, map the line/column to the original source.
let mapped = source_pos(this.source, origin, start, end).await?;
if let Some((source, start, end)) = mapped {
return Ok(Self::cell(IssueSource {
source,
range: Some(SourceRange::LineColumn(start, end).cell()),
}));
}
}
Ok(self)
}
/// Create a [`IssueSource`] from byte offsets given by an swc ast node /// Create a [`IssueSource`] from byte offsets given by an swc ast node
/// span. /// span.
/// ///
...@@ -518,6 +556,63 @@ impl IssueSource { ...@@ -518,6 +556,63 @@ impl IssueSource {
} }
} }
async fn source_pos(
source: Vc<Box<dyn Source>>,
origin: Vc<FileSystemPath>,
start: SourcePos,
end: SourcePos,
) -> Result<Option<(Vc<Box<dyn Source>>, SourcePos, SourcePos)>> {
let Some(generator) = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(source).await?
else {
return Ok(None);
};
let srcmap = generator.generate_source_map();
let Some(srcmap) = *convert_to_turbopack_source_map(srcmap, origin).await? else {
return Ok(None);
};
let find = |line: usize, col: usize| async move {
let TokenWithSource {
token,
source_content,
} = &*srcmap.lookup_token_and_source(line, col).await?;
match &*token.await? {
crate::source_map::Token::Synthetic(t) => Ok::<_, anyhow::Error>((
SourcePos {
line: t.generated_line as _,
column: t.generated_column as _,
},
*source_content,
)),
crate::source_map::Token::Original(t) => Ok((
SourcePos {
line: t.original_line as _,
column: t.original_column as _,
},
*source_content,
)),
}
};
let (start, content_1) = find(start.line, start.column).await?;
let (end, content_2) = find(end.line, end.column).await?;
let Some((content_1, content_2)) = content_1.zip(content_2) else {
return Ok(None);
};
let (content_1, content_2) = (content_1.resolve().await?, content_2.resolve().await?);
if content_1 != content_2 {
return Ok(None);
}
Ok(Some((content_1, start, end)))
}
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OptionIssueSource(Option<Vc<IssueSource>>); pub struct OptionIssueSource(Option<Vc<IssueSource>>);
......
...@@ -119,7 +119,7 @@ impl Issue for ResolvingIssue { ...@@ -119,7 +119,7 @@ impl Issue for ResolvingIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn source(&self) -> Vc<OptionIssueSource> { fn source(&self) -> Vc<OptionIssueSource> {
Vc::cell(self.source) Vc::cell(self.source.map(|s| s.resolve_source_map(self.file_path)))
} }
// TODO add sub_issue for a description of resolve_options // TODO add sub_issue for a description of resolve_options
......
...@@ -10,10 +10,13 @@ use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMap ...@@ -10,10 +10,13 @@ use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMap
use turbo_tasks::{RcStr, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{RcStr, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
rope::{Rope, RopeBuilder}, rope::{Rope, RopeBuilder},
FileContent, FileSystemPath, File, FileContent, FileSystem, FileSystemPath, VirtualFileSystem,
}; };
use crate::{source_pos::SourcePos, SOURCE_MAP_PREFIX}; use crate::{
asset::AssetContent, source::Source, source_pos::SourcePos, virtual_source::VirtualSource,
SOURCE_MAP_PREFIX,
};
pub(crate) mod source_map_asset; pub(crate) mod source_map_asset;
...@@ -80,6 +83,13 @@ pub enum Token { ...@@ -80,6 +83,13 @@ pub enum Token {
Original(OriginalToken), Original(OriginalToken),
} }
#[turbo_tasks::value]
#[derive(Clone, Debug)]
pub struct TokenWithSource {
pub token: Vc<Token>,
pub source_content: Option<Vc<Box<dyn Source>>>,
}
/// A SyntheticToken represents a region of the generated file that was created /// A SyntheticToken represents a region of the generated file that was created
/// by some build tool. /// by some build tool.
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -313,77 +323,31 @@ impl SourceMap { ...@@ -313,77 +323,31 @@ impl SourceMap {
/// synthetic code or user-authored original code. /// synthetic code or user-authored original code.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn lookup_token(self: Vc<Self>, line: usize, column: usize) -> Result<Vc<Token>> { pub async fn lookup_token(self: Vc<Self>, line: usize, column: usize) -> Result<Vc<Token>> {
let token = match &*self.await? { let (token, _) = self
SourceMap::Decoded(map) => { .await?
let mut token = map .lookup_token_and_source_internal(line, column, true)
.lookup_token(line as u32, column as u32) .await?;
.map(Token::from) Ok(token)
.unwrap_or_else(|| {
Token::Synthetic(SyntheticToken {
generated_line: line,
generated_column: column,
guessed_original_file: None,
})
});
if let Token::Synthetic(SyntheticToken {
guessed_original_file,
..
}) = &mut token
{
if let DecodedMap::Regular(map) = &map.map.0 {
if map.get_source_count() == 1 {
let source = map.sources().next().unwrap();
*guessed_original_file = Some(source.to_string());
}
}
}
token
}
SourceMap::Sectioned(map) => {
let len = map.sections.len();
let mut low = 0;
let mut high = len;
let pos = SourcePos { line, column };
// A "greatest lower bound" binary search. We're looking for the closest section
// offset <= to our line/col.
while low < high {
let mid = (low + high) / 2;
if pos < map.sections[mid].offset {
high = mid;
} else {
low = mid + 1;
}
}
// Our GLB search will return the section immediately to the right of the
// section we actually want to recurse into, because the binary search does not
// early exit on an exact match (it'll `low = mid + 1`).
if low > 0 && low <= len {
let SourceMapSection { map, offset } = &map.sections[low - 1];
// We're looking for the position `l` lines into region covered by this
// sourcemap's section.
let l = line - offset.line;
// The source map starts offset by the section's column only on its first line.
// On the 2nd+ line, the source map covers starting at column 0.
let c = if line == offset.line {
column - offset.column
} else {
column
};
return Ok(map.lookup_token(l, c));
}
Token::Synthetic(SyntheticToken {
generated_line: line,
generated_column: column,
guessed_original_file: None,
})
}
};
Ok(token.cell())
} }
/// Traces a generated line/column into an mapping token representing either
/// synthetic code or user-authored original code.
#[turbo_tasks::function]
pub async fn lookup_token_and_source(
self: Vc<Self>,
line: usize,
column: usize,
) -> Result<Vc<TokenWithSource>> {
let (token, content) = self
.await?
.lookup_token_and_source_internal(line, column, true)
.await?;
Ok(TokenWithSource {
token,
source_content: content,
}
.cell())
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn with_resolved_sources( pub async fn with_resolved_sources(
self: Vc<Self>, self: Vc<Self>,
...@@ -523,6 +487,113 @@ impl SourceMap { ...@@ -523,6 +487,113 @@ impl SourceMap {
} }
} }
impl SourceMap {
async fn lookup_token_and_source_internal(
&self,
line: usize,
column: usize,
need_source_content: bool,
) -> Result<(Vc<Token>, Option<Vc<Box<dyn Source>>>)> {
let mut content: Option<Vc<Box<dyn Source>>> = None;
let token: Token = match self {
SourceMap::Decoded(map) => {
let tok = map.lookup_token(line as u32, column as u32);
let mut token = tok.map(Token::from).unwrap_or_else(|| {
Token::Synthetic(SyntheticToken {
generated_line: line,
generated_column: column,
guessed_original_file: None,
})
});
if let Token::Synthetic(SyntheticToken {
guessed_original_file,
..
}) = &mut token
{
if let DecodedMap::Regular(map) = &map.map.0 {
if map.get_source_count() == 1 {
let source = map.sources().next().unwrap();
*guessed_original_file = Some(source.to_string());
}
}
}
if need_source_content && content.is_none() {
if let Some(map) = map.map.as_regular_source_map() {
content = tok.and_then(|tok| {
let src_id = tok.get_src_id();
let name = map.get_source(src_id);
let content = map.get_source_contents(src_id);
let (name, content) = name.zip(content)?;
let path = VirtualFileSystem::new().root().join(name.into());
let content =
AssetContent::file(FileContent::new(File::from(content)).cell());
Some(Vc::upcast(VirtualSource::new(path, content)))
});
}
}
token
}
SourceMap::Sectioned(map) => {
let len = map.sections.len();
let mut low = 0;
let mut high = len;
let pos = SourcePos { line, column };
// A "greatest lower bound" binary search. We're looking for the closest section
// offset <= to our line/col.
while low < high {
let mid = (low + high) / 2;
if pos < map.sections[mid].offset {
high = mid;
} else {
low = mid + 1;
}
}
// Our GLB search will return the section immediately to the right of the
// section we actually want to recurse into, because the binary search does not
// early exit on an exact match (it'll `low = mid + 1`).
if low > 0 && low <= len {
let SourceMapSection { map, offset } = &map.sections[low - 1];
// We're looking for the position `l` lines into region covered by this
// sourcemap's section.
let l = line - offset.line;
// The source map starts offset by the section's column only on its first line.
// On the 2nd+ line, the source map covers starting at column 0.
let c = if line == offset.line {
column - offset.column
} else {
column
};
if need_source_content {
let result = map.lookup_token_and_source(l, c).await?;
return Ok((result.token, result.source_content));
} else {
return Ok((map.lookup_token(l, c), None));
}
}
Token::Synthetic(SyntheticToken {
generated_line: line,
generated_column: column,
guessed_original_file: None,
})
}
};
Ok((token.cell(), content))
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl GenerateSourceMap for SourceMap { impl GenerateSourceMap for SourceMap {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -682,3 +753,14 @@ impl SourceMapSection { ...@@ -682,3 +753,14 @@ impl SourceMapSection {
}) })
} }
} }
#[turbo_tasks::function]
pub async fn convert_to_turbopack_source_map(
source_map: Vc<OptionSourceMap>,
origin: Vc<FileSystemPath>,
) -> Result<Vc<OptionSourceMap>> {
let Some(source_map) = *source_map.await? else {
return Ok(Vc::cell(None));
};
Ok(Vc::cell(Some(source_map.with_resolved_sources(origin))))
}
...@@ -574,6 +574,7 @@ async fn process_content( ...@@ -574,6 +574,7 @@ async fn process_content(
match err.kind { match err.kind {
lightningcss::error::ParserError::UnexpectedToken(_) lightningcss::error::ParserError::UnexpectedToken(_)
| lightningcss::error::ParserError::UnexpectedImportRule | lightningcss::error::ParserError::UnexpectedImportRule
| lightningcss::error::ParserError::SelectorError(..)
| lightningcss::error::ParserError::EndOfInput => { | lightningcss::error::ParserError::EndOfInput => {
let source = err.loc.as_ref().map(|loc| { let source = err.loc.as_ref().map(|loc| {
let pos = SourcePos { let pos = SourcePos {
...@@ -586,7 +587,7 @@ async fn process_content( ...@@ -586,7 +587,7 @@ async fn process_content(
ParsingIssue { ParsingIssue {
file: fs_path_vc, file: fs_path_vc,
msg: Vc::cell(err.to_string().into()), msg: Vc::cell(err.to_string().into()),
source: Vc::cell(source), source,
} }
.cell() .cell()
.emit(); .emit();
...@@ -609,11 +610,10 @@ async fn process_content( ...@@ -609,11 +610,10 @@ async fn process_content(
}; };
IssueSource::from_line_col(source, pos, pos) IssueSource::from_line_col(source, pos, pos)
}); });
ParsingIssue { ParsingIssue {
file: fs_path_vc, file: fs_path_vc,
msg: Vc::cell(e.to_string().into()), msg: Vc::cell(e.to_string().into()),
source: Vc::cell(source), source,
} }
.cell() .cell()
.emit(); .emit();
...@@ -738,11 +738,11 @@ impl CssError { ...@@ -738,11 +738,11 @@ impl CssError {
ParsingIssue { ParsingIssue {
file, file,
msg: Vc::cell(CSS_MODULE_ERROR.into()), msg: Vc::cell(CSS_MODULE_ERROR.into()),
source: Vc::cell(Some(IssueSource::from_swc_offsets( source: Some(IssueSource::from_swc_offsets(
source, source,
span.lo.0 as _, span.lo.0 as _,
span.hi.0 as _, span.hi.0 as _,
))), )),
} }
.cell() .cell()
.emit(); .emit();
...@@ -751,7 +751,7 @@ impl CssError { ...@@ -751,7 +751,7 @@ impl CssError {
ParsingIssue { ParsingIssue {
file, file,
msg: Vc::cell(format!("{CSS_MODULE_ERROR}, (lightningcss, {selector})").into()), msg: Vc::cell(format!("{CSS_MODULE_ERROR}, (lightningcss, {selector})").into()),
source: Vc::cell(None), source: None,
} }
.cell() .cell()
.emit(); .emit();
...@@ -1073,7 +1073,7 @@ impl TransformConfig for ModuleTransformConfig { ...@@ -1073,7 +1073,7 @@ impl TransformConfig for ModuleTransformConfig {
struct ParsingIssue { struct ParsingIssue {
msg: Vc<RcStr>, msg: Vc<RcStr>,
file: Vc<FileSystemPath>, file: Vc<FileSystemPath>,
source: Vc<OptionIssueSource>, source: Option<Vc<IssueSource>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -1095,7 +1095,7 @@ impl Issue for ParsingIssue { ...@@ -1095,7 +1095,7 @@ impl Issue for ParsingIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn source(&self) -> Vc<OptionIssueSource> { fn source(&self) -> Vc<OptionIssueSource> {
self.source Vc::cell(self.source.map(|s| s.resolve_source_map(self.file)))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -71,7 +71,7 @@ use turbopack_core::{ ...@@ -71,7 +71,7 @@ use turbopack_core::{
resolve, FindContextFileResult, ModulePart, resolve, FindContextFileResult, ModulePart,
}, },
source::Source, source::Source,
source_map::{GenerateSourceMap, OptionSourceMap, SourceMap}, source_map::{convert_to_turbopack_source_map, GenerateSourceMap, OptionSourceMap, SourceMap},
}; };
use turbopack_resolve::{ use turbopack_resolve::{
ecmascript::{apply_cjs_specific_options, cjs_resolve_source}, ecmascript::{apply_cjs_specific_options, cjs_resolve_source},
...@@ -3203,14 +3203,3 @@ fn maybe_decode_data_url(url: RcStr) -> Vc<OptionSourceMap> { ...@@ -3203,14 +3203,3 @@ fn maybe_decode_data_url(url: RcStr) -> Vc<OptionSourceMap> {
Vc::cell(None) Vc::cell(None)
} }
} }
#[turbo_tasks::function]
async fn convert_to_turbopack_source_map(
source_map: Vc<OptionSourceMap>,
origin: Vc<FileSystemPath>,
) -> Result<Vc<OptionSourceMap>> {
let Some(source_map) = *source_map.await? else {
return Ok(Vc::cell(None));
};
Ok(Vc::cell(Some(source_map.with_resolved_sources(origin))))
}
...@@ -187,7 +187,7 @@ impl MdxTransformedAsset { ...@@ -187,7 +187,7 @@ impl MdxTransformedAsset {
} }
.cell()), .cell()),
Err(err) => { Err(err) => {
let loc = Vc::cell(err.place.map(|p| { let loc = err.place.map(|p| {
let (start, end) = match *p { let (start, end) = match *p {
// markdown's positions are 1-indexed, SourcePos is 0-indexed. // markdown's positions are 1-indexed, SourcePos is 0-indexed.
// Both end positions point to the first character after the range // Both end positions point to the first character after the range
...@@ -211,7 +211,7 @@ impl MdxTransformedAsset { ...@@ -211,7 +211,7 @@ impl MdxTransformedAsset {
}; };
IssueSource::from_line_col(this.source, start, end) IssueSource::from_line_col(this.source, start, end)
})); });
MdxIssue { MdxIssue {
path: this.source.ident().path(), path: this.source.ident().path(),
...@@ -241,7 +241,7 @@ struct MdxTransformResult { ...@@ -241,7 +241,7 @@ struct MdxTransformResult {
struct MdxIssue { struct MdxIssue {
/// Place of message. /// Place of message.
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
loc: Vc<OptionIssueSource>, loc: Option<Vc<IssueSource>>,
/// Reason for message (should use markdown). /// Reason for message (should use markdown).
reason: String, reason: String,
/// Category of message. /// Category of message.
...@@ -259,7 +259,7 @@ impl Issue for MdxIssue { ...@@ -259,7 +259,7 @@ impl Issue for MdxIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
fn source(&self) -> Vc<OptionIssueSource> { fn source(&self) -> Vc<OptionIssueSource> {
self.loc Vc::cell(self.loc.map(|s| s.resolve_source_map(self.path)))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -21,6 +21,7 @@ use turbopack_core::{ ...@@ -21,6 +21,7 @@ use turbopack_core::{
reference_type::{EntryReferenceSubType, InnerAssets, ReferenceType}, reference_type::{EntryReferenceSubType, InnerAssets, ReferenceType},
resolve::{find_context_file_or_package_key, options::ImportMapping, FindContextFileResult}, resolve::{find_context_file_or_package_key, options::ImportMapping, FindContextFileResult},
source::Source, source::Source,
source_map::{GenerateSourceMap, OptionSourceMap},
source_transform::SourceTransform, source_transform::SourceTransform,
virtual_source::VirtualSource, virtual_source::VirtualSource,
}; };
...@@ -408,6 +409,18 @@ async fn find_config_in_location( ...@@ -408,6 +409,18 @@ async fn find_config_in_location(
Ok(None) Ok(None)
} }
#[turbo_tasks::value_impl]
impl GenerateSourceMap for PostCssTransformedAsset {
#[turbo_tasks::function]
async fn generate_source_map(&self) -> Result<Vc<OptionSourceMap>> {
let source = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(self.source).await?;
match source {
Some(source) => Ok(source.generate_source_map()),
None => Ok(Vc::cell(None)),
}
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl PostCssTransformedAsset { impl PostCssTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
......
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