Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

Add --comment option #68

Closed

Conversation

clintwood
Copy link
Contributor

@clintwood clintwood commented Jul 6, 2018

This PR adds a -C, --comment options to Transform flow types to flow Comment Types in output.

E.g. $ flow-remove-types --comment source.js

/* flow */

// Import types
import type { SomeType } from 'some-module';

outputs:

/* flow */

// Import types
/*:: import type { SomeType } from 'some-module'; */

Closes #66.

@swac
Copy link

swac commented Oct 17, 2018

What's needed to get this PR merged? This feature would be great to have!

@clintwood
Copy link
Contributor Author

@leebyron, please could you take a look at this PR and PR #64 - the last release to flow-remove-types was Oct 18, 2017

@motiz88
Copy link
Contributor

motiz88 commented Feb 15, 2019

Hi! I apologise for how long it's taken us to look at this. It looks like a really valuable feature, and as I'm doing some work on this package towards a v2 release, I'd love to get this in as well.

That said, I have some concerns about the code as-is. @clintwood, would you have the bandwidth to address some feedback here?

Copy link
Contributor

@motiz88 motiz88 left a comment

Choose a reason for hiding this comment

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

I think this mode also needs to support source maps, since the comment start/end characters will necessarily cause code to move around. I don't suppose this just happens to work if we pass --sourcemaps? 🙂 At any rate, the tests should cover this scenario.

At minimum, we should detect unsupported combinations of flags and output a clear error message.

}
} else {
var toCommentLines = toComment.split(LINE_RX);
// TODO: detect file line endings scheme (\n or \r\n)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably resolve this TODO. I wouldn't want to merge this feature if it messes up Windows line endings.

toCommentLines.push('\n*/');
result += toCommentLines.join('');
}
} else if (!pretty) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if both --pretty and --comment are specified?

@@ -29,6 +29,16 @@ echo "Test: flow-remove-types --pretty --sourcemaps inline test/source.js"
DIFF=$(./flow-remove-types --pretty --sourcemaps inline test/source.js | diff test/expected-pretty-inlinemap.js -);
if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi;

# Test expected output with --comment option
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also add the new test cases to test-update.sh.

@clintwood
Copy link
Contributor Author

With the greatest of respect I have switched to Typescript and do not have time to dig into this any longer. Please feel free to close or fork my branch and make the above changes. Thanks.

@clintwood clintwood closed this Feb 16, 2019
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.

3 participants