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

Parse error when constructor argument has negative number default value #522

Closed
dishuostec opened this issue Apr 13, 2020 · 2 comments · Fixed by #531
Closed

Parse error when constructor argument has negative number default value #522

dishuostec opened this issue Apr 13, 2020 · 2 comments · Fixed by #531

Comments

@dishuostec
Copy link

This code will produce an error Expected identifier after access modifiers in constructor arg.:

export class Foo {
	constructor({ p = -1 }: { p?: number }) {

	}
}

see https://sucrase.io/#selectedTransforms=typescript&code=export%20class%20Foo%20%7B%0A%09constructor(%7B%20p%20%3D%20-1%20%7D%3A%20%7B%20p%3A%20number%20%7D)%20%7B%0A%0A%09%7D%0A%7D

@alangpierce
Copy link
Owner

Thanks for the report! Looks like it's misinterpreting the - as a flow access modifier. I've got a fix working and I should be able to release it soon.

alangpierce added a commit that referenced this issue May 10, 2020
Fixes #522

Previously, the logic to compile TS constructor param assignments walked through
all tokens in the constructor looking for access modifiers, but this can cause
problems if default values include access modifiers. Now, we mark commas
associated with the constructor and only emit assignments when we see an
open-paren or comma followed by an access modifier.
alangpierce added a commit that referenced this issue May 10, 2020
#531)

Fixes #522

Previously, the logic to compile TS constructor param assignments walked through
all tokens in the constructor looking for access modifiers, but this can cause
problems if default values include access modifiers. Now, we mark commas
associated with the constructor and only emit assignments when we see an
open-paren or comma followed by an access modifier.
@alangpierce
Copy link
Owner

This is fixed now in Sucrase 3.14.0.

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

Successfully merging a pull request may close this issue.

2 participants