Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (εΌ ζΆ›) committed Oct 22, 2024
1 parent 1b2a0a4 commit 380da54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/swc-plugin-canyon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swc-plugin-canyon",
"version": "0.0.2-alpha.21",
"version": "0.0.2-alpha.22",
"description": "A SWC plugin cooperates with istanbul to report the coverage",
"main": "swc_plugin_canyon.wasm",
"scripts": {
Expand Down
22 changes: 20 additions & 2 deletions plugins/swc-plugin-canyon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use swc_core::ecma::{
use swc_core::ecma::ast::{AssignTarget};
use swc_core::ecma::visit::VisitMutWith;
use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata};
use swc_core::plugin::metadata::TransformPluginMetadataContextKind;

pub struct TransformVisitor {
injected: bool,
Expand Down Expand Up @@ -99,7 +100,15 @@ impl VisitMut for TransformVisitor {
}

#[plugin_transform]
pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
// 使用TransformPluginProgramMetadataθŽ·ε–ηŽ―ε’ƒε˜ι‡
let env = metadata.get_context(&TransformPluginMetadataContextKind::Env).unwrap_or("-".to_string());
let filename = metadata.get_context(&TransformPluginMetadataContextKind::Filename).unwrap_or("-".to_string());
let cwd = metadata.get_context(&TransformPluginMetadataContextKind::Cwd).unwrap_or("-".to_string());
println!("env: {}", env);
println!("filename: {}", filename);
println!("cwd: {}", cwd);
println!("ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘ηœ‹ζˆ‘");
program.fold_with(&mut as_folder(TransformVisitor::new()))
}

Expand All @@ -110,5 +119,14 @@ test_inline!(
// θΎ“ε…₯代码
r#"console.log("transform");"#,
// η»ζ’δ»Άθ½¬ζ’εŽηš„θΎ“ε‡Ίδ»£η 
r#"console.log("transform"); window.__canyon__ = {dsn: "-",reporter:"-"};"#
r#"console.log("transform");
(new Function('return this')()).__canyon__ = {
dsn: "-",
reporter: "-",
instrumentCwd: "/",
branch: "-",
sha: "-",
projectID: "-"
};
"#
);

0 comments on commit 380da54

Please sign in to comment.