Giter Site home page Giter Site logo

Comments (5)

dyc3 avatar dyc3 commented on May 24, 2024

I'd like to give this a shot.

from biome.

dyc3 avatar dyc3 commented on May 24, 2024

I have a smaller repro here: https://biomejs.dev/playground/?code=YwBvAG4AcwB0ACAAVgBhAGwATQBlAG4AdQBEAGkAdgBpAGQAZQA6ACAAUgBlAGEAYwB0AEYARgBDADwATQBlAGQAZABkAGQAZABkAGQAZABkAE0AZQBuAHUARABpAHYAaQBkAGUAcgBQAHIAbwBwAHMATQBlAG4AdQBEAGkAdgBpAGQAZQByAFAAcgBvAHAAcwB6AHoAegA%2BAD0AKAB4ACkAIAA9AD4AIAA1ADsACgA%3D

from biome.

dyc3 avatar dyc3 commented on May 24, 2024

I've been combing over the code for a while now, and I think I understand what's going on. Mostly notes for myself:

The variable declaration group is higher up in the IR tree than the type annotation group. When the tree gets flattened into FormatElements, the variable declaration group gets evaluated first to see if it breaks (and since it's long enough, it breaks). Then the type annotation group gets evaluated, and its not long enough, so it doesn't break. This evaluation happens here:

// Measure to see if the group fits up on a single line. If that's the case,
// print the group in "flat" mode, otherwise continue in expanded mode
stack.push(TagKind::Group, args.with_print_mode(PrintMode::Flat));
let fits = self.fits(queue, stack, indent_stack)?;
stack.pop(TagKind::Group)?;

I think one way to fix this is to introduce some kind of "break priority" field to the Group struct, and then favor breaking type annotations, but I think that could introduce some complexity.

from biome.

ah-yu avatar ah-yu commented on May 24, 2024

I think one way to fix this is to introduce some kind of "break priority" field to the Group struct, and then favor breaking type annotations, but I think that could introduce some complexity.

It seems that this approach assumes the current generated IR is accurate. Perhaps we could compare the IR generated by Biome and Prettier to identify differences between them and address these disparities to see if the issue is resolved.

from biome.

dyc3 avatar dyc3 commented on May 24, 2024

Ok yeah, I was looking at the IR before and it looked identical, but I'm looking at it again and it is definitely not. Biome is emitting an extra group around the left hand side of the assignment.

from biome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.