swc_plugin_proxy/metadata/
transform_plugin_metadata.rs#[cfg(feature = "__plugin_mode")]
use swc_common::Mark;
#[cfg(feature = "__plugin_mode")]
use swc_trace_macro::swc_trace;
#[cfg(all(feature = "__rkyv", feature = "__plugin_mode", target_arch = "wasm32"))]
use crate::memory_interop::read_returned_result_from_host;
#[cfg(feature = "__plugin_mode")]
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
use crate::{PluginCommentsProxy, PluginSourceMapProxy};
#[cfg(feature = "__plugin_mode")]
#[derive(Debug)]
pub struct TransformPluginProgramMetadata {
pub comments: Option<PluginCommentsProxy>,
pub source_map: PluginSourceMapProxy,
pub unresolved_mark: Mark,
}
#[cfg(target_arch = "wasm32")] extern "C" {
fn __copy_context_key_to_host_env(bytes_ptr: u32, bytes_ptr_len: u32);
fn __get_transform_plugin_config(allocated_ret_ptr: u32) -> u32;
fn __get_transform_context(key: u32, allocated_ret_ptr: u32) -> i32;
fn __get_experimental_transform_context(allocated_ret_ptr: u32) -> u32;
fn __get_raw_experiemtal_transform_context(allocated_ret_ptr: u32) -> u32;
}
#[cfg(feature = "__plugin_mode")]
#[swc_trace]
impl TransformPluginProgramMetadata {
pub fn get_transform_plugin_config(&self) -> Option<String> {
#[cfg(target_arch = "wasm32")]
return read_returned_result_from_host(|serialized_ptr| unsafe {
__get_transform_plugin_config(serialized_ptr)
});
#[cfg(not(target_arch = "wasm32"))]
None
}
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
pub fn get_context(
&self,
key: &swc_common::plugin::metadata::TransformPluginMetadataContextKind,
) -> Option<String> {
#[cfg(target_arch = "wasm32")]
return read_returned_result_from_host(|serialized_ptr| unsafe {
__get_transform_context(*key as u32, serialized_ptr) as u32
});
#[cfg(not(target_arch = "wasm32"))]
None
}
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
pub fn get_experimental_context(&self, key: &str) -> Option<String> {
#[cfg(target_arch = "wasm32")]
return read_returned_result_from_host(|serialized_ptr| unsafe {
let serialized = swc_common::plugin::serialized::PluginSerializedBytes::try_serialize(
&swc_common::plugin::serialized::VersionedSerializable::new(key.to_string()),
)
.expect("Should be serializable");
let (key_ptr, key_ptr_len) = serialized.as_ptr();
__copy_context_key_to_host_env(key_ptr as u32, key_ptr_len as u32);
__get_experimental_transform_context(serialized_ptr)
});
#[cfg(not(target_arch = "wasm32"))]
None
}
#[allow(unreachable_code)]
pub fn get_raw_experimental_context(
&self,
) -> swc_common::collections::AHashMap<String, String> {
unimplemented!("Not supported yet");
#[cfg(target_arch = "wasm32")]
return read_returned_result_from_host(|serialized_ptr| unsafe {
__get_raw_experiemtal_transform_context(serialized_ptr)
})
.expect("Raw experimental metadata should exists, even if it's empty map");
#[cfg(not(target_arch = "wasm32"))]
swc_common::collections::AHashMap::default()
}
}