diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dd1e7f6431a7e..35536bb224628 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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; } diff --git a/tests/baselines/reference/modifierParenCast.js b/tests/baselines/reference/modifierParenCast.js new file mode 100644 index 0000000000000..d4026dcb3d4df --- /dev/null +++ b/tests/baselines/reference/modifierParenCast.js @@ -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; diff --git a/tests/baselines/reference/modifierParenCast.symbols b/tests/baselines/reference/modifierParenCast.symbols new file mode 100644 index 0000000000000..abf03d6c41a3e --- /dev/null +++ b/tests/baselines/reference/modifierParenCast.symbols @@ -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)) + diff --git a/tests/baselines/reference/modifierParenCast.types b/tests/baselines/reference/modifierParenCast.types new file mode 100644 index 0000000000000..09367b30fca30 --- /dev/null +++ b/tests/baselines/reference/modifierParenCast.types @@ -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 + diff --git a/tests/cases/compiler/modifierParenCast.ts b/tests/cases/compiler/modifierParenCast.ts new file mode 100644 index 0000000000000..c2b09f54b687e --- /dev/null +++ b/tests/cases/compiler/modifierParenCast.ts @@ -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); \ No newline at end of file