Skip to content

Commit c4cf359

Browse files
committedMay 28, 2024·
fix(@angular/build): print Sass @warn location
When using the `@warn` directive, the `span` entry in the warning object is often undefined. Instead, the `stack` property is populated. ```js { "warnings": [ { "deprecation": false, "deprecationType": null, "span": undefined, "stack": "projects/foo/src/app/app.component.scss 1:1 root stylesheet\n", "message": "some message" } ] } ``` ### Before ``` ▲ [WARNING] some message [plugin angular-sass] ``` ### Now ``` ▲ [WARNING] some message [plugin angular-sass] projects/foo/src/app/app.component.scss 1:1 root stylesheet ``` Closes: #27726 (cherry picked from commit 4a879a9)
1 parent acbffd2 commit c4cf359

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import type { OnLoadResult, PartialMessage, ResolveResult } from 'esbuild';
9+
import type { OnLoadResult, PartialMessage, PartialNote, ResolveResult } from 'esbuild';
1010
import { dirname, join, relative } from 'node:path';
1111
import { fileURLToPath, pathToFileURL } from 'node:url';
1212
import type { CanonicalizeContext, CompileResult, Exception, Syntax } from 'sass';
@@ -140,7 +140,15 @@ async function compileString(
140140
},
141141
],
142142
logger: {
143-
warn: (text, { deprecation, span }) => {
143+
warn: (text, { deprecation, stack, span }) => {
144+
const notes: PartialNote[] = [];
145+
if (deprecation) {
146+
notes.push({ text });
147+
}
148+
if (stack && !span) {
149+
notes.push({ text: stack });
150+
}
151+
144152
warnings.push({
145153
text: deprecation ? 'Deprecation' : text,
146154
location: span && {
@@ -150,7 +158,7 @@ async function compileString(
150158
line: span.start.line + 1,
151159
column: span.start.column,
152160
},
153-
notes: deprecation ? [{ text }] : undefined,
161+
notes,
154162
});
155163
},
156164
},

0 commit comments

Comments
 (0)
Please sign in to comment.