Skip to content

Commit f808594

Browse files
committed
Add String.raw
1 parent 68c91a5 commit f808594

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

crates/js-sys/src/lib.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,108 @@ extern "C" {
36323632
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
36333633
#[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
36343634
pub fn value_of(this: &JsString) -> JsString;
3635+
3636+
/// The static `raw()` method is a tag function of template literals,
3637+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3638+
///
3639+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3640+
#[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
3641+
pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
3642+
3643+
/// The static `raw()` method is a tag function of template literals,
3644+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3645+
///
3646+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3647+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3648+
pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
3649+
3650+
/// The static `raw()` method is a tag function of template literals,
3651+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3652+
///
3653+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3654+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3655+
pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
3656+
3657+
/// The static `raw()` method is a tag function of template literals,
3658+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3659+
///
3660+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3661+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3662+
pub fn raw_2(
3663+
call_site: &Object,
3664+
substitutions_1: &str,
3665+
substitutions_2: &str,
3666+
) -> Result<JsString, JsValue>;
3667+
3668+
/// The static `raw()` method is a tag function of template literals,
3669+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3670+
///
3671+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3672+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3673+
pub fn raw_3(
3674+
call_site: &Object,
3675+
substitutions_1: &str,
3676+
substitutions_2: &str,
3677+
substitutions_3: &str,
3678+
) -> Result<JsString, JsValue>;
3679+
3680+
/// The static `raw()` method is a tag function of template literals,
3681+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3682+
///
3683+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3684+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3685+
pub fn raw_4(
3686+
call_site: &Object,
3687+
substitutions_1: &str,
3688+
substitutions_2: &str,
3689+
substitutions_3: &str,
3690+
substitutions_4: &str,
3691+
) -> Result<JsString, JsValue>;
3692+
3693+
/// The static `raw()` method is a tag function of template literals,
3694+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3695+
///
3696+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3697+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3698+
pub fn raw_5(
3699+
call_site: &Object,
3700+
substitutions_1: &str,
3701+
substitutions_2: &str,
3702+
substitutions_3: &str,
3703+
substitutions_4: &str,
3704+
substitutions_5: &str,
3705+
) -> Result<JsString, JsValue>;
3706+
3707+
/// The static `raw()` method is a tag function of template literals,
3708+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3709+
///
3710+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3711+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3712+
pub fn raw_6(
3713+
call_site: &Object,
3714+
substitutions_1: &str,
3715+
substitutions_2: &str,
3716+
substitutions_3: &str,
3717+
substitutions_4: &str,
3718+
substitutions_5: &str,
3719+
substitutions_6: &str,
3720+
) -> Result<JsString, JsValue>;
3721+
3722+
/// The static `raw()` method is a tag function of template literals,
3723+
/// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
3724+
///
3725+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
3726+
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
3727+
pub fn raw_7(
3728+
call_site: &Object,
3729+
substitutions_1: &str,
3730+
substitutions_2: &str,
3731+
substitutions_3: &str,
3732+
substitutions_4: &str,
3733+
substitutions_5: &str,
3734+
substitutions_6: &str,
3735+
substitutions_7: &str,
3736+
) -> Result<JsString, JsValue>;
36353737
}
36363738

36373739
impl JsString {

crates/js-sys/tests/wasm/JsString.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,14 @@ fn value_of() {
489489
let greeting = JsString::from("Hello world!");
490490
assert_eq!(greeting.value_of(), "Hello world!");
491491
}
492+
493+
#[wasm_bindgen_test]
494+
fn raw() {
495+
let call_site = Object::new();
496+
let raw = Array::of3(&"foo".into(), &"bar".into(), &"123".into());
497+
Reflect::set(&call_site.as_ref(), &"raw".into(), &raw.into());
498+
assert_eq!(JsString::raw_2(&call_site, "5", "JavaScript").unwrap(), "foo5barJavaScript123");
499+
let substitutions = Array::of2(&"5".into(), &"JavaScript".into());
500+
assert_eq!(JsString::raw(&call_site, &substitutions).unwrap(), "foo5barJavaScript123");
501+
assert!(JsString::raw_0(&JsValue::null().unchecked_into()).is_err());
502+
}

0 commit comments

Comments
 (0)