diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index b09f582d..c7501da4 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -3632,6 +3632,108 @@ extern "C" { /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf) #[wasm_bindgen(method, js_class = "String", js_name = valueOf)] pub fn value_of(this: &JsString) -> JsString; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")] + pub fn raw(call_site: &Object, substitutions: &Array) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_0(call_site: &Object) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_2( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + ) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_3( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + substitutions_3: &str, + ) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_4( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + substitutions_3: &str, + substitutions_4: &str, + ) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_5( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + substitutions_3: &str, + substitutions_4: &str, + substitutions_5: &str, + ) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_6( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + substitutions_3: &str, + substitutions_4: &str, + substitutions_5: &str, + substitutions_6: &str, + ) -> Result; + + /// The static `raw()` method is a tag function of template literals, + /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) + #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)] + pub fn raw_7( + call_site: &Object, + substitutions_1: &str, + substitutions_2: &str, + substitutions_3: &str, + substitutions_4: &str, + substitutions_5: &str, + substitutions_6: &str, + substitutions_7: &str, + ) -> Result; } impl JsString { diff --git a/crates/js-sys/tests/wasm/JsString.rs b/crates/js-sys/tests/wasm/JsString.rs index 0553914e..5d5b5975 100644 --- a/crates/js-sys/tests/wasm/JsString.rs +++ b/crates/js-sys/tests/wasm/JsString.rs @@ -489,3 +489,14 @@ fn value_of() { let greeting = JsString::from("Hello world!"); assert_eq!(greeting.value_of(), "Hello world!"); } + +#[wasm_bindgen_test] +fn raw() { + let call_site = Object::new(); + let raw = Array::of3(&"foo".into(), &"bar".into(), &"123".into()); + Reflect::set(&call_site.as_ref(), &"raw".into(), &raw.into()); + assert_eq!(JsString::raw_2(&call_site, "5", "JavaScript").unwrap(), "foo5barJavaScript123"); + let substitutions = Array::of2(&"5".into(), &"JavaScript".into()); + assert_eq!(JsString::raw(&call_site, &substitutions).unwrap(), "foo5barJavaScript123"); + assert!(JsString::raw_0(&JsValue::null().unchecked_into()).is_err()); +}