mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 04:07:18 +03:00
feat(es/transforms): Add an API for returning metadata to JS (#9022)
This commit is contained in:
parent
2b81d72333
commit
6ce112cfeb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3982,6 +3982,7 @@ dependencies = [
|
||||
"swc_plugin_proxy",
|
||||
"swc_plugin_runner",
|
||||
"swc_trace_macro",
|
||||
"swc_transform_common",
|
||||
"testing",
|
||||
"vergen",
|
||||
]
|
||||
|
@ -21,6 +21,7 @@ version = "0.92.11"
|
||||
"ecma_loader",
|
||||
"ecma_ast",
|
||||
"trace_macro",
|
||||
"transform_common",
|
||||
"plugin_transform",
|
||||
]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
@ -40,6 +41,8 @@ doctest = false
|
||||
# swc_common/ahash
|
||||
common_ahash = ["swc_common/ahash"]
|
||||
|
||||
transform_common = []
|
||||
|
||||
# swc_ecma_loader/cache*
|
||||
ecma_loader_lru = ["swc_ecma_loader/lru"]
|
||||
ecma_loader_parking_lot = ["swc_ecma_loader/parking_lot"]
|
||||
@ -371,6 +374,7 @@ swc_plugin = { optional = true, version = "0.90.0", path =
|
||||
swc_plugin_macro = { optional = true, version = "0.9.16", path = "../swc_plugin_macro" }
|
||||
swc_plugin_proxy = { optional = true, version = "0.42.1", path = "../swc_plugin_proxy" }
|
||||
swc_trace_macro = { optional = true, version = "0.1.3", path = "../swc_trace_macro" }
|
||||
swc_transform_common = { optional = true, version = "0.1.0", path = "../swc_transform_common" }
|
||||
testing = { optional = true, version = "0.35.24", path = "../testing" }
|
||||
# TODO: eventually swc_plugin_runner needs to remove default features
|
||||
swc_plugin_runner = { optional = true, version = "0.107.1", path = "../swc_plugin_runner", default-features = false }
|
||||
|
@ -184,6 +184,12 @@ pub mod trace_macro {
|
||||
pub use swc_trace_macro::*;
|
||||
}
|
||||
|
||||
#[cfg(feature = "transform_common")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "transform_common")))]
|
||||
pub mod transform_common {
|
||||
pub use swc_transform_common::*;
|
||||
}
|
||||
|
||||
// swc_bundler
|
||||
#[cfg(feature = "__bundler")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "__bundler")))]
|
||||
|
@ -1,3 +1,7 @@
|
||||
//! (Experimental) Output capturing.
|
||||
//!
|
||||
//! This module provides a way to emit metadata to the JS caller.
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use better_scoped_tls::scoped_tls;
|
||||
@ -6,6 +10,9 @@ use serde_json::Value;
|
||||
|
||||
scoped_tls!(static OUTPUT: RefCell<FxHashMap<String, Value>>);
|
||||
|
||||
/// (Experimental) Captures output.
|
||||
///
|
||||
/// This is not stable and may be removed in the future.
|
||||
pub fn capture<Ret>(f: impl FnOnce() -> Ret) -> (Ret, FxHashMap<String, Value>) {
|
||||
let output = RefCell::new(FxHashMap::default());
|
||||
|
||||
@ -14,6 +21,9 @@ pub fn capture<Ret>(f: impl FnOnce() -> Ret) -> (Ret, FxHashMap<String, Value>)
|
||||
(ret, output.into_inner())
|
||||
}
|
||||
|
||||
/// (Experimental) Emits a value to the JS caller.
|
||||
///
|
||||
/// This is not stable and may be removed in the future.
|
||||
pub fn emit(key: String, value: Value) {
|
||||
OUTPUT.with(|output| {
|
||||
let previous = output.borrow_mut().insert(key, value);
|
||||
|
Loading…
Reference in New Issue
Block a user