Skip to content
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

Fable is generating invalid Javascript for inline fuction returning object #3632

Open
sWW26 opened this issue Dec 1, 2023 · 1 comment
Open

Comments

@sWW26
Copy link

sWW26 commented Dec 1, 2023

Description

Fable is generating invalid Javascript for inline function call that immediately calls function on returned object.

Repro code

https://fable.io/repl/#?code=DYUwLgBAlgdssggMwgYwIbGAI3ag1hALwCwAUBJcgK4wQAUAlBALQB85VXEA3gD4RO3YQBUQAZ0hEadJqzYQADgCdYYJHQBEYyZqHCuAEQD2AOWNgAFrADmxGQ2btH+7nwC+rrnwUYsuAnJyUEgAD3t6FEjaCHDnUIA6HTAmRkYgA&html=Q&css=Q

Expected and actual results

To be honest I don't really understand why the Javascript code is invalid, it looks fine to me but it appears to be some edge case around calling functions directly on raw objects as when I manually change the output to:

export const x = () => {
    let y = {
        DoNothing: () => {
        },
        Test: () => {
            toConsole(printf("Test"));
        },
    };
    y.Test();
};

The interpreter is accepts it.

Related information

  • Fable version: 4.5, 4.6
@MangelMaxime
Copy link
Member

Generated code should probably have some parentheses:

export const x = () => {
    ({
        DoNothing: () => {
        },
        Test: () => {
			toConsole(printf("Test"));
        }
    }).Test();
};

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

No branches or pull requests

2 participants