From e904753ecc96d5a2a1bac282044f1c8e63257e87 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 23 Jun 2025 18:16:13 -0400 Subject: [PATCH] fix --- packages/svelte/package.json | 2 +- .../svelte/scripts/process-messages/index.js | 2 -- .../src/compiler/phases/1-parse/acorn.js | 7 ++++- packages/svelte/src/compiler/print/index.js | 27 ++++++++++++------- .../svelte/src/compiler/types/template.d.ts | 2 +- pnpm-lock.yaml | 10 +++---- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/packages/svelte/package.json b/packages/svelte/package.json index cced2562cb..1cc5870f43 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -171,7 +171,7 @@ "axobject-query": "^4.1.0", "clsx": "^2.1.1", "esm-env": "^1.2.1", - "esrap": "https://pkg.pr.new/sveltejs/esrap@ef4051a", + "esrap": "https://pkg.pr.new/sveltejs/esrap@17c22f5", "is-reference": "^3.0.3", "locate-character": "^3.0.0", "magic-string": "^0.30.11", diff --git a/packages/svelte/scripts/process-messages/index.js b/packages/svelte/scripts/process-messages/index.js index d246cfbba5..80bf0bade6 100644 --- a/packages/svelte/scripts/process-messages/index.js +++ b/packages/svelte/scripts/process-messages/index.js @@ -147,7 +147,6 @@ function run() { const printed = esrap.print( ast, - // @ts-expect-error ts({ comments: comments.filter((comment) => comment !== jsdoc) }) @@ -358,7 +357,6 @@ function run() { .join('\n') }; - // @ts-expect-error const block = esrap.print({ ...ast, body: [clone] }, ts({ comments: [jsdoc_clone] })).code; printed.code += `\n\n${block}`; diff --git a/packages/svelte/src/compiler/phases/1-parse/acorn.js b/packages/svelte/src/compiler/phases/1-parse/acorn.js index f28ceab4ce..6fd7fcaf4d 100644 --- a/packages/svelte/src/compiler/phases/1-parse/acorn.js +++ b/packages/svelte/src/compiler/phases/1-parse/acorn.js @@ -107,6 +107,8 @@ function get_comment_handlers(source, comments, index = 0) { * @param {string} value * @param {number} start * @param {number} end + * @param {import('acorn').Position} [start_loc] + * @param {import('acorn').Position} [end_loc] */ onComment: (block, value, start, end, start_loc, end_loc) => { if (block && /\n/.test(value)) { @@ -125,7 +127,10 @@ function get_comment_handlers(source, comments, index = 0) { value, start, end, - loc: { start: start_loc, end: end_loc } + loc: { + start: /** @type {import('acorn').Position} */ (start_loc), + end: /** @type {import('acorn').Position} */ (end_loc) + } }); }, diff --git a/packages/svelte/src/compiler/print/index.js b/packages/svelte/src/compiler/print/index.js index 0e81cd6faf..afa3556632 100644 --- a/packages/svelte/src/compiler/print/index.js +++ b/packages/svelte/src/compiler/print/index.js @@ -10,7 +10,6 @@ import { is_void } from '../../utils.js'; export function print(ast) { // @ts-expect-error some bullshit return esrap.print(ast, { - // @ts-expect-error some bullshit ...ts({ comments: ast.type === 'Root' ? ast.comments : [] }), ...visitors }); @@ -641,13 +640,23 @@ const visitors = { for (const modifier of node.modifiers) { context.write(`|${modifier}`); } - if ( - node.expression !== null && - !(node.expression.type === 'Identifier' && node.expression.name === node.name) - ) { - context.write('={'); - context.visit(node.expression); - context.write('}'); + + if (node.value === true) { + return; + } + + context.write('='); + + if (Array.isArray(node.value)) { + context.write('"'); + + for (const tag of node.value) { + context.visit(tag); + } + + context.write('"'); + } else { + context.visit(node.value); } }, @@ -746,7 +755,7 @@ const visitors = { context.write('` element, if exists */ module: Script | null; /** Comments found in