Skip to content

Flow: Return type annotations not supported on arrow functions #29

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

Closed
clark-pan opened this issue Apr 12, 2018 · 7 comments
Closed

Flow: Return type annotations not supported on arrow functions #29

clark-pan opened this issue Apr 12, 2018 · 7 comments
Labels

Comments

@clark-pan
Copy link

clark-pan commented Apr 12, 2018

screen shot 2018-04-12 at 2 13 06 pm

As an aside, sorry for the issue spam over the last few days. I'm really liking this package so far.

@Thom1729 Thom1729 added the bug label Apr 12, 2018
@Thom1729
Copy link
Owner

As an aside, sorry for the issue spam over the last few days.

The more the better! The bugs are out there, and I can't fix them if I don't know about them.

Unfortunately, this is another case where perfect parsing is impossible. The current syntax uses an imperfect lookahead to detect arrow functions. We can (and should) modify that lookahead to account for type annotations. However, since type annotations can involve arbitrarily complex expressions, it won't be perfect.

I might not get to this for a few days, as I'll be travelling.

@Thom1729 Thom1729 changed the title Annotating the return type of an Arrow function removes syntax highlighting Flow: Return type annotations not supported on arrow functions May 9, 2018
@Thom1729
Copy link
Owner

I've just released version 1.0.18, which handles simple return type declarations.

@neutraali
Copy link

I've just released version 1.0.18, which handles simple return type declarations.

Is this in effect (1.0.19)? I'm assuming "simple return types" refer to, for example, primitives.

// Syntax highlighting OK
value = () => {
	// Do stuff
	return this._input.value;
}
// Syntax highlighting not OK
value = (): string => {
	// Do stuff
	return this._input.value;
}

@Thom1729
Copy link
Owner

Thom1729 commented Jun 1, 2018

It works for me. Try rebuilding your syntaxes.

I'm assuming "simple return types" refer to, for example, primitives.

Yes, single identifiers in general.

@neutraali
Copy link

neutraali commented Jun 8, 2018

Might be a bit of an edge-case, but the return type declarations seem to break string templates with substitutions for some reason (class context):

export default class Foo {
	// Highlighting OK
	bar = (you: string = 'World') => {
		return `Hello ${you}! ${'Welcome!'}`;
	}
	// Highlighting broken beyond this
	baz = (you: string = 'World'): string => {
		return `Hello ${you}! ${'Welcome!'}`;
	}
}

@Thom1729
Copy link
Owner

Thom1729 commented Jun 8, 2018

It's misparsing string => ... as a function type, and everything after that is breaking. I'll have to figure out what the right algorithm is for that. (Unfortunately, the Flow docs are very vague on syntax issues.)

@Thom1729
Copy link
Owner

Should be fully working by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants