Parser chokes on TypeScript method #48

Closed
opened 2025-09-18 13:33:46 +02:00 by bmeurer · 3 comments
bmeurer commented 2025-09-18 13:33:46 +02:00 (Migrated from github.com)

In the context of crbug.com/445874747 I realized that the TypeScript grammar seems to choke on some perfectly valid TypeScript: I minimized it to this already.

In the context of [crbug.com/445874747](http://crbug.com/445874747) I realized that the TypeScript grammar seems to choke on some perfectly valid TypeScript: I minimized it to [this](https://codemirror.net/try/#c=aW1wb3J0IHtiYXNpY1NldHVwLCBFZGl0b3JWaWV3fSBmcm9tICJjb2RlbWlycm9yIgppbXBvcnQge2phdmFzY3JpcHR9IGZyb20gIkBjb2RlbWlycm9yL2xhbmctamF2YXNjcmlwdCIKCm5ldyBFZGl0b3JWaWV3KHsKICBkb2M6ICJjb25zb2xlLmxvZygnaGVsbG8nKVxuIiwKICBleHRlbnNpb25zOiBbYmFzaWNTZXR1cCwgamF2YXNjcmlwdCh7dHlwZXNjcmlwdDogdHJ1ZX0pXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSkK) already.
bmeurer commented 2025-09-18 13:35:09 +02:00 (Migrated from github.com)

Oh, just realized that the copied URL from the playground doesn't include the contents 👀 , so here's the TypeScript:

class X {
  initialize(
      completions: (this: X, expression: string) => Promise<T[]>,    stopCharacters?: string): void {
    this.loadCompletions = completions;
    this.completionStopCharacters = stopCharacters || ' =:[({;,!+-*/&|^<>.';
    this.usesSuggestionBuilder = usesSuggestionBuilder || false;
  }
}
Oh, just realized that the copied URL from the playground doesn't include the contents 👀 , so here's the TypeScript: ```typescript class X { initialize( completions: (this: X, expression: string) => Promise<T[]>, stopCharacters?: string): void { this.loadCompletions = completions; this.completionStopCharacters = stopCharacters || ' =:[({;,!+-*/&|^<>.'; this.usesSuggestionBuilder = usesSuggestionBuilder || false; } } ```
marijnh commented 2025-09-18 14:16:24 +02:00 (Migrated from github.com)

The issue was the this in the parameter list of the function type. Attached patch should help.

The issue was the `this` in the parameter list of the function type. Attached patch should help.
bmeurer commented 2025-10-01 12:32:48 +02:00 (Migrated from github.com)

Thanks!

Thanks!
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/javascript#48
No description provided.