-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Description
When a decorator appears immediately after a TypeScript-only declaration such as a type or interface, the parser throws a syntax error — even though this is perfectly valid TypeScript syntax.
This seems to happen because the parser doesn’t correctly reset its internal state after handling a type-only declaration, so the next @ token is misinterpreted.
Reproduction
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
type User = {
id: number;
name: string;
email: string;
}
@Injectable({
providedIn: 'root', // makes the service available app-wide
})
export class UserService {
private apiUrl = 'https://jsonplaceholder.typicode.com/users';
constructor(private http: HttpClient) {}
// Fetch all users
getUsers(): Observable<User[]> {
return this.http.get<User[]>(this.apiUrl);
}
// Fetch a single user by ID
getUserById(id: number): Observable<User> {
return this.http.get<User>(`${this.apiUrl}/${id}`);
}
}Output
Failed to parse source code: Unexpected character '@' (11:0)
Expected
The code should parse successfully. This is valid TypeScript and compiles fine in the TypeScript compiler and Babel’s TypeScript parser.
Environment
Node: 20.x
"acorn": "^8.15.0",
"@sveltejs/acorn-typescript": "^1.0.6"
Metadata
Metadata
Assignees
Labels
No labels