Skip to content

Commit

Permalink
Use optional chaining to catch null error codes in error.js (#1054)
Browse files Browse the repository at this point in the history
* Use optional chaining to catch null error codes in error.js

Starting a new vite project and selecting svelte-ts template results in an error, because `code` var in error.js is null. Optional chaining resolves this issue.

* chore: add changeset

---------

Co-authored-by: dominikg <[email protected]>
  • Loading branch information
trbernstein and dominikg authored Dec 18, 2024
1 parent d215c88 commit 47184d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/giant-plants-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

fix errorhandling to work with errors that don't have a code property
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/utils/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function formatFrameForVite(frame) {
* @returns {boolean}
*/
function couldBeFixedByCssPreprocessor(code) {
return code === 'expected_token' || code === 'unexpected_eof' || code.startsWith('css_');
return code === 'expected_token' || code === 'unexpected_eof' || code?.startsWith('css_');
}

/**
Expand Down

0 comments on commit 47184d4

Please sign in to comment.