Skip to content

Commit

Permalink
feat(es/plugin): Add experimental metadata field (swc-project#5254)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored Jul 20, 2022
1 parent 1c7855d commit bd1c2cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion crates/swc_plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub use swc_common::{
},
};

pub mod collections {
pub use swc_common::collections::AHashMap;
}

pub mod comments {
pub use swc_common::comments::{Comment, CommentKind, Comments};
pub use swc_plugin_proxy::PluginCommentsProxy;
Expand Down Expand Up @@ -84,7 +88,22 @@ pub struct TransformPluginProgramMetadata {
pub unresolved_mark: crate::syntax_pos::Mark,
/// Stringified JSON value for relative context while running transform,
/// like filenames.
/// /// This is readonly. Changing value in plugin doesn't affect host's
/// This is readonly. Changing value in plugin doesn't affect host's
/// behavior.
pub transform_context: String,
/// Non typed, extensible properties without breaking plugin compability
/// between host.
///
/// Adding a new property to this metadata will be a breaking changes we
/// can't do freely.
/// Instead, we use this as a placeholder `@swc/core` may try new metadata.
/// Once it's proven to be stable with enough usecases, it'll be
/// promoted to actual property to TransformPluginProgramMetadata with
/// proper type support.
///
/// There is no typed deserialization support for this unfortunately. Plugin
/// need to deserialize stringified values manually. In most cases this'll
/// be JSON type, but depends on the nature of the metadata it may
/// require different way to deserialize.
pub experimental: collections::AHashMap<String, String>,
}
3 changes: 2 additions & 1 deletion crates/swc_plugin_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ fn handle_func(func: ItemFn) -> TokenStream {
source_map: swc_plugin::source_map::PluginSourceMapProxy,
plugin_config: config,
unresolved_mark: swc_plugin::syntax_pos::Mark::from_u32(unresolved_mark),
transform_context: context
transform_context: context,
experimental: swc_plugin::collections::AHashMap::default(),
};

// Take original plugin fn ident, then call it with interop'ed args
Expand Down

0 comments on commit bd1c2cc

Please sign in to comment.