WebAssembly / component-model

Repository for design and specification of the Component Model
Other
954 stars 79 forks source link

How to alias a child of a sibling comonent? #220

Closed lum1n0us closed 1 year ago

lum1n0us commented 1 year ago

Expand below by adding a child $C1 into $C.

(component $Parent
  (component $C ...
    (component $C1 ...)
  )

  (component
    (alias outer $Parent $C (component $Parent_C))
    (instance (instantiate $Parent_C))

    ;; how to alias $C1?
  )
)

Is there a way to alias $C1 instead of $C?

I am thinkg about (alias outer $Parent_C $C1 (component $Parent_C_C1)), but it is wrong because outer parameter Parent_C not found

lukewagner commented 1 year ago

Since $C1 is not exported by $C, $C1 is a private/encapsulated detail of $C. To alias $C1 at the point of your comment, $C needs to (export "C1" (component $C1)) and then you can (alias export $Parent_C "C1" (component $C1)).

Hope that helps, let me know if you have any other questions.

lum1n0us commented 1 year ago

Thanks a lot.

P.S. The final version is

(component $Parent
  (component $C ...
    (component $C1 ...)
    (export "C1" (component $C1))
  )

  (component
    (alias outer $Parent $C (component $Parent_C))
    (instance $p_c (instantiate $Parent_C))

    ;; alias $C1
    (alias export $p_c "C1" (component $Parent_C_C1))
  )
)