Skip to content

Commit d5081c2

Browse files
authored
fix(css): avoid mutating sass error multiple times (#22115)
1 parent dbc180d commit d5081c2

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

  • packages/vite/src/node/plugins

packages/vite/src/node/plugins/css.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,7 @@ const scssProcessor = (
26092609
): StylePreprocessor<SassStylePreprocessorInternalOptions> => {
26102610
let worker: ReturnType<typeof makeScssWorker> | undefined
26112611
let failedSassEmbedded: boolean | undefined
2612+
const normalizedErrors = new WeakSet<Error>()
26122613

26132614
return {
26142615
close() {
@@ -2668,19 +2669,24 @@ const scssProcessor = (
26682669
deps,
26692670
}
26702671
} catch (e) {
2671-
// normalize SASS error
2672-
e.message = `[sass] ${e.message}`
2673-
e.id = e.file
2674-
e.frame = e.formatted
2675-
// modern api lacks `line` and `column` property. extract from `e.span`.
2676-
// NOTE: the values are 0-based so +1 is required.
2677-
if (e.span?.start) {
2678-
e.line = e.span.start.line + 1
2679-
e.column = e.span.start.column + 1
2680-
// it also lacks `e.formatted`, so we shim with the message here since
2681-
// sass error messages have the frame already in them and we don't want
2682-
// to re-generate a new frame (same as legacy api)
2683-
e.frame = e.message
2672+
if (!normalizedErrors.has(e)) {
2673+
// normalize SASS error
2674+
e.message = `[sass] ${e.message}`
2675+
e.id = e.file
2676+
e.frame = e.formatted
2677+
// modern api lacks `line` and `column` property. extract from `e.span`.
2678+
// NOTE: the values are 0-based so +1 is required.
2679+
if (e.span?.start) {
2680+
e.line = e.span.start.line + 1
2681+
e.column = e.span.start.column + 1
2682+
// it also lacks `e.formatted`, so we shim with the message here since
2683+
// sass error messages have the frame already in them and we don't want
2684+
// to re-generate a new frame (same as legacy api)
2685+
e.frame = e.message
2686+
}
2687+
// sass sometimes re-uses the error instance
2688+
// avoid mutating the same instance multiple times
2689+
normalizedErrors.add(e)
26842690
}
26852691
return { code: '', error: e, deps: [] }
26862692
}

0 commit comments

Comments
 (0)