Skip to content

fix(oxfmt): Handle literalline for script-in-vue#20130

Merged
graphite-app[bot] merged 1 commit intomainfrom
03-09-fix_oxfmt_handle_literalline_for_script-in-vue
Mar 13, 2026
Merged

fix(oxfmt): Handle literalline for script-in-vue#20130
graphite-app[bot] merged 1 commit intomainfrom
03-09-fix_oxfmt_handle_literalline_for_script-in-vue

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Mar 9, 2026

Fixes #20084, closes #20085

Currently, in the context of js-in-vue, there are 2 types of code paths:

  • Script block: run_full()
    • Converts a string formatted by oxc_formatter into Prettier's Doc format by splitting it into lines, joining with hardline
  • Other cases: run_fragment()
    • Converts the IR formatted by oxc_formatter into Prettier's Doc format through an IR -> Doc implementation

The current issue can be described as a bug in the former.

As a result of simply splitting by lines, newlines within strings (newlines within TemplateLiterals) are also treated as hardline (which are affected by parent indentation, it should be literalline), causing the nesting to deepen with each format.

To fix this, the former code path now also goes through an IR -> Doc conversion process.

Additionally, by doing this, the printWidth is also handled correctly.

In #20085, which involves re-converting a formatted string into an AST and then traversing it, was deemed undesirable.

Copilot AI review requested due to automatic review settings March 9, 2026 01:11
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug labels Mar 9, 2026
Copy link
Member Author

leaysgur commented Mar 9, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes oxfmt’s textToDoc() output for JS/TS embedded in Vue <script> blocks by converting formatter IR directly into a Prettier Doc so that literalline vs hardline semantics are preserved (notably when vueIndentScriptAndStyle: true and Prettier wraps the script in indent()).

Changes:

  • Add regression tests (and snapshots) for Vue SFC formatting with template literals, including an idempotency check.
  • Switch jsTextToDoc “full mode” from string-based output to IR → Prettier Doc conversion, preserving literalline for template literal content.
  • Enhance IR → Prettier Doc conversion logic (space/newline handling) and adjust NAPI JS bindings surface/types.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
apps/oxfmt/test/api/js-in-vue.test.ts Adds Vue SFC template-literal regression tests (incl. idempotency).
apps/oxfmt/test/api/snapshots/js-in-vue.test.ts.snap Updates snapshots for the new Vue template-literal cases.
apps/oxfmt/src/prettier_compat/to_prettier_doc.rs Converts formatter IR to Prettier Doc with literalline support and additional whitespace/newline state handling.
apps/oxfmt/src/core/config.rs Removes the NAPI-only set_filepath_override helper.
apps/oxfmt/src/api/text_to_doc_api.rs Uses IR → Prettier Doc conversion in full mode; wires external callback filepath via external options.
apps/oxfmt/src-js/bindings.js Adjusts JS exports from the native binding (removes Severity export).
apps/oxfmt/src-js/bindings.d.ts Removes several type declarations from the generated .d.ts.

You can also share your feedback on Copilot code review. Take the survey.

@leaysgur leaysgur force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch 2 times, most recently from c42dc1b to e38c9ab Compare March 9, 2026 01:46
@leaysgur
Copy link
Member Author

leaysgur commented Mar 9, 2026

Oxfmt Ecosystem CI

suite oxfmt@latest 7ad7521 branch
formatjs/formatjs
eggjs/egg
AmanVarshney01/create-better-t-stack
cnpm/cnpmcore
fastify/fastify-vite
vercel/turborepo
monkeytypegame/monkeytype
actualbudget/actual
vuejs/core
fuma-nama/fumadocs
huggingface/huggingface.js
vuejs/pinia
lichess-org/lila
dyad-sh/dyad
Comfy-Org/ComfyUI_frontend
openclaw/openclaw
rolldown/rolldown
cloudflare/agents
tale/headplane
mastodon/mastodon
aidenybai/react-grab
getsentry/sentry-javascript
npmx-dev/npmx.dev

@leaysgur leaysgur force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch from e38c9ab to 0372f2f Compare March 9, 2026 02:11
@leaysgur

This comment was marked as resolved.

@leaysgur leaysgur force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch 4 times, most recently from 4743936 to 2fc3ec3 Compare March 9, 2026 08:57
@leaysgur leaysgur marked this pull request as draft March 9, 2026 09:01
@leaysgur
Copy link
Member Author

leaysgur commented Mar 9, 2026

To be extra careful, I want to test it a bit more, so I'll revert it back to Draft for now.

@leaysgur leaysgur force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch 3 times, most recently from d6d4b0b to 7ad7521 Compare March 10, 2026 04:52
@leaysgur
Copy link
Member Author

leaysgur commented Mar 10, 2026

@leaysgur leaysgur marked this pull request as ready for review March 10, 2026 05:04
@leaysgur leaysgur requested a review from Dunqing March 10, 2026 05:04
@leaysgur leaysgur force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch from 7ad7521 to 325026b Compare March 10, 2026 13:00
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Mar 12, 2026
Copy link
Member

Dunqing commented Mar 12, 2026

Merge activity

graphite-app bot pushed a commit that referenced this pull request Mar 12, 2026
Fixes #20084, closes #20085

Currently, in the context of `js-in-vue`, there are 2 types of code paths:

- Script block: `run_full()`
  - Converts a **string** formatted by `oxc_formatter` into Prettier's Doc format by splitting it into lines, joining with `hardline`
