Skip to content

Commit 049a7a1

Browse files
committed
fixup! fix(@angular/build): attach location to Sass errors and guard stack parsing
1 parent 5322da7 commit 049a7a1

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

‎packages/angular/build/src/tools/esbuild/stylesheets/sass-language.ts‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ async function compileString(
248248
};
249249
} catch (error) {
250250
if (isSassException(error)) {
251-
const location = error.span && spanToLocation(error.span);
251+
const location = spanToLocation(error.span);
252252
const watchFiles = [filePath, ...extractFilesFromStack(error.sassStack)];
253-
if (location?.file) {
253+
if (location.file) {
254254
watchFiles.push(location.file);
255255
}
256256

@@ -291,24 +291,12 @@ function* extractFilesFromStack(stack: string): Iterable<string> {
291291
const lines = stack.split('\n');
292292
const cwd = process.cwd();
293293

294-
// Stack line has format of "<file> <location> <identifier>"
294+
// Stack line has format of `<file> <line>:<column> <identifier>`
295295
for (const line of lines) {
296-
const segments = line.split(' ');
297-
if (segments.length < 3) {
298-
break;
299-
}
300-
301-
// Extract path from stack line.
302-
// Paths may contain spaces. All segments before location are part of the file path.
303-
let path = '';
304-
let index = 0;
305-
while (index < segments.length && !segments[index].match(/\d+:\d+/)) {
306-
path += (path ? ' ' : '') + segments[index++];
307-
}
308-
309-
if (path && index < segments.length) {
296+
const match = line.trim().match(/^(.+?)\s+\d+:\d+/);
297+
if (match) {
310298
// Stack paths from sass are relative to the current working directory (not input file or workspace root)
311-
yield join(cwd, path);
299+
yield join(cwd, match[1]);
312300
}
313301
}
314302
}

0 commit comments

Comments
 (0)