Skip to content

Commit 7be3afb

Browse files
fix: add empty stack to CompileDiagnostic to show error on build (#13942)
* fix: add empty stack to `CompileDiagnostic` to show error on build * chore: generate types * chore: make stack optional to make TS happy * chore: generate types -.-" * chore: add comment
1 parent da1fefc commit 7be3afb

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

.changeset/brave-fans-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: add empty stack to `CompileDiagnostic` to show error on build

packages/svelte/src/compiler/utils/compile_diagnostic.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function get_code_frame(source, line, column) {
3939
* @typedef {{
4040
* code: string;
4141
* message: string;
42+
* stack?: string;
4243
* filename?: string;
4344
* start?: Location;
4445
* end?: Location;
@@ -50,6 +51,8 @@ function get_code_frame(source, line, column) {
5051
/** @implements {ICompileDiagnostic} */
5152
export class CompileDiagnostic {
5253
name = 'CompileDiagnostic';
54+
// adding an empty stack so that vite will show the file and frame during build
55+
stack = '';
5356

5457
/**
5558
* @param {string} code

packages/svelte/tests/migrate/samples/impossible-migrate-with-errors/_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default test({
2020
^`,
2121
message: 'Unexpected end of input',
2222
name: 'CompileError',
23+
stack: '',
2324
position: [30, 30],
2425
start: {
2526
character: 30,

packages/svelte/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ declare module 'svelte/compiler' {
14581458
type ICompileDiagnostic = {
14591459
code: string;
14601460
message: string;
1461+
stack?: string;
14611462
filename?: string;
14621463
start?: Location;
14631464
end?: Location;
@@ -2286,6 +2287,7 @@ declare module 'svelte/types/compiler/interfaces' {
22862287
type ICompileDiagnostic = {
22872288
code: string;
22882289
message: string;
2290+
stack?: string;
22892291
filename?: string;
22902292
start?: Location;
22912293
end?: Location;

0 commit comments

Comments
 (0)