- Other cases: `run_fragment()`
  - Converts the **IR** formatted by `oxc_formatter` into Prettier's Doc format through an IR -> Doc implementation

The current issue can be described as a bug in the former.

As a result of simply splitting by lines, newlines within strings (newlines within `TemplateLiteral`s) are also treated as `hardline` (which are affected by parent indentation, it should be `literalline`), causing the nesting to deepen with each format.

To fix this, the former code path now also goes through an IR -> Doc conversion process.

Additionally, by doing this, the `printWidth` is also handled correctly.

In #20085, which involves re-converting a formatted string into an AST and then traversing it, was deemed undesirable.
@graphite-app graphite-app bot force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch from 325026b to 90b1d6c Compare March 12, 2026 23:53
Fixes #20084, closes #20085

Currently, in the context of `js-in-vue`, there are 2 types of code paths:

- Script block: `run_full()`
  - Converts a **string** formatted by `oxc_formatter` into Prettier's Doc format by splitting it into lines, joining with `hardline`
- Other cases: `run_fragment()`
  - Converts the **IR** formatted by `oxc_formatter` into Prettier's Doc format through an IR -> Doc implementation

The current issue can be described as a bug in the former.

As a result of simply splitting by lines, newlines within strings (newlines within `TemplateLiteral`s) are also treated as `hardline` (which are affected by parent indentation, it should be `literalline`), causing the nesting to deepen with each format.

To fix this, the former code path now also goes through an IR -> Doc conversion process.

Additionally, by doing this, the `printWidth` is also handled correctly.

In #20085, which involves re-converting a formatted string into an AST and then traversing it, was deemed undesirable.
@graphite-app graphite-app bot force-pushed the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch from 90b1d6c to 88ee826 Compare March 12, 2026 23:55
@graphite-app graphite-app bot merged commit 88ee826 into main Mar 13, 2026
19 checks passed
@graphite-app graphite-app bot deleted the 03-09-fix_oxfmt_handle_literalline_for_script-in-vue branch March 13, 2026 00:06
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 13, 2026
camc314 pushed a commit that referenced this pull request Mar 16, 2026
# Oxlint
### 🚀 Features

- c95951f linter/plugins: Implement `sourceCode.markVariableAsUsed` (#20357) (overlookmotel)
- 7a2a7d0 linter: Implement `n/handle-callback-err` rule (#19616) (Mikhail Baev)

### 🐛 Bug Fixes

- f8fbd6e linter/plugins: Remove `hashbang` property from AST (#20365) (overlookmotel)
- 6eb5b01 linter/prefer-await-to-then: Ignore Promise static methods (#20347) (camc314)
- a4b61f7 linter: Remove `defineConfig` check (#20308) (camc314)
- 3ad7f53 linter/explicit-module-boundary-types: False positive with satisfies expr (#20309) (camc314)
- f547401 linter/no-unused-private-class-members: Treat switch discriminants as read (#20307) (camc314)
- 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen)

### ⚡ Performance

- e4f7248 linter: Remove unnecessary clone of owned String in drain loop (#20388) (Boshen)
- 4a67f1d linter: Eliminate Vec allocation in disable directive matching (#20387) (Boshen)
- 618a598 linter/plugins: Add fast path for files with no comments (#20366) (overlookmotel)
- b0125c5 linter/plugins: Deserialize comments without AST (#20364) (overlookmotel)
- 9cd612f linter/plugins: Recycle comment objects (#20362) (overlookmotel)
- bf442f8 linter/plugins: Cheaper `Token` creation (#20360) (overlookmotel)
- 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen)
- 7946eba linter/plugins: Avoid arguments spread and temp array when merging (#20318) (overlookmotel)
- fc7cf8a linter/plugins: Pre-define less CFG merger functions (#20317) (overlookmotel)
- 3b9eb28 linter/plugins: Streamline getting/creating visit fn mergers (#20319) (overlookmotel)
- f04e850 linter/plugins: Inline binary search functions into call sites (#20312) (overlookmotel)
- fe24afe linter/plugins: Apply replace globals TSDown plugin to JS files (#20305) (overlookmotel)
- 77cdacc linter/plugins: Use array buffer views for tokens (#20301) (overlookmotel)
- 910c941 linter/plugins: Reorder branches in `getTokenByRangeStart` (#20296) (overlookmotel)
- af7674c linter/tokens: Avoid extra token value allocation (#20013) (camc314)

### 📚 Documentation

- 24490b5 linter: Improve formatting for 80ish rules' docs. (#20411) (connorshea)
- 3383523 linter: Improve `--tsconfig` flag docs (#20342) (camc314)
# Oxfmt
### 🚀 Features

- d22c443 oxfmt: Export `OxfmtConfig` type (#20275) (leaysgur)
- a11ecff oxfmt/lsp: Respect `angular` language id as `.component.html` file (#20242) (Sysix)

### 🐛 Bug Fixes

- ce65099 formatter: Preserve parentheses around as expression before private field access (#20419) (bab)
- f908742 oxfmt: Revert #20326 partially (#20413) (leaysgur)
- 4ef93ea formatter: Honor trailing ignore comments after list separators (#19925) (Andreas Lubbe)
- 68fb0d0 oxfmt: Skip vite.config.ts which fails to import (#20326) (leaysgur)
- 88ee826 oxfmt: Handle literalline for script-in-vue (#20130) (leaysgur)
- 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oxfmt: non-idempotent formatting of template literals in Vue SFC with vueIndentScriptAndStyle

3 participants