Skip to content

Commit

Permalink
fix(@angular/build): print Sass @warn location
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
alan-agius4 committed May 28, 2024
1 parent acbffd2 commit c4cf359
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import type { OnLoadResult, PartialMessage, ResolveResult } from 'esbuild';
import type { OnLoadResult, PartialMessage, PartialNote, ResolveResult } from 'esbuild';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { CanonicalizeContext, CompileResult, Exception, Syntax } from 'sass';
Expand Down Expand Up @@ -140,7 +140,15 @@ async function compileString(
},
],
logger: {
warn: (text, { deprecation, span }) => {
warn: (text, { deprecation, stack, span }) => {
const notes: PartialNote[] = [];
if (deprecation) {
notes.push({ text });
}
if (stack && !span) {
notes.push({ text: stack });
}

warnings.push({
text: deprecation ? 'Deprecation' : text,
location: span && {
Expand All @@ -150,7 +158,7 @@ async function compileString(
line: span.start.line + 1,
column: span.start.column,
},
notes: deprecation ? [{ text }] : undefined,
notes,
});
},
},
Expand Down

0 comments on commit c4cf359

Please sign in to comment.