Skip to content

Commit

Permalink
fix(44466): Fixes parsing contextual keyword casts as arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed May 9, 2022
1 parent 1071240 commit 3dd9ef4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4538,6 +4538,10 @@ namespace ts {
// isn't actually allowed, but we want to treat it as a lambda so we can provide
// a good error message.
if (isModifierKind(second) && second !== SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsIdentifier)) {
if (lookAhead(() => nextToken() === SyntaxKind.AsKeyword)) {
// https://github.com/microsoft/TypeScript/issues/44466
return Tristate.False;
}
return Tristate.True;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/overrideParenVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [overrideParenVariable.ts]

let override: any;
export const a = (override as number);

//// [overrideParenVariable.js]

export const a = override;
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions tests/cases/compiler/readonlyParenCast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@target: ES5

let readonly: any;

export const a = (readonly as number);

0 comments on commit 3dd9ef4

Please sign in to comment.