Skip to content
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/ninety-rockets-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: allow for more svelte-ignore to work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { filename, locator, warnings, ignore_stack } from './state.js';
import { filename, locator, warnings, ignore_stack, ignore_map } from './state.js';

/** @typedef {{ start?: number, end?: number }} NodeLike */

Expand All @@ -8,7 +8,11 @@ import { filename, locator, warnings, ignore_stack } from './state.js';
* @param {string} message
*/
function w(node, code, message) {
if (ignore_stack.at(-1)?.has(code)) return;
let stack = ignore_stack;
if (node) {
stack = ignore_map.get(node) ?? ignore_stack;
}
if (stack && stack.at(-1)?.has(code)) return;

warnings.push({
code,
Expand Down
5 changes: 4 additions & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { prune } from './css/css-prune.js';
import { hash } from './utils.js';
import { warn_unused } from './css/css-warn.js';
import { extract_svelte_ignore } from '../../utils/extract_svelte_ignore.js';
import { pop_ignore, push_ignore } from '../../state.js';
import { ignore_map, ignore_stack, pop_ignore, push_ignore } from '../../state.js';

/**
* @param {import('#compiler').Script | null} script
Expand Down Expand Up @@ -1107,6 +1107,7 @@ function is_safe_identifier(expression, scope) {
/** @type {import('./types').Visitors} */
const common_visitors = {
_(node, { state, next, path }) {
ignore_map.set(node, structuredClone(ignore_stack));
const parent = path.at(-1);
if (parent?.type === 'Fragment' && node.type !== 'Comment' && node.type !== 'Text') {
const idx = parent.nodes.indexOf(/** @type {any} */ (node));
Expand All @@ -1129,6 +1130,7 @@ const common_visitors = {

if (ignores.length > 0) {
push_ignore(ignores);
ignore_map.set(node, structuredClone(ignore_stack));
next();
pop_ignore();
}
Expand All @@ -1148,6 +1150,7 @@ const common_visitors = {
}
if (ignores.length > 0) {
push_ignore(ignores);
ignore_map.set(node, structuredClone(ignore_stack));
next();
pop_ignore();
}
Expand Down
14 changes: 13 additions & 1 deletion packages/svelte/src/compiler/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ export let filename;

export let locator = getLocator('', { offsetLine: 1 });

/** @type {Set<string>[]} */
/**
* The current stack of ignored warnings
* @type {Set<string>[]}
*/
export let ignore_stack = [];

/**
* For each node the list of warnings that should be ignored for that node.
* Exists in addition to `ignore_stack` because not all warnings are emitted
* while the stack is being built.
* @type {Map<import("./types").SvelteNode | NodeLike, Set<string>[]>}
*/
export let ignore_map = new Map();

/**
* @param {string[]} ignores
*/
Expand Down Expand Up @@ -49,4 +60,5 @@ export function reset(source, options) {
locator = getLocator(source, { offsetLine: 1 });
warnings = [];
ignore_stack = [];
ignore_map.clear();
}
16 changes: 14 additions & 2 deletions packages/svelte/src/compiler/warnings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* This file is generated by scripts/process-messages/index.js. Do not edit! */

import { filename, locator, warnings, ignore_stack } from './state.js';
import {
filename,
locator,
warnings,
ignore_stack,
ignore_map
} from './state.js';

/** @typedef {{ start?: number, end?: number }} NodeLike */
/**
Expand All @@ -9,7 +15,13 @@ import { filename, locator, warnings, ignore_stack } from './state.js';
* @param {string} message
*/
function w(node, code, message) {
if (ignore_stack.at(-1)?.has(code)) return;
let stack = ignore_stack;

if (node) {
stack = ignore_map.get(node) ?? ignore_stack;
}

if (stack && stack.at(-1)?.has(code)) return;

warnings.push({
code,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
// svelte-ignore export_let_unused
export let some;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<svelte:options runes />

<script>
// svelte-ignore non_reactive_update
let value;

value="";
</script>

{value}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]