Skip to content

chore: remove some todos #16515

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

Merged
merged 6 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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/happy-countries-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: remove some todos
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function convert(source, ast) {
ClassDirective(node) {
return { ...node, type: 'Class' };
},
Comment(node) {
TemplateComment(node) {
return {
...node,
ignores: extract_svelte_ignore(node.start, node.data, false)
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ const template = {
);
}
},
Comment(node, { state }) {
TemplateComment(node, { state }) {
const migrated = migrate_svelte_ignore(node.data);
if (migrated !== node.data) {
state.str.overwrite(node.start + '<!--'.length, node.end - '-->'.length, migrated);
Expand Down Expand Up @@ -1707,14 +1707,14 @@ function extract_type_and_comment(declarator, state, path) {
}

// Ensure modifiers are applied in the same order as Svelte 4
const modifier_order = [
const modifier_order = /** @type {const} */ ([
'preventDefault',
'stopPropagation',
'stopImmediatePropagation',
'self',
'trusted',
'once'
];
]);

/**
* @param {AST.RegularElement | AST.SvelteElement | AST.SvelteWindow | AST.SvelteDocument | AST.SvelteBody} element
Expand Down
1 change: 0 additions & 1 deletion packages/svelte/src/compiler/phases/1-parse/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @import { AST } from '#compiler' */
/** @import { Comment } from 'estree' */
// @ts-expect-error acorn type definitions are borked in the release we use
import { isIdentifierStart, isIdentifierChar } from 'acorn';
import fragment from './state/fragment.js';
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function element(parser) {
parser.eat('-->', true);

parser.append({
type: 'Comment',
type: 'TemplateComment',
start,
end: parser.index,
data
Expand Down Expand Up @@ -302,7 +302,7 @@ export default function element(parser) {
if (is_top_level_script_or_style) {
parser.eat('>', true);

/** @type {AST.Comment | null} */
/** @type {AST.TemplateComment | null} */
let prev_comment = null;
for (let i = current.fragment.nodes.length - 1; i >= 0; i--) {
const node = current.fragment.nodes[i];
Expand All @@ -311,7 +311,7 @@ export default function element(parser) {
break;
}

if (node.type === 'Comment') {
if (node.type === 'TemplateComment') {
prev_comment = node;
break;
} else if (node.type !== 'Text' || node.data.trim()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ const visitors = {
/** @type {string[]} */
const ignores = [];

if (parent?.type === 'Fragment' && node.type !== 'Comment' && node.type !== 'Text') {
if (parent?.type === 'Fragment' && node.type !== 'TemplateComment' && node.type !== 'Text') {
const idx = parent.nodes.indexOf(/** @type {any} */ (node));

for (let i = idx - 1; i >= 0; i--) {
const prev = parent.nodes[i];

if (prev.type === 'Comment') {
if (prev.type === 'TemplateComment') {
ignores.push(
...extract_svelte_ignore(
prev.start + 4 /* '<!--'.length */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function SnippetBlock(node, context) {
(node) =>
node.type !== 'SnippetBlock' &&
(node.type !== 'Text' || node.data.trim()) &&
node.type !== 'Comment'
node.type !== 'TemplateComment'
)
) {
e.snippet_conflict(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function Text(node, context) {
for (const child of parent.nodes) {
if (child === node) break;

if (child.type === 'Comment') {
if (child.type === 'TemplateComment') {
is_ignored ||= extract_svelte_ignore(
child.start + 4,
child.data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export function check_element(node, context) {
}
case 'figure': {
const children = node.fragment.nodes.filter((node) => {
if (node.type === 'Comment') return false;
if (node.type === 'TemplateComment') return false;
if (node.type === 'Text') return regex_not_whitespace.test(node.data);
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ export function visit_component(node, context) {
context.visit(attribute, attribute.type === 'LetDirective' ? default_state : context.state);
}

/** @type {AST.Comment[]} */
/** @type {AST.TemplateComment[]} */
let comments = [];

/** @type {Record<string, AST.Fragment['nodes']>} */
const nodes = { default: [] };

for (const child of node.fragment.nodes) {
if (child.type === 'Comment') {
if (child.type === 'TemplateComment') {
comments.push(child);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function validate_element(node, context) {
} else if (
parent.body.nodes.filter(
(n) =>
n.type !== 'Comment' &&
n.type !== 'TemplateComment' &&
n.type !== 'ConstTag' &&
(n.type !== 'Text' || n.data.trim() !== '')
).length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { BlockStatement } from './visitors/BlockStatement.js';
import { BreakStatement } from './visitors/BreakStatement.js';
import { CallExpression } from './visitors/CallExpression.js';
import { ClassBody } from './visitors/ClassBody.js';
import { Comment } from './visitors/Comment.js';
import { Component } from './visitors/Component.js';
import { ConstTag } from './visitors/ConstTag.js';
import { DebugTag } from './visitors/DebugTag.js';
Expand Down Expand Up @@ -53,6 +52,7 @@ import { SvelteBoundary } from './visitors/SvelteBoundary.js';
import { SvelteHead } from './visitors/SvelteHead.js';
import { SvelteSelf } from './visitors/SvelteSelf.js';
import { SvelteWindow } from './visitors/SvelteWindow.js';
import { TemplateComment } from './visitors/TemplateComment.js';
import { TitleElement } from './visitors/TitleElement.js';
import { TransitionDirective } from './visitors/TransitionDirective.js';
import { UpdateExpression } from './visitors/UpdateExpression.js';
Expand Down Expand Up @@ -96,7 +96,6 @@ const visitors = {
BreakStatement,
CallExpression,
ClassBody,
Comment,
Component,
ConstTag,
DebugTag,
Expand Down Expand Up @@ -130,6 +129,7 @@ const visitors = {
SvelteHead,
SvelteSelf,
SvelteWindow,
TemplateComment,
TitleElement,
TransitionDirective,
UpdateExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/** @import { Context } from '../types' */
import { dev, is_ignored } from '../../../../state.js';
import * as b from '#compiler/builders';
import { get_rune } from '../../../scope.js';
import { get_rune, UNKNOWN } from '../../../scope.js';
import { transform_inspect_rune } from '../../utils.js';
import { should_proxy } from '../utils.js';

Expand Down Expand Up @@ -82,7 +82,9 @@ export function CallExpression(node, context) {
['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes(
node.callee.property.name
) &&
node.arguments.some((arg) => arg.type !== 'Literal') // TODO more cases?
node.arguments.some(
(arg) => arg.type === 'SpreadElement' || context.state.scope.evaluate(arg).values.has(UNKNOWN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evaluation of SpreadElement will result in UNKNOWN anyway, so the first check can be removed, right?
And maybe it's cleaner to add has/is_unknown prop-flag to Evaluation and use it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope.evaluate's parameters only accept an Expression node, which does not include SpreadElements.
I'll add the has unknown check in a bit.

)
) {
return b.call(
node.callee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import * as b from '#compiler/builders';
import { build_event, build_event_handler } from './shared/events.js';

const modifiers = [
const modifiers = /** @type {const} */ ([
'stopPropagation',
'stopImmediatePropagation',
'preventDefault',
'self',
'trusted',
'once'
];
]);

/**
* @param {AST.OnDirective} node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/** @import { ComponentContext } from '../types' */

/**
* @param {AST.Comment} node
* @param {AST.TemplateComment} node
* @param {ComponentContext} context
*/
export function Comment(node, context) {
export function TemplateComment(node, context) {
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true
context.state.template.push_comment(node.data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const empty_comment = b.literal(EMPTY_COMMENT);
* @param {ComponentContext} context
*/
export function process_children(nodes, { visit, state }) {
/** @type {Array<AST.Text | AST.Comment | AST.ExpressionTag>} */
/** @type {Array<AST.Text | AST.TemplateComment | AST.ExpressionTag>} */
let sequence = [];

function flush() {
Expand All @@ -41,9 +41,9 @@ export function process_children(nodes, { visit, state }) {
for (let i = 0; i < sequence.length; i++) {
const node = sequence[i];

if (node.type === 'Text' || node.type === 'Comment') {
if (node.type === 'Text' || node.type === 'TemplateComment') {
quasi.value.cooked +=
node.type === 'Comment' ? `<!--${node.data}-->` : escape_html(node.data);
node.type === 'TemplateComment' ? `<!--${node.data}-->` : escape_html(node.data);
} else {
const evaluated = state.scope.evaluate(node.expression);

Expand All @@ -68,7 +68,7 @@ export function process_children(nodes, { visit, state }) {
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i];

if (node.type === 'Text' || node.type === 'Comment' || node.type === 'ExpressionTag') {
if (node.type === 'Text' || node.type === 'TemplateComment' || node.type === 'ExpressionTag') {
sequence.push(node);
} else {
if (sequence.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function clean_nodes(
const regular = [];

for (const node of nodes) {
if (node.type === 'Comment' && !preserve_comments) {
if (node.type === 'TemplateComment' && !preserve_comments) {
continue;
}

Expand Down Expand Up @@ -285,7 +285,7 @@ export function clean_nodes(
// and would still call node.replaceWith() on the script tag, it would be a no-op because the script tag has no parent.
if (trimmed.length === 1 && first.type === 'RegularElement' && first.name === 'script') {
trimmed.push({
type: 'Comment',
type: 'TemplateComment',
data: '',
start: -1,
end: -1
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { is_reserved, is_rune } from '../../utils.js';
import { determine_slot } from '../utils/slot.js';
import { validate_identifier_name } from './2-analyze/visitors/shared/utils.js';

const UNKNOWN = Symbol('unknown');
export const UNKNOWN = Symbol('unknown');
/** Includes `BigInt` */
const NUMBER = Symbol('number');
const STRING = Symbol('string');
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/types/css.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export namespace _CSS {
end: number;
styles: string;
/** Possible comment atop the style tag */
comment: AST.Comment | null;
comment: AST.TemplateComment | null;
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/types/legacy-nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export interface LegacyWindow extends BaseElement {
}

export interface LegacyComment extends BaseNode {
type: 'Comment';
type: 'TemplateComment';
/** the contents of the comment */
data: string;
/** any svelte-ignore directives — <!-- svelte-ignore a b c --> would result in ['a', 'b', 'c'] */
Expand Down
21 changes: 15 additions & 6 deletions packages/svelte/src/compiler/types/template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export namespace AST {

export interface Fragment {
type: 'Fragment';
nodes: Array<Text | Tag | ElementLike | Block | Comment>;
nodes: Array<Text | Tag | ElementLike | Block | TemplateComment>;
/** @internal */
metadata: {
/**
Expand Down Expand Up @@ -144,9 +144,8 @@ export namespace AST {
}

/** An HTML comment */
// TODO rename to disambiguate
export interface Comment extends BaseNode {
type: 'Comment';
export interface TemplateComment extends BaseNode {
type: 'TemplateComment';
/** the contents of the comment */
data: string;
}
Expand Down Expand Up @@ -247,7 +246,17 @@ export namespace AST {
name: string;
/** The 'y' in `on:x={y}` */
expression: null | Expression;
modifiers: string[]; // TODO specify
modifiers: Array<
| 'capture'
| 'nonpassive'
| 'once'
| 'passive'
| 'preventDefault'
| 'self'
| 'stopImmediatePropagation'
| 'stopPropagation'
| 'trusted'
>;
/** @internal */
metadata: {
expression: ExpressionMetadata;
Expand Down Expand Up @@ -604,7 +613,7 @@ export namespace AST {
| AST.SpreadAttribute
| Directive
| AST.AttachTag
| AST.Comment
| AST.TemplateComment
| Block;

export type SvelteNode = Node | TemplateNode | AST.Fragment | _CSS.Node | Script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"end": 31,
"children": [
{
"type": "Comment",
"type": "TemplateComment",
"start": 0,
"end": 31,
"data": " svelte-ignore foo, bar ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"end": 18,
"children": [
{
"type": "Comment",
"type": "TemplateComment",
"start": 0,
"end": 18,
"data": " a comment ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"data": "\n"
},
{
"type": "Comment",
"type": "TemplateComment",
"start": 45,
"end": 69,
"data": " prettier-ignore ",
Expand Down Expand Up @@ -83,7 +83,7 @@
"data": "\n"
},
{
"type": "Comment",
"type": "TemplateComment",
"start": 162,
"end": 186,
"data": " prettier-ignore ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "Fragment",
"nodes": [
{
"type": "Comment",
"type": "TemplateComment",
"start": 0,
"end": 27,
"data": "should not error out"
Expand Down
Loading
Loading