benjamn / benjamn/recast

TypeScript: cannot parse decorator + generator syntax

Open
#569 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
363
Avg merge
3d 8h
Merged PRs (30d)
3

Description

Howdy!
Thanks for creating recast 🙇
I found it troublesome to parse a code like this:
```typescript
export default class DocumentsService {
@abc({ on: 'init' })
*loadEndpoint() {
yield 'abc';
return 'foo';
};
};
```
The error is `SyntaxError: Unexpected token (3:16)`
A workaround is to explicitly declare the method as public

```typescript
export default class DocumentsService {
@abc({ on: 'init' })
public *loadEndpoint() {
yield 'abc';
return 'foo';
};
};
```

I created [a repository with minimal failing example](https://github.com/maciejmyslinski/recast-issue) so that you an try it out yourself.

I thought those issues with babel might be connected:
* https://github.com/babel/babel/issues/5704
* https://github.com/babel/babylon/issues/13

But they claimed this is fixed so I decided to report it here first.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the TypeScript snippet in the linked minimal failing example, then compare it with the version that adds the public modifier. Trace the parsing entry point that reports the unexpected token; done means the decorator-plus-generator example parses successfully without requiring public.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.