Skip to content

factory: createBinary doesn't parenthesise unary expression as LHS of exponentiation #25221

Description

TypeScript Version: 3.0.0-dev.20180621

Search Terms:

Code

import * as ts from 'typescript';
const n = ts.createBinary(ts.createPrefix(ts.SyntaxKind.MinusToken, ts.createNumericLiteral('1')), ts.SyntaxKind.AsteriskAsteriskToken, ts.createNumericLiteral('2'));
ts.createPrinter().printNode(ts.EmitHint.Unspecified, n, ts.createSourceFile('dummy.ts', '', ts.ScriptTarget.Latest));

Expected behavior:

(-1) ** 2

This should work for all unary expressions: AwaitExpression, PrefixUnaryExpression, VoidExpression, DeleteExpression, TypeOfExpression
These already work as expected: TypeAssertionExpression, YieldExpression

Actual behavior:

Invalid code, this is a syntax error: -1 ** 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions