Skip to content

Commit 4b80cfa

Browse files
merrymanRobins Kiste
authored andcommitted
❄️: updated swc plugin
1 parent 146ddf4 commit 4b80cfa

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

lively.freezer/swc-plugin/Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lively.freezer/swc-plugin/lively-swc-transforms/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,26 @@ export { EvalStrategy, SimpleEvalStrategy };
378378

379379
#[test]
380380
fn test_declaration_wrapper_uses_computed_member() {
381+
// With declaration_wrapper set, function declarations get wrapped with the wrapper
382+
// as a direct function call, passing (name, kind, value, captureObj) as args.
383+
// Variable declarations do NOT get __define__ wrapping.
381384
let mut config = LivelyTransformConfig::default();
382385
config.capture_obj = "__lvVarRecorder".to_string();
383386
config.declaration_wrapper = Some("defVar_http://localhost:9011/test.js".to_string());
384387
config.module_id = "http://localhost:9011/test.js".to_string();
385388
let input = "function createLivelyLangObject() { return 1; }";
386389
let output = transform_code(input, config);
387-
eprintln!("Output: {}", output);
390+
// Function declarations are wrapped: wrapper("name", "function", ident, captureObj)
388391
assert!(
389-
output.contains("__lvVarRecorder[\"defVar_http://localhost:9011/test.js\"]"),
390-
"Expected computed member access __lvVarRecorder[\"defVar_...\"] but got:\n{}",
392+
output.contains(r#"defVar_http://localhost:9011/test.js("createLivelyLangObject", "function", createLivelyLangObject, __lvVarRecorder)"#),
393+
"Expected declaration wrapper call with __lvVarRecorder as 4th arg but got:\n{}",
394+
output
395+
);
396+
// The capture assignment should use the wrapper result
397+
assert!(
398+
output.contains("__lvVarRecorder.createLivelyLangObject ="),
399+
"Expected recorder capture assignment but got:\n{}",
391400
output
392401
);
393-
assert!(!output.contains("defVar_http:"), "Must NOT emit bare identifier with colon");
394402
}
395403
}

lively.freezer/swc-plugin/lively-swc-transforms/src/transforms/scope_capturing.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use swc_common::{SyntaxContext, DUMMY_SP};
22
use std::collections::{HashSet, HashMap};
33
use swc_ecma_ast::*;
4-
use swc_ecma_visit::{VisitMut, VisitMutWith};
4+
use swc_ecma_visit::{VisitWith, VisitMut, VisitMutWith};
55

66
use crate::utils::ast_helpers::*;
77
use crate::utils::scope_analyzer::ScopeAnalyzer;
@@ -2247,11 +2247,11 @@ mod tests {
22472247

22482248
#[test]
22492249
fn test_export_aliased_var() {
2250-
// Babel: 'var x = 23; export { x as y };' → '_rec.x = 23; var x = _rec.x; export { x as y };'
2250+
// 'var x = 23; export { x as y };' → captures x, renames export local to __export_y__
22512251
let output = transform_code("var x = 23; export { x as y };");
22522252
assert!(output.contains("__varRecorder__.x = 23;"), "captures local var with value: {}", output);
2253-
assert!(output.contains("var x = __varRecorder__.x;"), "re-declares var from recorder: {}", output);
2254-
assert!(output.contains("export { x as y }"), "keeps aliased export: {}", output);
2253+
assert!(output.contains("var __export_y__ = __varRecorder__.x;"), "re-declares with __export_ prefix: {}", output);
2254+
assert!(output.contains("export { __export_y__ as y }"), "keeps aliased export with renamed local: {}", output);
22552255
}
22562256

22572257
#[test]
@@ -2899,11 +2899,11 @@ mod tests {
28992899

29002900
#[test]
29012901
fn babel_export_aliased_var_statement() {
2902-
// Babel: 'var x = 23; export { x as y };'
2902+
// 'var x = 23; export { x as y };' → captures x, renames export local to __export_y__
29032903
let output = transform_code("var x = 23; export { x as y };");
29042904
assert!(output.contains("__varRecorder__.x = 23;"), "captures x with value: {}", output);
2905-
assert!(output.contains("var x = __varRecorder__.x;"), "re-declares var from recorder: {}", output);
2906-
assert!(output.contains("export { x as y }"), "keeps aliased export: {}", output);
2905+
assert!(output.contains("var __export_y__ = __varRecorder__.x;"), "re-declares with __export_ prefix: {}", output);
2906+
assert!(output.contains("export { __export_y__ as y }"), "keeps aliased export with renamed local: {}", output);
29072907
}
29082908

29092909
#[test]
@@ -3291,7 +3291,7 @@ mod tests {
32913291
// Babel puts __module_exports__ near the top (after recorder init),
32923292
// not at the end of the module body
32933293
let output = transform_code_resurrection("export var x = 23; var y = 42;");
3294-
let recorder_pos = output.find("recorderFor").expect("has recorder init");
3294+
let recorder_pos = output.find("moduleEnv").expect("has recorder init");
32953295
let module_exports_pos = output.find("__module_exports__").expect("has module_exports");
32963296
let last_assignment_pos = output.rfind("__varRecorder__").expect("has assignments");
32973297
assert!(module_exports_pos < last_assignment_pos,
@@ -3466,7 +3466,7 @@ mod tests {
34663466
// The hoisted let declarations must come AFTER the recorder init and __moduleMeta__,
34673467
// but BEFORE other code
34683468
let output = transform_code_resurrection("var x = 1; function foo() {}");
3469-
let recorder_pos = output.find("recorderFor").expect("has recorder init");
3469+
let recorder_pos = output.find("moduleEnv").expect("has recorder init");
34703470
let meta_pos = output.find("__moduleMeta__").expect("has module meta");
34713471
let let_foo_pos = output.find("var foo").expect("has var foo");
34723472
let var_x_pos = output.find("__varRecorder__.x").expect("has var x");
14.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)