Skip to content

feat(webidl): add support for namespace attributes#4930

Merged
guybedford merged 5 commits into
wasm-bindgen:mainfrom
guybedford:namespace-attributes
Feb 5, 2026
Merged

feat(webidl): add support for namespace attributes#4930
guybedford merged 5 commits into
wasm-bindgen:mainfrom
guybedford:namespace-attributes

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for WebIDL namespace attributes in wasm-bindgen-webidl, which were previously ignored by the binding generator.

  • Added AttributeNamespaceData struct and handling in first_pass.rs
  • Added NamespaceAttribute and NamespaceAttributeKind in generator.rs
  • Updated Namespace struct and code generation to include attributes
  • Added append_ns_attribute() method in lib.rs
  • Added tests for namespace attributes (basic and with [Throws])

Generated Output

For a WebIDL like:

namespace CSS {
    readonly attribute HighlightRegistry highlights;
};

The generated Rust code is:

pub mod css {
    use wasm_bindgen::prelude::*;
    
    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen(getter, js_namespace = CSS, js_name = highlights)]
        #[doc = "Getter for the `CSS.highlights` field."]
        pub fn highlights() -> HighlightRegistry;
    }
}

Per the WebIDL spec, namespace attributes are always readonly, so only getter bindings are generated.

Fixes #4865

Previously, namespace attributes in WebIDL were ignored by the binding
generator. This change adds support for namespace attributes, generating
proper getter bindings for them.

Per the WebIDL spec, namespace attributes are always readonly, so only
getter bindings are generated. The implementation uses static_method_of
with a generated namespace type binding (e.g., JsNamespaceCSS) to enable
proper property access on the namespace object.

This enables APIs like the CSS Custom Highlight API which adds the
`highlights` attribute to the `CSS` namespace.

Includes an end-to-end test with a PI attribute on the math_test namespace.

Fixes wasm-bindgen#4865
@guybedford guybedford force-pushed the namespace-attributes branch from dbdb562 to f541293 Compare February 3, 2026 05:42
@guybedford guybedford mentioned this pull request Feb 3, 2026
1 task
@guybedford guybedford enabled auto-merge (squash) February 5, 2026 16:34
@guybedford guybedford merged commit 27425e7 into wasm-bindgen:main Feb 5, 2026
59 checks passed
@guybedford guybedford deleted the namespace-attributes branch February 5, 2026 17:27
@guybedford guybedford mentioned this pull request Feb 20, 2026
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 this pull request may close these issues.

wasm-bindgen-webidl binding generator ignores namespace attributes

2 participants