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

System.FormattableString results in doubled '{' in JavaScript output #3889

Closed
roboz0r opened this issue Sep 18, 2024 · 0 comments · Fixed by #3890
Closed

System.FormattableString results in doubled '{' in JavaScript output #3889

roboz0r opened this issue Sep 18, 2024 · 0 comments · Fixed by #3890

Comments

@roboz0r
Copy link
Contributor

roboz0r commented Sep 18, 2024

Description

When writing bindings referring to System.FormattableString the resulting JavaScript string includes {{ and }} where only single characters are expected. This results in broken styles in e.g. Fable.Lit.

Repro code

REPL

open System
open Fable.Core

[<Erase>]
type Binding() =
    [<Emit("css($0, $1)")>]
    static member inline private cssInner(strs: string[], [<ParamArray>] args: obj[]) : obj = jsNative

    static member inline css(s: FormattableString) =
        Binding.cssInner (s.GetStrings(), s.GetArguments())

module X = 
  let ex1 () =
    let color = "blue"
    Binding.css 
        $""":host {{
            color: {color};
        }}"""

  let ex2 () =
    Binding.css 
        $$""":host {
            color: blue;
        }"""

  let ex3 () =
    Binding.css 
        $":host {{
            color: blue;
        }}"

Expected and actual results

Actual

export function X_ex1() {
    const color = "blue";
    const s = fmt`:host {{
            color: ${color};
        }}`;
    return css(s.strs, ...s.args);
}

Expected

export function X_ex1() {
    const color = "blue";
    const s = fmt`:host {
            color: ${color};
        }`;
    return css(s.strs, ...s.args);
}

or

export function X_ex1() {
    const color = "blue";
    return css(`:host {
            color: ${color};
        }`);
}

Related information

  • Fable version: dotnet fable --version 4.20.0
  • Operating system: Windows 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant