@@ -4,17 +4,22 @@ use swc_plugin::{ast::*, plugin_transform, syntax_pos::DUMMY_SP};
44mod hash;
55use hash:: hash;
66
7+ /// Static plugin configuration.
78#[ derive( Serialize , Deserialize ) ]
89#[ serde( rename_all = "camelCase" ) ]
910#[ serde( deny_unknown_fields) ]
1011pub struct Config {
12+ /// Prefix variables with a readable name, e.g. `primary--1isauia0`.
1113 #[ serde( default = "bool::default" ) ]
12- display_name : bool ,
14+ pub display_name : bool ,
1315}
1416
17+ /// Additional context for the plugin.
1518#[ derive( Serialize , Deserialize ) ]
1619#[ serde( rename_all = "camelCase" ) ]
20+ #[ serde( deny_unknown_fields) ]
1721pub struct PluginContext {
22+ /// The name of the current file.
1823 #[ serde( default ) ]
1924 pub filename : Option < String > ,
2025}
@@ -163,24 +168,13 @@ impl VisitMut for TransformVisitor {
163168 }
164169}
165170
166- /// An entrypoint to the SWC's transform plugin.
167- /// `plugin_transform` macro handles necessary interop to communicate with the host,
168- /// and entrypoint function name (`process_transform`) can be anything else.
169- ///
170- /// If plugin need to handle low-level ptr directly,
171- /// it is possible to opt out from macro by writing transform fn manually via raw interface
171+ /// Transforms a [`Program`].
172172///
173- /// `__plugin_process_impl(
174- /// ast_ptr: *const u8,
175- /// ast_ptr_len: i32,
176- /// config_str_ptr: *const u8,
177- /// config_str_ptr_len: i32) ->
178- /// i32 /* 0 for success, fail otherwise.
179- /// Note this is only for internal pointer interop result,
180- /// not actual transform result */
173+ /// # Arguments
181174///
182- /// However, this means plugin author need to handle all of serialization/deserialization
183- /// steps with communicating with host. Refer `swc_plugin_macro` for more details.
175+ /// - `program` - The SWC [`Program`] to transform.
176+ /// - `plugin_config` - [`Config`] as JSON.
177+ /// - `context` - [`PluginContext`] as JSON.
184178#[ plugin_transform]
185179pub fn process_transform ( program : Program , plugin_config : String , context : String ) -> Program {
186180 let config: Config = serde_json:: from_str ( & plugin_config)
0 commit comments