From 0ccf09c8b0208a0ef83522b433d8bb4a48bdb513 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 19:43:26 +0000 Subject: [PATCH 1/4] Initial plan From 5c5b8c28e694ca00c843511f5ba295f695fb7fcf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:02:53 +0000 Subject: [PATCH 2/4] Add regression coverage for assertion-erased unary exponentiation operands Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- ...ssion(erasablesyntaxonly=false).errors.txt | 103 +++++++++++++++++ ...ession(erasablesyntaxonly=true).errors.txt | 109 ++++++++++++++++++ ...exponentiationWithErasedUnaryExpression.ts | 84 ++++++++++++++ 3 files changed, 296 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt create mode 100644 tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt new file mode 100644 index 0000000000000..4c2d201fa09a4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt @@ -0,0 +1,103 @@ +invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(18,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(19,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(20,8): error TS2532: Object is possibly 'undefined'. +invalid.ts(21,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(31,19): error TS1005: ';' expected. +invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + + +==== invalid.ts (7 errors) ==== + export {}; + declare let x: any; + declare const obj: { p?: number }; + + // Assertions must not hide an invalid left operand of **. + -x ** 2; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2; + +x as any ** 2; + ~x as any ** 2; + !x as any ** 2; + typeof x as any ** 2; + void x as any ** 2; + delete obj.p as any ** 2; + + -x satisfies any ** 2; + +x satisfies any ** 2; + ~x satisfies any ** 2; + !x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + typeof x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + void x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + delete obj.p satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + + -x as any as number ** 2; + -x satisfies any satisfies number ** 2; + -x as any satisfies number ** 2; + -x satisfies any as number ** 2; + -(x) as number ** 2; + -x! satisfies number ** 2; + x as number ** 2; + -x satisfies number ** 2; + 2 ** -x as number ** 2; + ~~ +!!! error TS1005: ';' expected. + + async function invalidAwait() { + await x ** 2; + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + await x as number ** 2; + await x satisfies number ** 2; + await x as any as number ** 2; + await x satisfies any satisfies number ** 2; + await x as any satisfies number ** 2; + await x satisfies any as number ** 2; + } + +==== valid.ts (0 errors) ==== + export {}; + declare let x: any; + declare const obj: { p?: number }; + + // Parentheses, update expressions, and unary right operands remain valid. + (-x) as number ** 2; + (-x) satisfies number ** 2; + (-x as number) ** 2; + (-x satisfies number) ** 2; + (-x) as any satisfies number ** 2; + (+x) as number ** 2; + (~x) satisfies number ** 2; + (!x) as any ** 2; + (typeof x) as any ** 2; + (void x) as any ** 2; + (delete obj.p) as any ** 2; + x as number ** 2; + x! satisfies number ** 2; + ++x as number ** 2; + --x satisfies number ** 2; + x++ satisfies number ** 2; + x-- as number ** 2; + -x as number * 2; + 2 ** -x as number; + 2 ** (-x as number); + 2 ** (-x satisfies number); + + async function validAwait() { + (await x) as number ** 2; + (await x) satisfies number ** 2; + (await x as number) ** 2; + (await x satisfies number) ** 2; + (await x) satisfies any as number ** 2; + 2 ** await x as number; + } + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt new file mode 100644 index 0000000000000..1349cd2285e91 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt @@ -0,0 +1,109 @@ +invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(18,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(19,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(20,8): error TS2532: Object is possibly 'undefined'. +invalid.ts(21,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(29,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(30,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(31,19): error TS1005: ';' expected. +invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + + +==== invalid.ts (9 errors) ==== + export {}; + declare let x: any; + declare const obj: { p?: number }; + + // Assertions must not hide an invalid left operand of **. + -x ** 2; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2; + +x as any ** 2; + ~x as any ** 2; + !x as any ** 2; + typeof x as any ** 2; + void x as any ** 2; + delete obj.p as any ** 2; + + -x satisfies any ** 2; + +x satisfies any ** 2; + ~x satisfies any ** 2; + !x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + typeof x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + void x satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + delete obj.p satisfies any ** 2; + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + + -x as any as number ** 2; + -x satisfies any satisfies number ** 2; + -x as any satisfies number ** 2; + -x satisfies any as number ** 2; + -(x) as number ** 2; + -x! satisfies number ** 2; + x as number ** 2; + ~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + -x satisfies number ** 2; + ~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + 2 ** -x as number ** 2; + ~~ +!!! error TS1005: ';' expected. + + async function invalidAwait() { + await x ** 2; + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + await x as number ** 2; + await x satisfies number ** 2; + await x as any as number ** 2; + await x satisfies any satisfies number ** 2; + await x as any satisfies number ** 2; + await x satisfies any as number ** 2; + } + +==== valid.ts (0 errors) ==== + export {}; + declare let x: any; + declare const obj: { p?: number }; + + // Parentheses, update expressions, and unary right operands remain valid. + (-x) as number ** 2; + (-x) satisfies number ** 2; + (-x as number) ** 2; + (-x satisfies number) ** 2; + (-x) as any satisfies number ** 2; + (+x) as number ** 2; + (~x) satisfies number ** 2; + (!x) as any ** 2; + (typeof x) as any ** 2; + (void x) as any ** 2; + (delete obj.p) as any ** 2; + x as number ** 2; + x! satisfies number ** 2; + ++x as number ** 2; + --x satisfies number ** 2; + x++ satisfies number ** 2; + x-- as number ** 2; + -x as number * 2; + 2 ** -x as number; + 2 ** (-x as number); + 2 ** (-x satisfies number); + + async function validAwait() { + (await x) as number ** 2; + (await x) satisfies number ** 2; + (await x as number) ** 2; + (await x satisfies number) ** 2; + (await x) satisfies any as number ** 2; + 2 ** await x as number; + } + \ No newline at end of file diff --git a/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts b/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts new file mode 100644 index 0000000000000..e3acc99a93214 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts @@ -0,0 +1,84 @@ +// @target: esnext +// @erasableSyntaxOnly: false, true +// @noEmit: true +// @noTypesAndSymbols: true + +// @filename: invalid.ts +export {}; +declare let x: any; +declare const obj: { p?: number }; + +// Assertions must not hide an invalid left operand of **. +-x ** 2; +-x as any ** 2; ++x as any ** 2; +~x as any ** 2; +!x as any ** 2; +typeof x as any ** 2; +void x as any ** 2; +delete obj.p as any ** 2; + +-x satisfies any ** 2; ++x satisfies any ** 2; +~x satisfies any ** 2; +!x satisfies any ** 2; +typeof x satisfies any ** 2; +void x satisfies any ** 2; +delete obj.p satisfies any ** 2; + +-x as any as number ** 2; +-x satisfies any satisfies number ** 2; +-x as any satisfies number ** 2; +-x satisfies any as number ** 2; +-(x) as number ** 2; +-x! satisfies number ** 2; +x as number ** 2; +-x satisfies number ** 2; +2 ** -x as number ** 2; + +async function invalidAwait() { + await x ** 2; + await x as number ** 2; + await x satisfies number ** 2; + await x as any as number ** 2; + await x satisfies any satisfies number ** 2; + await x as any satisfies number ** 2; + await x satisfies any as number ** 2; +} + +// @filename: valid.ts +export {}; +declare let x: any; +declare const obj: { p?: number }; + +// Parentheses, update expressions, and unary right operands remain valid. +(-x) as number ** 2; +(-x) satisfies number ** 2; +(-x as number) ** 2; +(-x satisfies number) ** 2; +(-x) as any satisfies number ** 2; +(+x) as number ** 2; +(~x) satisfies number ** 2; +(!x) as any ** 2; +(typeof x) as any ** 2; +(void x) as any ** 2; +(delete obj.p) as any ** 2; +x as number ** 2; +x! satisfies number ** 2; +++x as number ** 2; +--x satisfies number ** 2; +x++ satisfies number ** 2; +x-- as number ** 2; +-x as number * 2; +2 ** -x as number; +2 ** (-x as number); +2 ** (-x satisfies number); + +async function validAwait() { + (await x) as number ** 2; + (await x) satisfies number ** 2; + (await x as number) ** 2; + (await x satisfies number) ** 2; + (await x) satisfies any as number ** 2; + 2 ** await x as number; +} From f3a7e6480cc0fb19e1f0e2a2c9a802aca9f701d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:17:30 +0000 Subject: [PATCH 3/4] Reject assertion erasure exposing unary exponentiation operands Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- tsc/internal/parser/parser.go | 10 +- ...ssion(erasablesyntaxonly=false).errors.txt | 98 ++++++++++++++++--- ...ession(erasablesyntaxonly=true).errors.txt | 98 ++++++++++++++++--- 3 files changed, 179 insertions(+), 27 deletions(-) diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go index b1c20ccf6109c..c14f8ba86191a 100644 --- a/tsc/internal/parser/parser.go +++ b/tsc/internal/parser/parser.go @@ -4768,8 +4768,16 @@ func (p *Parser) parseBinaryExpressionRest(precedence ast.OperatorPrecedence, le // are binary operators, we want to stop parsing when $$ would bind before ## after erasing the // assertion. See https://github.com/microsoft/TypeScript/issues/63527. lastPrecedence := ast.OperatorPrecedenceHighest - if ast.IsBinaryExpression(lastOperand) { + // Unary expressions cannot be exposed on the left of '**', but update expressions can. + switch lastOperand.Kind { + case ast.KindBinaryExpression: lastPrecedence = ast.GetBinaryOperatorPrecedence(lastOperand.AsBinaryExpression().OperatorToken.Kind) + case ast.KindPrefixUnaryExpression: + if op := lastOperand.AsPrefixUnaryExpression().Operator; op != ast.KindPlusPlusToken && op != ast.KindMinusMinusToken { + lastPrecedence = ast.OperatorPrecedenceExponentiation + } + case ast.KindDeleteExpression, ast.KindTypeOfExpression, ast.KindVoidExpression, ast.KindAwaitExpression, ast.KindTypeAssertionExpression: + lastPrecedence = ast.OperatorPrecedenceExponentiation } if operator == ast.KindSatisfiesKeyword { leftOperand = p.makeSatisfiesExpression(leftOperand, p.parseType()) diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt index 4c2d201fa09a4..08fd9a4c5341d 100644 --- a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt @@ -1,13 +1,37 @@ invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(18,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -invalid.ts(19,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -invalid.ts(20,8): error TS2532: Object is possibly 'undefined'. -invalid.ts(21,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(7,11): error TS1005: ';' expected. +invalid.ts(8,11): error TS1005: ';' expected. +invalid.ts(9,11): error TS1005: ';' expected. +invalid.ts(10,11): error TS1005: ';' expected. +invalid.ts(11,17): error TS1005: ';' expected. +invalid.ts(12,15): error TS1005: ';' expected. +invalid.ts(13,21): error TS1005: ';' expected. +invalid.ts(15,18): error TS1005: ';' expected. +invalid.ts(16,18): error TS1005: ';' expected. +invalid.ts(17,18): error TS1005: ';' expected. +invalid.ts(18,18): error TS1005: ';' expected. +invalid.ts(19,24): error TS1005: ';' expected. +invalid.ts(20,22): error TS1005: ';' expected. +invalid.ts(21,28): error TS1005: ';' expected. +invalid.ts(23,21): error TS1005: ';' expected. +invalid.ts(24,35): error TS1005: ';' expected. +invalid.ts(25,28): error TS1005: ';' expected. +invalid.ts(26,28): error TS1005: ';' expected. +invalid.ts(27,16): error TS1005: ';' expected. +invalid.ts(28,22): error TS1005: ';' expected. +invalid.ts(29,21): error TS1005: ';' expected. +invalid.ts(30,29): error TS1005: ';' expected. invalid.ts(31,19): error TS1005: ';' expected. invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(35,23): error TS1005: ';' expected. +invalid.ts(36,30): error TS1005: ';' expected. +invalid.ts(37,30): error TS1005: ';' expected. +invalid.ts(38,44): error TS1005: ';' expected. +invalid.ts(39,37): error TS1005: ';' expected. +invalid.ts(40,37): error TS1005: ';' expected. -==== invalid.ts (7 errors) ==== +==== invalid.ts (31 errors) ==== export {}; declare let x: any; declare const obj: { p?: number }; @@ -17,37 +41,73 @@ invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator i ~~ !!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x as any ** 2; + ~~ +!!! error TS1005: ';' expected. +x as any ** 2; + ~~ +!!! error TS1005: ';' expected. ~x as any ** 2; + ~~ +!!! error TS1005: ';' expected. !x as any ** 2; + ~~ +!!! error TS1005: ';' expected. typeof x as any ** 2; + ~~ +!!! error TS1005: ';' expected. void x as any ** 2; + ~~ +!!! error TS1005: ';' expected. delete obj.p as any ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. +x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. ~x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. !x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. typeof x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. void x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~ +!!! error TS1005: ';' expected. delete obj.p satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. -x as any as number ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. -x as any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any as number ** 2; + ~~ +!!! error TS1005: ';' expected. -(x) as number ** 2; + ~~ +!!! error TS1005: ';' expected. -x! satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. x as number ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. 2 ** -x as number ** 2; ~~ !!! error TS1005: ';' expected. @@ -57,11 +117,23 @@ invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator i ~~~~~~~ !!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x as any as number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x as any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies any as number ** 2; + ~~ +!!! error TS1005: ';' expected. } ==== valid.ts (0 errors) ==== diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt index 1349cd2285e91..22049f130e174 100644 --- a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt @@ -1,15 +1,39 @@ invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(18,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -invalid.ts(19,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -invalid.ts(20,8): error TS2532: Object is possibly 'undefined'. -invalid.ts(21,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(7,11): error TS1005: ';' expected. +invalid.ts(8,11): error TS1005: ';' expected. +invalid.ts(9,11): error TS1005: ';' expected. +invalid.ts(10,11): error TS1005: ';' expected. +invalid.ts(11,17): error TS1005: ';' expected. +invalid.ts(12,15): error TS1005: ';' expected. +invalid.ts(13,21): error TS1005: ';' expected. +invalid.ts(15,18): error TS1005: ';' expected. +invalid.ts(16,18): error TS1005: ';' expected. +invalid.ts(17,18): error TS1005: ';' expected. +invalid.ts(18,18): error TS1005: ';' expected. +invalid.ts(19,24): error TS1005: ';' expected. +invalid.ts(20,22): error TS1005: ';' expected. +invalid.ts(21,28): error TS1005: ';' expected. +invalid.ts(23,21): error TS1005: ';' expected. +invalid.ts(24,35): error TS1005: ';' expected. +invalid.ts(25,28): error TS1005: ';' expected. +invalid.ts(26,28): error TS1005: ';' expected. +invalid.ts(27,16): error TS1005: ';' expected. +invalid.ts(28,22): error TS1005: ';' expected. invalid.ts(29,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(29,21): error TS1005: ';' expected. invalid.ts(30,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(30,29): error TS1005: ';' expected. invalid.ts(31,19): error TS1005: ';' expected. invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(35,23): error TS1005: ';' expected. +invalid.ts(36,30): error TS1005: ';' expected. +invalid.ts(37,30): error TS1005: ';' expected. +invalid.ts(38,44): error TS1005: ';' expected. +invalid.ts(39,37): error TS1005: ';' expected. +invalid.ts(40,37): error TS1005: ';' expected. -==== invalid.ts (9 errors) ==== +==== invalid.ts (33 errors) ==== export {}; declare let x: any; declare const obj: { p?: number }; @@ -19,41 +43,77 @@ invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator i ~~ !!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x as any ** 2; + ~~ +!!! error TS1005: ';' expected. +x as any ** 2; + ~~ +!!! error TS1005: ';' expected. ~x as any ** 2; + ~~ +!!! error TS1005: ';' expected. !x as any ** 2; + ~~ +!!! error TS1005: ';' expected. typeof x as any ** 2; + ~~ +!!! error TS1005: ';' expected. void x as any ** 2; + ~~ +!!! error TS1005: ';' expected. delete obj.p as any ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. +x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. ~x satisfies any ** 2; + ~~ +!!! error TS1005: ';' expected. !x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. typeof x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. void x satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. + ~~ +!!! error TS1005: ';' expected. delete obj.p satisfies any ** 2; - ~~~~~~~~~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS1005: ';' expected. -x as any as number ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. -x as any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. -x satisfies any as number ** 2; + ~~ +!!! error TS1005: ';' expected. -(x) as number ** 2; + ~~ +!!! error TS1005: ';' expected. -x! satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. x as number ** 2; ~~~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + ~~ +!!! error TS1005: ';' expected. -x satisfies number ** 2; ~~~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + ~~ +!!! error TS1005: ';' expected. 2 ** -x as number ** 2; ~~ !!! error TS1005: ';' expected. @@ -63,11 +123,23 @@ invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator i ~~~~~~~ !!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x as any as number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x as any satisfies number ** 2; + ~~ +!!! error TS1005: ';' expected. await x satisfies any as number ** 2; + ~~ +!!! error TS1005: ';' expected. } ==== valid.ts (0 errors) ==== From b64beb298613f85f4a6264f63057efff7baaf57a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:57:55 +0000 Subject: [PATCH 4/4] Use unary exponentiation diagnostics through assertion chains Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- tsc/internal/parser/parser.go | 38 ++- ...ssion(erasablesyntaxonly=false).errors.txt | 235 ++++++++++------- ...ession(erasablesyntaxonly=true).errors.txt | 242 +++++++++++------- ...exponentiationWithErasedUnaryExpression.ts | 10 + 4 files changed, 338 insertions(+), 187 deletions(-) diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go index c14f8ba86191a..db1bb03defb8c 100644 --- a/tsc/internal/parser/parser.go +++ b/tsc/internal/parser/parser.go @@ -4768,16 +4768,25 @@ func (p *Parser) parseBinaryExpressionRest(precedence ast.OperatorPrecedence, le // are binary operators, we want to stop parsing when $$ would bind before ## after erasing the // assertion. See https://github.com/microsoft/TypeScript/issues/63527. lastPrecedence := ast.OperatorPrecedenceHighest + unaryOperator := ast.KindUnknown // Unary expressions cannot be exposed on the left of '**', but update expressions can. switch lastOperand.Kind { case ast.KindBinaryExpression: lastPrecedence = ast.GetBinaryOperatorPrecedence(lastOperand.AsBinaryExpression().OperatorToken.Kind) case ast.KindPrefixUnaryExpression: if op := lastOperand.AsPrefixUnaryExpression().Operator; op != ast.KindPlusPlusToken && op != ast.KindMinusMinusToken { - lastPrecedence = ast.OperatorPrecedenceExponentiation + unaryOperator = op } - case ast.KindDeleteExpression, ast.KindTypeOfExpression, ast.KindVoidExpression, ast.KindAwaitExpression, ast.KindTypeAssertionExpression: - lastPrecedence = ast.OperatorPrecedenceExponentiation + case ast.KindDeleteExpression: + unaryOperator = ast.KindDeleteKeyword + case ast.KindTypeOfExpression: + unaryOperator = ast.KindTypeOfKeyword + case ast.KindVoidExpression: + unaryOperator = ast.KindVoidKeyword + case ast.KindAwaitExpression: + unaryOperator = ast.KindAwaitKeyword + case ast.KindTypeAssertionExpression: + unaryOperator = ast.KindLessThanToken } if operator == ast.KindSatisfiesKeyword { leftOperand = p.makeSatisfiesExpression(leftOperand, p.parseType()) @@ -4787,6 +4796,9 @@ func (p *Parser) parseBinaryExpressionRest(precedence ast.OperatorPrecedence, le // Stop if the next operator would bind before the last operator when the assertion is erased. nextOperator := p.reScanGreaterThanToken() nextPrecedence := ast.GetBinaryOperatorPrecedence(nextOperator) + if nextOperator == ast.KindAsteriskAsteriskToken && unaryOperator != ast.KindUnknown { + p.reportInvalidExponentiationLeftOperand(lastOperand, unaryOperator) + } if shouldConsumeBinaryOperator(nextOperator, nextPrecedence, lastPrecedence) { break } @@ -4838,18 +4850,22 @@ func (p *Parser) parseUnaryExpressionOrHigher() *ast.Expression { unaryOperator := p.token simpleUnaryExpression := p.parseSimpleUnaryExpression() if p.token == ast.KindAsteriskAsteriskToken { - pos := scanner.SkipTrivia(p.sourceText, simpleUnaryExpression.Pos()) - end := simpleUnaryExpression.End() - if simpleUnaryExpression.Kind == ast.KindTypeAssertionExpression { - p.parseErrorAt(pos, end, diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses) - } else { - debug.Assert(isKeywordOrPunctuation(unaryOperator)) - p.parseErrorAt(pos, end, diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, scanner.TokenToString(unaryOperator)) - } + p.reportInvalidExponentiationLeftOperand(simpleUnaryExpression, unaryOperator) } return simpleUnaryExpression } +func (p *Parser) reportInvalidExponentiationLeftOperand(expression *ast.Expression, unaryOperator ast.Kind) { + pos := scanner.SkipTrivia(p.sourceText, expression.Pos()) + end := expression.End() + if expression.Kind == ast.KindTypeAssertionExpression { + p.parseErrorAt(pos, end, diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses) + } else { + debug.Assert(isKeywordOrPunctuation(unaryOperator)) + p.parseErrorAt(pos, end, diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, scanner.TokenToString(unaryOperator)) + } +} + func (p *Parser) isUpdateExpression() bool { switch p.token { case ast.KindPlusToken, ast.KindMinusToken, ast.KindTildeToken, ast.KindExclamationToken, ast.KindDeleteKeyword, ast.KindTypeOfKeyword, ast.KindVoidKeyword, ast.KindAwaitKeyword: diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt index 08fd9a4c5341d..412c15fcacd0c 100644 --- a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=false).errors.txt @@ -1,37 +1,54 @@ invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(7,11): error TS1005: ';' expected. -invalid.ts(8,11): error TS1005: ';' expected. -invalid.ts(9,11): error TS1005: ';' expected. -invalid.ts(10,11): error TS1005: ';' expected. -invalid.ts(11,17): error TS1005: ';' expected. -invalid.ts(12,15): error TS1005: ';' expected. -invalid.ts(13,21): error TS1005: ';' expected. -invalid.ts(15,18): error TS1005: ';' expected. -invalid.ts(16,18): error TS1005: ';' expected. -invalid.ts(17,18): error TS1005: ';' expected. -invalid.ts(18,18): error TS1005: ';' expected. -invalid.ts(19,24): error TS1005: ';' expected. -invalid.ts(20,22): error TS1005: ';' expected. -invalid.ts(21,28): error TS1005: ';' expected. -invalid.ts(23,21): error TS1005: ';' expected. -invalid.ts(24,35): error TS1005: ';' expected. -invalid.ts(25,28): error TS1005: ';' expected. -invalid.ts(26,28): error TS1005: ';' expected. -invalid.ts(27,16): error TS1005: ';' expected. -invalid.ts(28,22): error TS1005: ';' expected. -invalid.ts(29,21): error TS1005: ';' expected. -invalid.ts(30,29): error TS1005: ';' expected. -invalid.ts(31,19): error TS1005: ';' expected. -invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(35,23): error TS1005: ';' expected. -invalid.ts(36,30): error TS1005: ';' expected. -invalid.ts(37,30): error TS1005: ';' expected. -invalid.ts(38,44): error TS1005: ';' expected. -invalid.ts(39,37): error TS1005: ';' expected. -invalid.ts(40,37): error TS1005: ';' expected. +invalid.ts(7,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(8,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(9,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(9,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(10,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(11,1): error TS2532: Object is possibly 'undefined'. +invalid.ts(11,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(12,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(13,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(15,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(16,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(17,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(18,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(19,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(20,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(21,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(23,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(24,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(25,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(26,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(26,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(27,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(27,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(28,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(28,8): error TS2532: Object is possibly 'undefined'. +invalid.ts(29,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(29,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(31,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(32,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(33,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(34,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(35,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(36,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(37,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(38,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(39,17): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(40,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(41,19): error TS1005: ';' expected. +invalid.ts(44,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(45,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(46,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(47,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(48,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(49,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(50,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -==== invalid.ts (31 errors) ==== +==== invalid.ts (48 errors) ==== export {}; declare let x: any; declare const obj: { p?: number }; @@ -40,74 +57,118 @@ invalid.ts(40,37): error TS1005: ';' expected. -x ** 2; ~~ !!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + +x ** 2; + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~x ** 2; + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + !x ** 2; + ~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + typeof x ** 2; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + void x ** 2; + ~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + delete obj.p ** 2; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + x ** 2; + ~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. !x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. typeof x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. void x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. delete obj.p as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. !x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. typeof x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. void x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. delete obj.p satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -x as any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x as any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -(x) as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x! satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. x as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + const negated = -x as any ** 2; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2 ** 3; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. 2 ** -x as number ** 2; ~~ !!! error TS1005: ';' expected. @@ -117,23 +178,23 @@ invalid.ts(40,37): error TS1005: ';' expected. ~~~~~~~ !!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. } ==== valid.ts (0 errors) ==== diff --git a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt index 22049f130e174..fd19c9417b1ec 100644 --- a/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/exponentiationWithErasedUnaryExpression(erasablesyntaxonly=true).errors.txt @@ -1,39 +1,57 @@ invalid.ts(6,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(7,11): error TS1005: ';' expected. -invalid.ts(8,11): error TS1005: ';' expected. -invalid.ts(9,11): error TS1005: ';' expected. -invalid.ts(10,11): error TS1005: ';' expected. -invalid.ts(11,17): error TS1005: ';' expected. -invalid.ts(12,15): error TS1005: ';' expected. -invalid.ts(13,21): error TS1005: ';' expected. -invalid.ts(15,18): error TS1005: ';' expected. -invalid.ts(16,18): error TS1005: ';' expected. -invalid.ts(17,18): error TS1005: ';' expected. -invalid.ts(18,18): error TS1005: ';' expected. -invalid.ts(19,24): error TS1005: ';' expected. -invalid.ts(20,22): error TS1005: ';' expected. -invalid.ts(21,28): error TS1005: ';' expected. -invalid.ts(23,21): error TS1005: ';' expected. -invalid.ts(24,35): error TS1005: ';' expected. -invalid.ts(25,28): error TS1005: ';' expected. -invalid.ts(26,28): error TS1005: ';' expected. -invalid.ts(27,16): error TS1005: ';' expected. -invalid.ts(28,22): error TS1005: ';' expected. -invalid.ts(29,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -invalid.ts(29,21): error TS1005: ';' expected. -invalid.ts(30,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -invalid.ts(30,29): error TS1005: ';' expected. -invalid.ts(31,19): error TS1005: ';' expected. -invalid.ts(34,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -invalid.ts(35,23): error TS1005: ';' expected. -invalid.ts(36,30): error TS1005: ';' expected. -invalid.ts(37,30): error TS1005: ';' expected. -invalid.ts(38,44): error TS1005: ';' expected. -invalid.ts(39,37): error TS1005: ';' expected. -invalid.ts(40,37): error TS1005: ';' expected. +invalid.ts(7,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(8,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(9,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(9,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(10,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(10,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(11,1): error TS2532: Object is possibly 'undefined'. +invalid.ts(11,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(12,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(12,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(13,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(13,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(15,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(16,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(17,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(18,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(19,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(20,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(21,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(23,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(24,1): error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(25,1): error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(26,1): error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(26,4): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(27,1): error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(27,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(28,1): error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(28,8): error TS2532: Object is possibly 'undefined'. +invalid.ts(29,1): error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(29,14): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +invalid.ts(31,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(32,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(33,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(34,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(35,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(36,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(37,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(37,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(38,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +invalid.ts(38,1): error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(39,17): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(40,1): error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(41,19): error TS1005: ';' expected. +invalid.ts(44,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(45,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(46,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(47,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(48,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(49,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +invalid.ts(50,5): error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -==== invalid.ts (33 errors) ==== +==== invalid.ts (51 errors) ==== export {}; declare let x: any; declare const obj: { p?: number }; @@ -42,78 +60,124 @@ invalid.ts(40,37): error TS1005: ';' expected. -x ** 2; ~~ !!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + +x ** 2; + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~x ** 2; + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + !x ** 2; + ~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + typeof x ** 2; + ~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + void x ** 2; + ~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + delete obj.p ** 2; + ~~~~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + x ** 2; + ~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + ~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. !x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. typeof x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. void x as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. delete obj.p as any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. +x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '+' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. ~x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '~' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. !x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '!' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. typeof x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS17006: An unary expression with the 'typeof' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. void x satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~ +!!! error TS17006: An unary expression with the 'void' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. delete obj.p satisfies any ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~~~ +!!! error TS17006: An unary expression with the 'delete' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -x as any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x as any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -(x) as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x! satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. x as number ** 2; ~~~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. -x satisfies number ** 2; ~~~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~~~~ +!!! error TS17007: A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + const negated = -x as any ** 2; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. + -x as any ** 2 ** 3; + ~~ +!!! error TS17006: An unary expression with the '-' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. 2 ** -x as number ** 2; ~~ !!! error TS1005: ';' expected. @@ -123,23 +187,23 @@ invalid.ts(40,37): error TS1005: ';' expected. ~~~~~~~ !!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x as any satisfies number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. await x satisfies any as number ** 2; - ~~ -!!! error TS1005: ';' expected. + ~~~~~~~ +!!! error TS17006: An unary expression with the 'await' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses. } ==== valid.ts (0 errors) ==== diff --git a/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts b/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts index e3acc99a93214..503891b12a048 100644 --- a/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts +++ b/tsc/testdata/tests/cases/compiler/exponentiationWithErasedUnaryExpression.ts @@ -10,6 +10,14 @@ declare const obj: { p?: number }; // Assertions must not hide an invalid left operand of **. -x ** 2; ++x ** 2; +~x ** 2; +!x ** 2; +typeof x ** 2; +void x ** 2; +delete obj.p ** 2; +x ** 2; + -x as any ** 2; +x as any ** 2; ~x as any ** 2; @@ -34,6 +42,8 @@ delete obj.p satisfies any ** 2; -x! satisfies number ** 2; x as number ** 2; -x satisfies number ** 2; +const negated = -x as any ** 2; +-x as any ** 2 ** 3; 2 ** -x as number ** 2; async function invalidAwait() {