Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Add options to retain lines which helps babel to preserve newlines/whitespace#326

Open
levibuzolic wants to merge 1 commit intoKhan:masterfrom
levibuzolic:retain-lines
Open

Add options to retain lines which helps babel to preserve newlines/whitespace#326
levibuzolic wants to merge 1 commit intoKhan:masterfrom
levibuzolic:retain-lines

Conversation

@levibuzolic
Copy link
Copy Markdown

Implements a --retain-lines option to pass through to Babel's retainLines option. This allows Babel to try and preserve line positions when generating output code -- the resulting output can be quite ugly, but prettier does a great job of cleaning it up.

Input

import type { Something } from "Source";

type Another = {|
  key: string,
|};

/*
 * This is a comment
 */

// Another comment

function Hello() {
  const example = 1;

  return null
}

Output

BeforeAfter
import type { Something } from "Source";
type Another = {
  key: string;
};

/*
 * This is a comment
 */
// Another comment
function Hello() {
  const example = 1;
  return null;
}
import type { Something } from "Source";

type Another = {
  key: string;
};

/*
 * This is a comment
 */

// Another comment

function Hello() {
  const example = 1;

  return null;
}

Fixes #237

Copy link
Copy Markdown

@GunnarMM GunnarMM left a comment

Choose a reason for hiding this comment

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

Looks good to me. I have also used your PR to convert a big enterprise app and it did its job brilliantly!

@DeadManPoe
Copy link
Copy Markdown

@GunnarMM My company would benefit a lot from this, but I see this project has not had any new commits in the master branch since April 2021. How likely is this going to be merged?

@MasonChinkin
Copy link
Copy Markdown

😢 wish we could merge this @GunnarMM

@GunnarMM
Copy link
Copy Markdown

Merging is blocked. I don't have power here. Maybe @levibuzolic can take a look at the merge requirements

@levibuzolic
Copy link
Copy Markdown
Author

@MasonChinkin @GunnarMM @DeadManPoe given the specs don't run anymore and there hasn't been a PR merge or release in 2+ years I don't think it's going to happen.

But if you do want to use flow-to-ts with this change included, you can pull down my fork and just run it directly and target your codebase or whatever folder of your choice.

This retain lines feature is far from perfect and we found it did shift a few of our comments up a line in a few places, but it was definitely an improvement over the default behaviour.

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.

Blank lines between statements are removed

4 participants