Skip to content

Comment and assertion changes transpilation of return statement #60296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ei-pi opened this issue Oct 21, 2024 · 1 comment · Fixed by #60304
Closed

Comment and assertion changes transpilation of return statement #60296

ei-pi opened this issue Oct 21, 2024 · 1 comment · Fixed by #60304
Labels
Fix Available A PR has been opened for this issue

Comments

@ei-pi
Copy link

ei-pi commented Oct 21, 2024

🔎 Search Terms

transpile, output, return statement

🕗 Version & Regression Information

  • This changed between versions 4.5.5 and 4.6.0. Versions 4.6.1, 4.6.2, 4.7.4, 4.8.4, 4.9.5, 5.0.4, 5.1.6, 5.2.2, 5.3.3, 5.4.5, 5.5.4, 5.6.3, 5.7.0-beta, and 5.7.0-dev.20241020 (aka the ones accessible from the TS version dropdown on the Playground, along with 4.6.1) have all been explicitly tested on the Playground and all exhibit the behaviour—presumably, the versions in between do too.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEYD2A7AzgF3kgRgKwC54AlcJGYAHkxgEsUBzAGnihQE8A+AKG4Ho+8FEkRIAtmJAosbYEJEByKGgXwAvNgDWUdtwBmAVxRgMtVKwAUASngBvbvEfw4GAzBTwLDpz9x4A2gBEUDhggQC63o42GgCMANzcAL68hsam5jjWdlHOIK7unrk+AtgoEOysohJSWBpI2ro+vvhBIWGRPjHwCcm8pagVrB5KKupaOvpGJmYeYNn2Pi5uHl7NTn5toRGsaEIGYjggMLndvSlT6bPwwAu5y4Vr6-ClAO60GAAW8F8IyDXSeAAangowULA+8BwcCgmjQxQ2rWC23Cu32h2Op3G524QA

💻 Code

declare let x: number | undefined

// no comment and no 'as' = okay
function a() {
    return (
        x
    ) = 1;
}

function b() {
    return (
        // only a comment = okay
        x
    ) = 1;
}

// only an 'as' = okay
function c() {
    return (
        x as number
    ) = 1;
}

function d() {
    return (
        // with the comment + 'as', it breaks
        x as number
    ) = 1;
}

which transpiles to:

"use strict";
// no comment and no 'as' = okay
function a() {
    return (x) = 1;
}
function b() {
    return (
    // only a comment = okay
    x) = 1;
}
// only an 'as' = okay
function c() {
    return x = 1;
}
function d() {
    return 
    // with the comment + 'as', it breaks
    x = 1;
}

🙁 Actual behavior

The issue is function d—this function will always return undefined at runtime

🙂 Expected behavior

As with versions prior to 4.6.0, function d should be transpiled as:

function d() {
    return (
    // with the comment + 'as', it breaks
    x) = 1;
}

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

MartinJohns commented Oct 21, 2024

Related: #56591 and #59237.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants