Skip to content

"Unexpected token" parse error #13179

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

Closed
benmccann opened this issue Sep 9, 2024 · 7 comments · Fixed by sveltejs/acorn-typescript#1
Closed

"Unexpected token" parse error #13179

benmccann opened this issue Sep 9, 2024 · 7 comments · Fixed by sveltejs/acorn-typescript#1

Comments

@benmccann
Copy link
Member

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
Copy link
Member

Conduitry commented Sep 9, 2024

@7nik
Copy link
Contributor

7nik commented Sep 9, 2024

Probably TyrealHu/acorn-typescript#58

@dummdidumm
Copy link
Member

dummdidumm commented Sep 10, 2024

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

@nstuyvesant
Copy link

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
Copy link
Member

Yes, that is what is described in the linked issue above: TyrealHu/acorn-typescript#58

@elron
Copy link

elron commented Feb 19, 2025

Is there any news for this? I can't migrate my svelte-4 project

@paoloricciuti
Copy link
Member

Is there any news for this? I can't migrate my svelte-4 project

Unfortunately is blocked by upstream

dummdidumm added a commit to sveltejs/acorn-typescript that referenced this issue Feb 26, 2025
Does so by not parsing as JSX by default (this is a breaking change if you would switch to this parser from acorn-typescript)

Fixes sveltejs/svelte#13179
Fixes TyrealHu/acorn-typescript#58
@dummdidumm dummdidumm marked this as a duplicate of #11527 Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants