Skip to content

Conversation

thorn0
Copy link
Member

@thorn0 thorn0 commented May 27, 2020

fixes #6428

Also adds detection for previously not covered types like ForOfStatement.

Prettier 2.0.5
Playground link

--parser babel
--range-end 32
--range-start 20

Input:

f(       fff )
for   (z of [ v]) {}

Output:

f(       fff )
for   (z of [ v]) {}

Prettier pr-8419
Playground link

Output:

f(       fff )
for (z of [v]) {
}
  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@fisker
Copy link
Member

fisker commented May 27, 2020

Didn't notice there is a range related PR, need fix snapshots.

@fisker
Copy link
Member

fisker commented May 27, 2020

image

Two buttons...

@thorn0 thorn0 force-pushed the range-js-source-elements branch from 081417f to b14fd3e Compare May 27, 2020 19:45
@thorn0
Copy link
Member Author

thorn0 commented May 27, 2020

I updated the snapshots and added more sentence/declaration-like node types to this detection. Now I'm starting to think we should add class/interface members too. Why not? Why reformat the whole class instead of a single method? Am I missing something?

@thorn0
Copy link
Member Author

thorn0 commented May 28, 2020

I forgot how exactly range formatting works. It extracts the range and formats it as if it was a program. Class members on their own can't be parsed as a program, so disregard my previous comment.

@fisker
Copy link
Member

fisker commented May 28, 2020

Similar to

{
  a: '',
  ^^^^^
}

in JSON

@thorn0 thorn0 merged commit 5a0e33c into prettier:master May 29, 2020
@thorn0 thorn0 deleted the range-js-source-elements branch May 29, 2020 07:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--range-start and --range-end don't work as documented
3 participants