From 3dd9ef43ce489526e7284d170afec831147ae655 Mon Sep 17 00:00:00 2001 From: David Souther Date: Mon, 9 May 2022 10:22:22 -0700 Subject: [PATCH] fix(44466): Fixes parsing contextual keyword casts as arrow functions --- src/compiler/parser.ts | 4 ++++ tests/baselines/reference/overrideParenVariable.js | 8 ++++++++ tests/baselines/reference/overrideParenVariable.symbols | 0 tests/baselines/reference/overrideParenVariable.types | 0 tests/cases/compiler/readonlyParenCast.ts | 5 +++++ 5 files changed, 17 insertions(+) create mode 100644 tests/baselines/reference/overrideParenVariable.js create mode 100644 tests/baselines/reference/overrideParenVariable.symbols create mode 100644 tests/baselines/reference/overrideParenVariable.types create mode 100644 tests/cases/compiler/readonlyParenCast.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dd1e7f6431a..35536bb2246 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/overrideParenVariable.js b/tests/baselines/reference/overrideParenVariable.js new file mode 100644 index 00000000000..22eb85b7c31 --- /dev/null +++ b/tests/baselines/reference/overrideParenVariable.js @@ -0,0 +1,8 @@ +//// [overrideParenVariable.ts] + +let override: any; +export const a = (override as number); + +//// [overrideParenVariable.js] + +export const a = override; diff --git a/tests/baselines/reference/overrideParenVariable.symbols b/tests/baselines/reference/overrideParenVariable.symbols new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/baselines/reference/overrideParenVariable.types b/tests/baselines/reference/overrideParenVariable.types new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/cases/compiler/readonlyParenCast.ts b/tests/cases/compiler/readonlyParenCast.ts new file mode 100644 index 00000000000..b89372d3924 --- /dev/null +++ b/tests/cases/compiler/readonlyParenCast.ts @@ -0,0 +1,5 @@ +//@target: ES5 + +let readonly: any; + +export const a = (readonly as number); \ No newline at end of file