sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.73k stars 4.23k forks source link

"Unexpected token" parse error #13179

Open benmccann opened 1 month ago

benmccann commented 1 month ago

Describe the bug

Svelte 5 fails to parse code that Svelte 4 handled:

  $: jobDetails = <Partial<Record<JobName, JobDetails>>>{
    [JobName.ThumbnailGeneration]: {
      icon: mdiFileJpgBox,
      title: $getJobName(JobName.ThumbnailGeneration),
      subtitle: $t('admin.thumbnail_generation_job_description'),
    },
    [JobName.MetadataExtraction]: {
      icon: mdiTable,
      title: $getJobName(JobName.MetadataExtraction),
      subtitle: $t('admin.metadata_extraction_job_description'),
    },
    [JobName.Library]: {
      icon: mdiLibraryShelves,
      title: $getJobName(JobName.Library),
      subtitle: $t('admin.library_tasks_description'),
      allText: $t('all').toUpperCase(),
      missingText: $t('refresh').toUpperCase(),
    },
    [JobName.Sidecar]: {
      title: $getJobName(JobName.Sidecar),
      icon: mdiFileXmlBox,
      subtitle: $t('admin.sidecar_job_description'),
      allText: $t('sync').toUpperCase(),
      missingText: $t('discover').toUpperCase(),
      disabled: !$featureFlags.sidecar,
    },
    [JobName.SmartSearch]: {
      icon: mdiImageSearch,
      title: $getJobName(JobName.SmartSearch),
      subtitle: $t('admin.smart_search_job_description'),
      disabled: !$featureFlags.smartSearch,
    },
    [JobName.DuplicateDetection]: {
      icon: mdiContentDuplicate,
      title: $getJobName(JobName.DuplicateDetection),
      subtitle: $t('admin.duplicate_detection_job_description'),
      disabled: !$featureFlags.duplicateDetection,
    },
    [JobName.FaceDetection]: {
      icon: mdiFaceRecognition,
      title: $getJobName(JobName.FaceDetection),
      subtitle: $t('admin.face_detection_description'),
      handleCommand: handleConfirmCommand,
      disabled: !$featureFlags.facialRecognition,
    },
    [JobName.FacialRecognition]: {
      icon: mdiTagFaces,
      title: $getJobName(JobName.FacialRecognition),
      subtitle: $t('admin.facial_recognition_job_description'),
      handleCommand: handleConfirmCommand,
      disabled: !$featureFlags.facialRecognition,
    },
    [JobName.VideoConversion]: {
      icon: mdiVideo,
      title: $getJobName(JobName.VideoConversion),
      subtitle: $t('admin.video_conversion_job_description'),
    },
    [JobName.StorageTemplateMigration]: {
      icon: mdiFolderMove,
      title: $getJobName(JobName.StorageTemplateMigration),
      allowForceCommand: false,
      description: StorageMigrationDescription,
    },
    [JobName.Migration]: {
      icon: mdiFolderMove,
      title: $getJobName(JobName.Migration),
      subtitle: $t('admin.migration_job_description'),
      allowForceCommand: false,
    },
  };

Reproduction

https://github.com/immich-app/immich/blob/8cf33690b8ddd8e36bdf5d968c3d5700bfcc2949/web/src/lib/components/admin-page/jobs/jobs-panel.svelte#L60

Logs

No response

System Info

5.0.0-next.244

Severity

annoyance

Conduitry commented 1 month ago

Trimmed down example: https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACiWMQQ7CIBBFrzKZtYl7pE08R-mCUjAkFJAZjEq4uzQu38_7r6HzwRKKpWHUh0WB95zxgvzJJ9DLBraDKdVizkWSKT4zBB0fk0ImhbOKik2KxOBSggnkpsvcYNn0dxXwrG_oNxXl9X8d-ggeaffO2x0Fl2r72n9DY12niwAAAA==

<script lang="ts">
    const foo = <bar>{ [baz]: qux };
</script>

This is presumably an acorn-typescript bug.

7nik commented 1 month ago

Probably https://github.com/TyrealHu/acorn-typescript/issues/58

dummdidumm commented 1 month ago

Yeah probably - I think Acorn-Typescript doesn't parse type casts using <..> properly

nstuyvesant commented 1 week ago

Yeah probably - I think Acorn-Typescript doesn't parse type casts using <..> properly

Prior to Svelte 5 this worked...

function displayClass(classId: number): void {
  displayedClass = <ClassRecord>findParentRecord($classes, classId)
}

Now it has to be...

function displayClass(classId: number): void {
  displayedClass = findParentRecord($classes, classId) as ClassRecord
}

TSX does not permit the first type of casting (but I'm using regular TypeScript). Is it possible Acorn-TypeScript is treating TypeScript as TSX?

Conduitry commented 1 week ago

Yes, that is what is described in the linked issue above: https://github.com/TyrealHu/acorn-typescript/issues/58