Skip to content

factory: createExportAssignment doesn't parenthesise all expressions with parsing restrictionsΒ #25222

@ajafff

Description

@ajafff

TypeScript Version: 3.0.0-dev.20180621

Search Terms:

Code

import * as ts from 'typescript';
const n = ts.createExportAssignment(
            undefined,
            undefined,
            false,
            ts.createPropertyAccess(
                ts.createClassExpression(
                    undefined,
                    undefined,
                    undefined,
                    undefined,
                    [ts.createProperty(undefined, [ts.createToken(ts.SyntaxKind.StaticKeyword)], 'prop', undefined, undefined, ts.createLiteral('1'))],
                ),
                'prop',
            ),
        );
ts.createPrinter().printNode(ts.EmitHint.Unspecified, n, ts.createSourceFile('dummy.ts', '', ts.ScriptTarget.Latest));

Expected behavior:

export default (class {static prop = '1'}.prop);

Note that this also applies to export default (function() {}());

To fix this, parenthesizeDefaultExpression needs to use getLeftmostExpression to get the leading class or function expression.

Actual behavior:

Invalid code: export default class {static prop = '1'}.prop;

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptBugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions