Skip to content

createSourceFile build wrong AST in some cases.Β #46933

@dkulyk

Description

@dkulyk

Bug Report

πŸ•— Version & Regression Information

  • This is a parsing error on 4.5(maybe lower), 4.6-dev

⏯ Playground Link

AST Tree

πŸ’» Code

Parsed JS

!a
    ? (a = (function () {})())
    : (function(a){})(a);

Workbench Repro

import { createPrinter, createSourceFile, ScriptTarget } from "typescript";

const source = `!a
    ? (a = (function () {})())
    : (function(a){return !0})(a);`

console.log(
    createPrinter().printFile(
        createSourceFile(`test.js`, source, ScriptTarget.Latest)
    )
);

Workbench Repro

πŸ™ Actual behavior

Wrong JS/TS.

!a
    ? (a = (function () { })()): (function(: a):) => { } : ;
(a);

Local tsc for example.ts code make

"use strict";
!a
    ? (a = (function () { })()) => { } : ;
(a);

πŸ™‚ Expected behavior

!a
    ? (a = (function () { })()): (function (a) { })(a); ;
(a);

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions