Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flow to babel cli #10219

Closed
wants to merge 30 commits into from
Closed

Added flow to babel cli #10219

wants to merge 30 commits into from

Conversation

letladi
Copy link
Contributor

@letladi letladi commented Jul 14, 2019

added flow to the babel-cli package code.

@letladi letladi changed the title Add flow to babel cli Added flow to babel cli Jul 14, 2019
import { buildExternalHelpers } from "@babel/core";

function collect(value, previousValue): Array<string> {
function collect(
value: String | any,
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a string object, it's a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes. Sorry, that is my mistake. Will fix

// If the user passed the option with no value, like "babel-external-helpers --whitelist", do nothing.
if (typeof value !== "string") return previousValue;
if (!isString(value)) return previousValue;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't 🙈
Will fix.

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 15, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11155/

});
process.stdin.on("readable", function() {
const chunk = process.stdin.read();
if (isString(chunk)) code += toString(chunk);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need isString and toString here.

Note that chunk could also be a Buffer (docs), so isString(chunk) is not equivalent to chunk !== null.

code += chunk will implicitly convert chunk to string since code is a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove isString, but without toString flow will throw an error because it sees Buffer being incompatible with String

Copy link
Member

Choose a reason for hiding this comment

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

We can // $FlowIgnore it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright.

@@ -184,15 +199,14 @@ export default async function({ cliOptions, babelOptions }) {
}

console.error(err);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest leave return null here so that we can make this PR focus on adding flow type annotation without changing any internal logic.

Note that you can use union type to specify this function returns either a Promise<Object> or null.

_filenames.map(async function(filename: string): Promise<Object> | null {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll make the fix.

babelOptions,
}: CmdOptions): Promise<void> {
function buildResult(fileResults: Array<Object>): CompilationOutput {
const map: Object = new sourceMap.SourceMapGenerator({
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't flow already infer this type to the SourceMapGenerator class? (defined at

declare class SourceMapGenerator {
)

Copy link
Contributor Author

@letladi letladi Jul 15, 2019

Choose a reason for hiding this comment

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

It does, but the fromObject method expects a SourceMap but we pass it SourceMapGenerator and so causes errors, so maybe I should add SourceMap | SourceMapGenerator to that module declaration?

Copy link
Contributor Author

@letladi letladi Jul 15, 2019

Choose a reason for hiding this comment

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

I'm thinking something like this fromObject(obj: SourceMap | SourceMapGenerator). This works without errors.

Copy link
Member

Choose a reason for hiding this comment

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

I think that fromObject(obj: SourceMap) was correct, and it isn't intended to be called with a SourceMapGenerator object.
It should be .fromObject(map.toJSON()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I will make that change.

@nicolo-ribaudo nicolo-ribaudo added area: flow pkg: cli PR: Internal 🏠 A type of pull request used for our changelog categories labels Jul 15, 2019
@JLHwung
Copy link
Contributor

JLHwung commented Jul 18, 2019

@letladi Could you rebase your branch? Test fails because we have moved our fork of lerna into babel organization.

@letladi
Copy link
Contributor Author

letladi commented Jul 19, 2019

@JLHwung, will do.

letladi and others added 6 commits July 19, 2019 10:33
* removed duplicate tests for @babel/highlight getChalk method

* changed second 'getChalk' test case for when colors are not supported
* flow - allow type parameter defaults in function declarations

* fix flow test

* add intern_comments option

* fix flow parser test

* remove allowdefault from flowParseTypeParameterDeclaration

* rename test cases
@letladi
Copy link
Contributor Author

letladi commented Jul 19, 2019

Sorry, I'm still working on the rebase (haven't done this before)

@letladi
Copy link
Contributor Author

letladi commented Jul 19, 2019

I'm closing this. I will send in a new pull request shortly.
The rebasing is showing me flames. 🤦🏽‍♂️

@letladi letladi closed this Jul 19, 2019
@nicolo-ribaudo
Copy link
Member

I suggest squashing this commits before rebasing; it makes it easier to do.

@letladi
Copy link
Contributor Author

letladi commented Jul 19, 2019

I actually deleted everything. forked the repo again and added my changes; #10244

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: flow outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: cli PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants