Fable
Fable copied to clipboard
[JSX] Don't deduplicate import names so they can be used in JSX templates
Add a new type to Fable.Core.JSX (I need to check it doesn't conflict with JSX.ComponentAttribute) similar to:
module Fable.Core.JSX
type Component =
abstract Create: props: Prop list -> Element
With this we should be able to import components and use them in JSX templates:
open Fable.Core
open Fable.Core.JsInterop
let SlBreadcrumb: JSX.Component = importMember "@shoelace-style/shoelace/dist/react"
let SlBreadcrumbItem: JSX.Component = importMember "@shoelace-style/shoelace/dist/react"
let render() =
JSX.html $"""
<SlBreadcrumb>
<SlBreadcrumbItem>Catalog</SlBreadcrumbItem>
<SlBreadcrumbItem>Clothing</SlBreadcrumbItem>
<SlBreadcrumbItem>Women's</SlBreadcrumbItem>
</SlBreadcrumb>
"""
However, this is currently problematic because Fable will use a deduplicate identifier for the imported member. The code generated looks like this:
import { SlBreadcrumb as SlBreadcrumb_1 } from "@shoelace-style/shoelace/dist/react";
export const SlBreadcrumb = SlBreadcrumb_1;
We should generate something like this instead (also for default imports, if the member is private we just skip the declaration):
import { SlBreadcrumb } from "@shoelace-style/shoelace/dist/react";
export { SlBreadcrumb };
Actually, now that I think about it, it should be possible to use the identifiers in JSX because they're indeed in scope. But it'd be nice to avoid the duplication nonetheless.