Skip to content

fix: handle trailing comma in Worker new URL multiline format#21316

Closed
saimskywalker wants to merge 1 commit into
vitejs:mainfrom
saimskywalker:fix/worker-multiline-trailing-comma
Closed

fix: handle trailing comma in Worker new URL multiline format#21316
saimskywalker wants to merge 1 commit into
vitejs:mainfrom
saimskywalker:fix/worker-multiline-trailing-comma

Conversation

@saimskywalker
Copy link
Copy Markdown

No description provided.

The Worker plugin regex did not handle trailing commas after
`import.meta.url` when formatted by Prettier across multiple lines.

This aligns the Worker plugin regex with the Asset plugin regex
which already handles this case correctly.
@saimskywalker
Copy link
Copy Markdown
Author

I found that CI lint check (pnpm prettier --write . && git diff --exit-code) was failing because Prettier reformatted my code:

  1. In index.html - my long description line was being wrapped
  2. In main-module.js - my multiline Worker code was being collapsed to one line

But I need the multiline format to stay as-is because that's exactly what I'm testing (Worker with multiline URL and trailing comma).

The Solution:
I added prettier-ignore comments to preserve my intentional formatting:

  <!-- In index.html -->
  <!-- prettier-ignore -->
  <p>
    new Worker(new URL(..., import.meta.url,), ...) (multiline with trailing comma)
    ...
  </p>

// In main-module.js
// prettier-ignore

const wMultiline = new Worker(
  new URL(
    '../url-worker.js',
    import.meta.url,
  ),
  { type: 'module' },
)

This tells Prettier to skip these blocks, keeping the multiline format I need for the test.

@sapphi-red
Copy link
Copy Markdown
Member

#21325

@sapphi-red sapphi-red closed this Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants