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
Use all modifiers test
  • Loading branch information
DavidSouther authored May 11, 2022
1 parent e8216af commit a3e83be
Show file tree
Hide file tree
Showing 5 changed files with 112 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
23 changes: 23 additions & 0 deletions tests/baselines/reference/modifierParenCast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [modifierParenCast.ts]
let readonly: any = undefined;
let override: any = undefined;
let out: any = undefined;
let declare: any = undefined;

export const a = (readonly as number);
export const b = (override as number);
export const c = (out as number);
export const d = (declare as number);

//// [modifierParenCast.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.d = exports.c = exports.b = exports.a = void 0;
var readonly = undefined;
var override = undefined;
var out = undefined;
var declare = undefined;
exports.a = readonly;
exports.b = override;
exports.c = out;
exports.d = declare;
33 changes: 33 additions & 0 deletions tests/baselines/reference/modifierParenCast.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/compiler/modifierParenCast.ts ===
let readonly: any = undefined;
>readonly : Symbol(readonly, Decl(modifierParenCast.ts, 0, 3))
>undefined : Symbol(undefined)

let override: any = undefined;
>override : Symbol(override, Decl(modifierParenCast.ts, 1, 3))
>undefined : Symbol(undefined)

let out: any = undefined;
>out : Symbol(out, Decl(modifierParenCast.ts, 2, 3))
>undefined : Symbol(undefined)

let declare: any = undefined;
>declare : Symbol(declare, Decl(modifierParenCast.ts, 3, 3))
>undefined : Symbol(undefined)

export const a = (readonly as number);
>a : Symbol(a, Decl(modifierParenCast.ts, 5, 12))
>readonly : Symbol(readonly, Decl(modifierParenCast.ts, 0, 3))

export const b = (override as number);
>b : Symbol(b, Decl(modifierParenCast.ts, 6, 12))
>override : Symbol(override, Decl(modifierParenCast.ts, 1, 3))

export const c = (out as number);
>c : Symbol(c, Decl(modifierParenCast.ts, 7, 12))
>out : Symbol(out, Decl(modifierParenCast.ts, 2, 3))

export const d = (declare as number);
>d : Symbol(d, Decl(modifierParenCast.ts, 8, 12))
>declare : Symbol(declare, Decl(modifierParenCast.ts, 3, 3))

41 changes: 41 additions & 0 deletions tests/baselines/reference/modifierParenCast.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=== tests/cases/compiler/modifierParenCast.ts ===
let readonly: any = undefined;
>readonly : any
>undefined : undefined

let override: any = undefined;
>override : any
>undefined : undefined

let out: any = undefined;
>out : any
>undefined : undefined

let declare: any = undefined;
>declare : any
>undefined : undefined

export const a = (readonly as number);
>a : number
>(readonly as number) : number
>readonly as number : number
>readonly : any

export const b = (override as number);
>b : number
>(override as number) : number
>override as number : number
>override : any

export const c = (out as number);
>c : number
>(out as number) : number
>out as number : number
>out : any

export const d = (declare as number);
>d : number
>(declare as number) : number
>declare as number : number
>declare : any

11 changes: 11 additions & 0 deletions tests/cases/compiler/modifierParenCast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@target: ES5

let readonly: any = undefined;
let override: any = undefined;
let out: any = undefined;
let declare: any = undefined;

export const a = (readonly as number);
export const b = (override as number);
export const c = (out as number);
export const d = (declare as number);

0 comments on commit a3e83be

Please sign in to comment.