fix: skip Program comment nodes in migration to prevent crash (#18656)

Fixes #18304

The parent of a declaration could be the Program, on which HTML comments are added, which subsequently crashes the funciton. Ignore such comments.

---------

Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
pull/18668/head
Siddhesh Kabra 3 weeks ago committed by GitHub
parent 9414eaa41b
commit a5ea12ee93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ignore comments of Program node during migration script

@ -1590,7 +1590,12 @@ function migrate_slot_usage(node, path, state) {
*/
function extract_type_and_comment(declarator, state, path) {
const str = state.str;
const parent = path.at(-1);
let parent = path.at(-1);
if (parent?.type === 'Program') {
// We don't want comments from the program node
parent = undefined;
}
// Try to find jsdoc above the declaration
let comment_node = /** @type {Node} */ (parent)?.leadingComments?.at(-1);

@ -1,3 +1,4 @@
<!-- @component x -->
<script lang="ts">
let klass = '';
export { klass as class }

@ -1,3 +1,4 @@
<!-- @component x -->
<script lang="ts">
interface Props {
class?: string;

Loading…
Cancel
Save