Skip to content

Commit e41edff

Browse files
authored
fix: update warning codes for svelte5 (#1044)
* fix: update warning codes for svelte5 * fix(audit): bump nanoid * fix: replace css error code detection so that it works for svelte5 * chore: update changeset
1 parent 1b302f1 commit e41edff

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

Diff for: .changeset/eleven-pears-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
adapt internal handling of warning and error `code` property to changes in svelte5

Diff for: packages/e2e-tests/import-queries/svelte.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
preprocess: [vitePreprocess()],
55
onwarn(warning, defaultHandler) {
66
// import query test generates one of these
7-
if (warning.code === 'custom-element-no-tag') return;
7+
if (warning.code === 'options_missing_custom_element') return;
88
defaultHandler(warning);
99
}
1010
};

Diff for: packages/vite-plugin-svelte/src/utils/error.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ function formatFrameForVite(frame) {
101101
.join('\n');
102102
}
103103

104+
/**
105+
*
106+
* @param {string} code the svelte error code
107+
* @see https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/compiler/errors.js
108+
* @returns {boolean}
109+
*/
110+
function couldBeFixedByCssPreprocessor(code) {
111+
return code === 'expected_token' || code === 'unexpected_eof' || code.startsWith('css_');
112+
}
113+
104114
/**
105115
* @param {import('svelte/compiler').Warning & Error} err a svelte compiler error, which is a mix of Warning and an error
106116
* @param {string} originalCode
@@ -113,7 +123,7 @@ export function enhanceCompileError(err, originalCode, preprocessors) {
113123
const additionalMessages = [];
114124

115125
// Handle incorrect CSS preprocessor usage
116-
if (err.code === 'css-syntax-error') {
126+
if (couldBeFixedByCssPreprocessor(err.code)) {
117127
// Reference from Svelte: https://github.com/sveltejs/svelte/blob/9926347ad9dbdd0f3324d5538e25dcb7f5e442f8/packages/svelte/src/compiler/preprocess/index.js#L257
118128
const styleRe =
119129
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;

Diff for: packages/vite-plugin-svelte/src/utils/log.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function logCompilerWarnings(svelteRequest, warnings, options) {
182182
*/
183183
function ignoreCompilerWarning(warning, isBuild, emitCss) {
184184
return (
185-
(!emitCss && warning.code === 'css-unused-selector') || // same as rollup-plugin-svelte
185+
(!emitCss && warning.code === 'css_unused_selector') || // same as rollup-plugin-svelte
186186
(!isBuild && isNoScopableElementWarning(warning))
187187
);
188188
}
@@ -194,7 +194,7 @@ function ignoreCompilerWarning(warning, isBuild, emitCss) {
194194
*/
195195
function isNoScopableElementWarning(warning) {
196196
// see https://github.com/sveltejs/vite-plugin-svelte/issues/153
197-
return warning.code === 'css-unused-selector' && warning.message.includes('"*"');
197+
return warning.code === 'css_unused_selector' && warning.message.includes('"*"');
198198
}
199199

200200
/**

Diff for: pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)