Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't require commas between warnings in legacy mode #11669

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-beans-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: don't require warning codes to be separated by commas in non-runes mode
47 changes: 32 additions & 15 deletions packages/svelte/src/compiler/utils/extract_svelte_ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export function extract_svelte_ignore(offset, text, runes) {
/** @type {string[]} */
const ignores = [];

// Warnings have to be separated by commas, everything after is interpreted as prose
for (const match of text.slice(length).matchAll(/([\w$-]+)(,)?/gm)) {
const code = match[1];
if (runes) {
// Warnings have to be separated by commas, everything after is interpreted as prose
for (const match of text.slice(length).matchAll(/([\w$-]+)(,)?/gm)) {
const code = match[1];

ignores.push(code);
if (w.codes.includes(code)) {
ignores.push(code);
} else {
const replacement = replacements[code] ?? code.replace(/-/g, '_');

if (!w.codes.includes(code)) {
const replacement = replacements[code] ?? code.replace(/-/g, '_');

if (runes) {
// The type cast is for some reason necessary to pass the type check in CI
const start = offset + /** @type {number} */ (match.index);
const end = start + code.length;
Expand All @@ -51,13 +51,26 @@ export function extract_svelte_ignore(offset, text, runes) {
const suggestion = fuzzymatch(code, w.codes);
w.unknown_code({ start, end }, code, suggestion);
}
} else if (w.codes.includes(replacement)) {
ignores.push(replacement);
}

if (!match[2]) {
break;
}
}
} else {
// Non-runes mode: lax parsing, backwards compat with old codes
for (const match of text.slice(length).matchAll(/[\w$-]+/gm)) {
const code = match[0];

ignores.push(code);

if (!w.codes.includes(code)) {
const replacement = replacements[code] ?? code.replace(/-/g, '_');

if (!match[2]) {
break;
if (w.codes.includes(replacement)) {
ignores.push(replacement);
}
}
}
}

Expand All @@ -76,8 +89,12 @@ export function migrate_svelte_ignore(text) {
const length = match[0].length;
return (
text.substring(0, length) +
text
.substring(length)
.replace(/\w+-\w+(-\w+)*/g, (code) => replacements[code] ?? code.replace(/-/g, '_'))
text.substring(length).replace(/\w+-\w+(-\w+)*/g, (code, _, idx) => {
let replacement = replacements[code] ?? code.replace(/-/g, '_');
if (/\w+-\w+/.test(text.substring(length + idx + code.length))) {
replacement += ',';
}
return replacement;
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
</script>

<!-- svelte-ignore a11y-something-something -->
<div></div>

<!-- svelte-ignore a11y-something-something a11y-something-something2 -->
<div></div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
</script>

<!-- svelte-ignore a11y_something_something -->
<div></div>

<!-- svelte-ignore a11y_something_something, a11y_something_something2 -->
<div></div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@

<!-- svelte-ignore a11y-misplaced-scope -->
<div scope></div>

<!-- svelte-ignore a11y-missing-attribute a11y-misplaced-scope -->
<div>
<img src="this-is-fine.jpg">
<div scope></div>
</div>
Loading