diff --git a/.changeset/brave-fans-sneeze.md b/.changeset/brave-fans-sneeze.md new file mode 100644 index 0000000000..c5fe894acb --- /dev/null +++ b/.changeset/brave-fans-sneeze.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: add empty stack to `CompileDiagnostic` to show error on build diff --git a/packages/svelte/src/compiler/utils/compile_diagnostic.js b/packages/svelte/src/compiler/utils/compile_diagnostic.js index a27e06968f..374a20b8b5 100644 --- a/packages/svelte/src/compiler/utils/compile_diagnostic.js +++ b/packages/svelte/src/compiler/utils/compile_diagnostic.js @@ -39,6 +39,7 @@ function get_code_frame(source, line, column) { * @typedef {{ * code: string; * message: string; + * stack?: string; * filename?: string; * start?: Location; * end?: Location; @@ -50,6 +51,8 @@ function get_code_frame(source, line, column) { /** @implements {ICompileDiagnostic} */ export class CompileDiagnostic { name = 'CompileDiagnostic'; + // adding an empty stack so that vite will show the file and frame during build + stack = ''; /** * @param {string} code diff --git a/packages/svelte/tests/migrate/samples/impossible-migrate-with-errors/_config.js b/packages/svelte/tests/migrate/samples/impossible-migrate-with-errors/_config.js index 6d25bb63b1..57496dcba7 100644 --- a/packages/svelte/tests/migrate/samples/impossible-migrate-with-errors/_config.js +++ b/packages/svelte/tests/migrate/samples/impossible-migrate-with-errors/_config.js @@ -20,6 +20,7 @@ export default test({ ^`, message: 'Unexpected end of input', name: 'CompileError', + stack: '', position: [30, 30], start: { character: 30, diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 4e57607efc..c7794d5b0e 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1458,6 +1458,7 @@ declare module 'svelte/compiler' { type ICompileDiagnostic = { code: string; message: string; + stack?: string; filename?: string; start?: Location; end?: Location; @@ -2286,6 +2287,7 @@ declare module 'svelte/types/compiler/interfaces' { type ICompileDiagnostic = { code: string; message: string; + stack?: string; filename?: string; start?: Location; end?: Location;