mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
fix(plugin): Allow testing (#3542)
This commit is contained in:
parent
72b31977e4
commit
fbe91963bf
@ -1,5 +1,6 @@
|
||||
use swc_common::plugin::Serialized;
|
||||
|
||||
#[cfg(target_arch = "wasm32")] // Allow testing
|
||||
extern "C" {
|
||||
fn __emit_diagnostics(bytes_ptr: i32, bytes_ptr_len: i32);
|
||||
fn __free(bytes_ptr: i32, size: i32) -> i32;
|
||||
@ -13,14 +14,16 @@ extern "C" {
|
||||
pub struct PluginDiagnosticsEmitter {}
|
||||
|
||||
impl swc_common::errors::Emitter for PluginDiagnosticsEmitter {
|
||||
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
|
||||
fn emit(&mut self, db: &swc_common::errors::DiagnosticBuilder<'_>) {
|
||||
let diag =
|
||||
Serialized::serialize(&*db.diagnostic).expect("Should able to serialize Diagnostic");
|
||||
let diag_ref = diag.as_ref();
|
||||
|
||||
let ptr = diag_ref.as_ptr() as _;
|
||||
let ptr = diag_ref.as_ptr() as i32;
|
||||
let len = diag_ref.len() as i32;
|
||||
|
||||
#[cfg(target_arch = "wasm32")] // Allow testing
|
||||
unsafe {
|
||||
__emit_diagnostics(ptr, len);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ fn handle_func(func: ItemFn) -> TokenStream {
|
||||
|
||||
// Declaration for imported function from swc host.
|
||||
// Refer swc_plugin_runner for the actual implementation.
|
||||
#[cfg(target_arch = "wasm32")] // Allow testing
|
||||
extern "C" {
|
||||
fn __set_transform_result(bytes_ptr: i32, bytes_ptr_len: i32);
|
||||
fn __free(bytes_ptr: i32, size: i32) -> i32;
|
||||
@ -36,6 +37,7 @@ fn handle_func(func: ItemFn) -> TokenStream {
|
||||
/// When guest calls __set_transform_result host should've completed read guest's memory and allocates its byte
|
||||
/// into host's enviroment so guest can free its memory later.
|
||||
fn set_transform_result_volatile(bytes_ptr: i32, bytes_ptr_len: i32) {
|
||||
#[cfg(target_arch = "wasm32")] // Allow testing
|
||||
unsafe {
|
||||
__set_transform_result(bytes_ptr, bytes_ptr_len);
|
||||
__free(bytes_ptr, bytes_ptr_len);
|
||||
|
Loading…
Reference in New Issue
Block a user