chore: remove some todos

pull/16515/head
ComputerGuy 1 month ago
parent 99452053af
commit 8f3924177a

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: remove some todos

@ -190,7 +190,7 @@ export function convert(source, ast) {
ClassDirective(node) { ClassDirective(node) {
return { ...node, type: 'Class' }; return { ...node, type: 'Class' };
}, },
Comment(node) { TemplateComment(node) {
return { return {
...node, ...node,
ignores: extract_svelte_ignore(node.start, node.data, false) ignores: extract_svelte_ignore(node.start, node.data, false)

@ -1362,7 +1362,7 @@ const template = {
); );
} }
}, },
Comment(node, { state }) { TemplateComment(node, { state }) {
const migrated = migrate_svelte_ignore(node.data); const migrated = migrate_svelte_ignore(node.data);
if (migrated !== node.data) { if (migrated !== node.data) {
state.str.overwrite(node.start + '<!--'.length, node.end - '-->'.length, migrated); state.str.overwrite(node.start + '<!--'.length, node.end - '-->'.length, migrated);
@ -1707,14 +1707,14 @@ function extract_type_and_comment(declarator, state, path) {
} }
// Ensure modifiers are applied in the same order as Svelte 4 // Ensure modifiers are applied in the same order as Svelte 4
const modifier_order = [ const modifier_order = /** @type {const} */ ([
'preventDefault', 'preventDefault',
'stopPropagation', 'stopPropagation',
'stopImmediatePropagation', 'stopImmediatePropagation',
'self', 'self',
'trusted', 'trusted',
'once' 'once'
]; ]);
/** /**
* @param {AST.RegularElement | AST.SvelteElement | AST.SvelteWindow | AST.SvelteDocument | AST.SvelteBody} element * @param {AST.RegularElement | AST.SvelteElement | AST.SvelteWindow | AST.SvelteDocument | AST.SvelteBody} element

@ -1,5 +1,4 @@
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { Comment } from 'estree' */
// @ts-expect-error acorn type definitions are borked in the release we use // @ts-expect-error acorn type definitions are borked in the release we use
import { isIdentifierStart, isIdentifierChar } from 'acorn'; import { isIdentifierStart, isIdentifierChar } from 'acorn';
import fragment from './state/fragment.js'; import fragment from './state/fragment.js';

@ -59,7 +59,7 @@ export default function element(parser) {
parser.eat('-->', true); parser.eat('-->', true);
parser.append({ parser.append({
type: 'Comment', type: 'TemplateComment',
start, start,
end: parser.index, end: parser.index,
data data
@ -302,7 +302,7 @@ export default function element(parser) {
if (is_top_level_script_or_style) { if (is_top_level_script_or_style) {
parser.eat('>', true); parser.eat('>', true);
/** @type {AST.Comment | null} */ /** @type {AST.TemplateComment | null} */
let prev_comment = null; let prev_comment = null;
for (let i = current.fragment.nodes.length - 1; i >= 0; i--) { for (let i = current.fragment.nodes.length - 1; i >= 0; i--) {
const node = current.fragment.nodes[i]; const node = current.fragment.nodes[i];
@ -311,7 +311,7 @@ export default function element(parser) {
break; break;
} }
if (node.type === 'Comment') { if (node.type === 'TemplateComment') {
prev_comment = node; prev_comment = node;
break; break;
} else if (node.type !== 'Text' || node.data.trim()) { } else if (node.type !== 'Text' || node.data.trim()) {

@ -89,13 +89,13 @@ const visitors = {
/** @type {string[]} */ /** @type {string[]} */
const ignores = []; 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)); const idx = parent.nodes.indexOf(/** @type {any} */ (node));
for (let i = idx - 1; i >= 0; i--) { for (let i = idx - 1; i >= 0; i--) {
const prev = parent.nodes[i]; const prev = parent.nodes[i];
if (prev.type === 'Comment') { if (prev.type === 'TemplateComment') {
ignores.push( ignores.push(
...extract_svelte_ignore( ...extract_svelte_ignore(
prev.start + 4 /* '<!--'.length */, prev.start + 4 /* '<!--'.length */,

@ -71,7 +71,7 @@ export function SnippetBlock(node, context) {
(node) => (node) =>
node.type !== 'SnippetBlock' && node.type !== 'SnippetBlock' &&
(node.type !== 'Text' || node.data.trim()) && (node.type !== 'Text' || node.data.trim()) &&
node.type !== 'Comment' node.type !== 'TemplateComment'
) )
) { ) {
e.snippet_conflict(node); e.snippet_conflict(node);

@ -34,7 +34,7 @@ export function Text(node, context) {
for (const child of parent.nodes) { for (const child of parent.nodes) {
if (child === node) break; if (child === node) break;
if (child.type === 'Comment') { if (child.type === 'TemplateComment') {
is_ignored ||= extract_svelte_ignore( is_ignored ||= extract_svelte_ignore(
child.start + 4, child.start + 4,
child.data, child.data,

@ -510,7 +510,7 @@ export function check_element(node, context) {
} }
case 'figure': { case 'figure': {
const children = node.fragment.nodes.filter((node) => { 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); if (node.type === 'Text') return regex_not_whitespace.test(node.data);
return true; return true;
}); });

@ -127,14 +127,14 @@ export function visit_component(node, context) {
context.visit(attribute, attribute.type === 'LetDirective' ? default_state : context.state); context.visit(attribute, attribute.type === 'LetDirective' ? default_state : context.state);
} }
/** @type {AST.Comment[]} */ /** @type {AST.TemplateComment[]} */
let comments = []; let comments = [];
/** @type {Record<string, AST.Fragment['nodes']>} */ /** @type {Record<string, AST.Fragment['nodes']>} */
const nodes = { default: [] }; const nodes = { default: [] };
for (const child of node.fragment.nodes) { for (const child of node.fragment.nodes) {
if (child.type === 'Comment') { if (child.type === 'TemplateComment') {
comments.push(child); comments.push(child);
continue; continue;
} }

@ -98,7 +98,7 @@ export function validate_element(node, context) {
} else if ( } else if (
parent.body.nodes.filter( parent.body.nodes.filter(
(n) => (n) =>
n.type !== 'Comment' && n.type !== 'TemplateComment' &&
n.type !== 'ConstTag' && n.type !== 'ConstTag' &&
(n.type !== 'Text' || n.data.trim() !== '') (n.type !== 'Text' || n.data.trim() !== '')
).length > 1 ).length > 1

@ -19,7 +19,6 @@ import { BlockStatement } from './visitors/BlockStatement.js';
import { BreakStatement } from './visitors/BreakStatement.js'; import { BreakStatement } from './visitors/BreakStatement.js';
import { CallExpression } from './visitors/CallExpression.js'; import { CallExpression } from './visitors/CallExpression.js';
import { ClassBody } from './visitors/ClassBody.js'; import { ClassBody } from './visitors/ClassBody.js';
import { Comment } from './visitors/Comment.js';
import { Component } from './visitors/Component.js'; import { Component } from './visitors/Component.js';
import { ConstTag } from './visitors/ConstTag.js'; import { ConstTag } from './visitors/ConstTag.js';
import { DebugTag } from './visitors/DebugTag.js'; import { DebugTag } from './visitors/DebugTag.js';
@ -53,6 +52,7 @@ import { SvelteBoundary } from './visitors/SvelteBoundary.js';
import { SvelteHead } from './visitors/SvelteHead.js'; import { SvelteHead } from './visitors/SvelteHead.js';
import { SvelteSelf } from './visitors/SvelteSelf.js'; import { SvelteSelf } from './visitors/SvelteSelf.js';
import { SvelteWindow } from './visitors/SvelteWindow.js'; import { SvelteWindow } from './visitors/SvelteWindow.js';
import { TemplateComment } from './visitors/TemplateComment.js';
import { TitleElement } from './visitors/TitleElement.js'; import { TitleElement } from './visitors/TitleElement.js';
import { TransitionDirective } from './visitors/TransitionDirective.js'; import { TransitionDirective } from './visitors/TransitionDirective.js';
import { UpdateExpression } from './visitors/UpdateExpression.js'; import { UpdateExpression } from './visitors/UpdateExpression.js';
@ -96,7 +96,6 @@ const visitors = {
BreakStatement, BreakStatement,
CallExpression, CallExpression,
ClassBody, ClassBody,
Comment,
Component, Component,
ConstTag, ConstTag,
DebugTag, DebugTag,
@ -130,6 +129,7 @@ const visitors = {
SvelteHead, SvelteHead,
SvelteSelf, SvelteSelf,
SvelteWindow, SvelteWindow,
TemplateComment,
TitleElement, TitleElement,
TransitionDirective, TransitionDirective,
UpdateExpression, UpdateExpression,

@ -82,7 +82,7 @@ export function CallExpression(node, context) {
['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes( ['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes(
node.callee.property.name 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).is_known)
) { ) {
return b.call( return b.call(
node.callee, node.callee,

@ -2,10 +2,10 @@
/** @import { ComponentContext } from '../types' */ /** @import { ComponentContext } from '../types' */
/** /**
* @param {AST.Comment} node * @param {AST.TemplateComment} node
* @param {ComponentContext} context * @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 // 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); context.state.template.push_comment(node.data);
} }

@ -28,7 +28,7 @@ export const empty_comment = b.literal(EMPTY_COMMENT);
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function process_children(nodes, { visit, state }) { 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 = []; let sequence = [];
function flush() { function flush() {
@ -41,9 +41,9 @@ export function process_children(nodes, { visit, state }) {
for (let i = 0; i < sequence.length; i++) { for (let i = 0; i < sequence.length; i++) {
const node = sequence[i]; const node = sequence[i];
if (node.type === 'Text' || node.type === 'Comment') { if (node.type === 'Text' || node.type === 'TemplateComment') {
quasi.value.cooked += quasi.value.cooked +=
node.type === 'Comment' ? `<!--${node.data}-->` : escape_html(node.data); node.type === 'TemplateComment' ? `<!--${node.data}-->` : escape_html(node.data);
} else { } else {
const evaluated = state.scope.evaluate(node.expression); const evaluated = state.scope.evaluate(node.expression);
@ -68,7 +68,7 @@ export function process_children(nodes, { visit, state }) {
for (let i = 0; i < nodes.length; i += 1) { for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i]; 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); sequence.push(node);
} else { } else {
if (sequence.length > 0) { if (sequence.length > 0) {

@ -165,7 +165,7 @@ export function clean_nodes(
const regular = []; const regular = [];
for (const node of nodes) { for (const node of nodes) {
if (node.type === 'Comment' && !preserve_comments) { if (node.type === 'TemplateComment' && !preserve_comments) {
continue; continue;
} }
@ -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. // 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') { if (trimmed.length === 1 && first.type === 'RegularElement' && first.name === 'script') {
trimmed.push({ trimmed.push({
type: 'Comment', type: 'TemplateComment',
data: '', data: '',
start: -1, start: -1,
end: -1 end: -1

@ -15,7 +15,7 @@ export namespace _CSS {
end: number; end: number;
styles: string; styles: string;
/** Possible comment atop the style tag */ /** Possible comment atop the style tag */
comment: AST.Comment | null; comment: AST.TemplateComment | null;
}; };
} }

@ -210,7 +210,7 @@ export interface LegacyWindow extends BaseElement {
} }
export interface LegacyComment extends BaseNode { export interface LegacyComment extends BaseNode {
type: 'Comment'; type: 'TemplateComment';
/** the contents of the comment */ /** the contents of the comment */
data: string; data: string;
/** any svelte-ignore directives — <!-- svelte-ignore a b c --> would result in ['a', 'b', 'c'] */ /** any svelte-ignore directives — <!-- svelte-ignore a b c --> would result in ['a', 'b', 'c'] */

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

@ -5,7 +5,7 @@
"end": 31, "end": 31,
"children": [ "children": [
{ {
"type": "Comment", "type": "TemplateComment",
"start": 0, "start": 0,
"end": 31, "end": 31,
"data": " svelte-ignore foo, bar ", "data": " svelte-ignore foo, bar ",

@ -5,7 +5,7 @@
"end": 18, "end": 18,
"children": [ "children": [
{ {
"type": "Comment", "type": "TemplateComment",
"start": 0, "start": 0,
"end": 18, "end": 18,
"data": " a comment ", "data": " a comment ",

@ -21,7 +21,7 @@
"data": "\n" "data": "\n"
}, },
{ {
"type": "Comment", "type": "TemplateComment",
"start": 45, "start": 45,
"end": 69, "end": 69,
"data": " prettier-ignore ", "data": " prettier-ignore ",
@ -83,7 +83,7 @@
"data": "\n" "data": "\n"
}, },
{ {
"type": "Comment", "type": "TemplateComment",
"start": 162, "start": 162,
"end": 186, "end": 186,
"data": " prettier-ignore ", "data": " prettier-ignore ",

@ -8,7 +8,7 @@
"type": "Fragment", "type": "Fragment",
"nodes": [ "nodes": [
{ {
"type": "Comment", "type": "TemplateComment",
"start": 0, "start": 0,
"end": 27, "end": 27,
"data": "should not error out" "data": "should not error out"

@ -1145,7 +1145,7 @@ declare module 'svelte/compiler' {
export interface Fragment { export interface Fragment {
type: 'Fragment'; type: 'Fragment';
nodes: Array<Text | Tag | ElementLike | Block | Comment>; nodes: Array<Text | Tag | ElementLike | Block | TemplateComment>;
} }
export interface Root extends BaseNode { export interface Root extends BaseNode {
@ -1220,9 +1220,8 @@ declare module 'svelte/compiler' {
} }
/** An HTML comment */ /** An HTML comment */
// TODO rename to disambiguate export interface TemplateComment extends BaseNode {
export interface Comment extends BaseNode { type: 'TemplateComment';
type: 'Comment';
/** the contents of the comment */ /** the contents of the comment */
data: string; data: string;
} }
@ -1296,7 +1295,17 @@ declare module 'svelte/compiler' {
name: string; name: string;
/** The 'y' in `on:x={y}` */ /** The 'y' in `on:x={y}` */
expression: null | Expression; expression: null | Expression;
modifiers: string[]; modifiers: Array<
| 'capture'
| 'nonpassive'
| 'once'
| 'passive'
| 'preventDefault'
| 'self'
| 'stopImmediatePropagation'
| 'stopPropagation'
| 'trusted'
>;
} }
/** A `style:` directive */ /** A `style:` directive */
@ -1544,7 +1553,7 @@ declare module 'svelte/compiler' {
| AST.SpreadAttribute | AST.SpreadAttribute
| Directive | Directive
| AST.AttachTag | AST.AttachTag
| AST.Comment | AST.TemplateComment
| Block; | Block;
export type SvelteNode = Node | TemplateNode | AST.Fragment | _CSS.Node | Script; export type SvelteNode = Node | TemplateNode | AST.Fragment | _CSS.Node | Script;
@ -1599,7 +1608,7 @@ declare module 'svelte/compiler' {
end: number; end: number;
styles: string; styles: string;
/** Possible comment atop the style tag */ /** Possible comment atop the style tag */
comment: AST.Comment | null; comment: AST.TemplateComment | null;
}; };
} }

Loading…
Cancel
Save