You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(transformer_v1): avoid extra block scope for function bodies in hygiene - #1817
In swc_next_ecma_transformer_v1, hygiene's AnalyzerAndCollector created an extra child block scope when visiting FunctionBody, unlike upstream SWC where FunctionBody statements belong directly to the function scope. As a result, top-level let/const bindings in a function body were not checked for name conflicts against the enclosing function scope (such as parameter bindings or function-name usages recorded for default/rest parameters), causing SWC conformance mismatches on regressions/issues-9xxx/9198/1 and 9198/2 and risking invalid parameter/lexical redeclaration collisions.
Changes
Removed AnalyzerAndCollector::visit_function_body in crates/swc_ecma_transformer_v1/src/common/rename/analyzer_and_collector.rs so FunctionBody visits its statements directly in the enclosing function scope, matching upstream SWC.
Updated tasks/testsuite/snapshots/transform_v1_swc.snap: Positive Passed increased from 465/2110 to 467/2110 (regressions/issues-9xxx/9198/1 and 9198/2 now pass) with no regressions across other suites.
Verified with cargo fmt --check, cargo clippy -p swc_next_ecma_transformer_v1 --all-targets -- -D warnings, cargo test -p swc_next_ecma_transformer_v1, and conformance.
Median instruction counts from three processes, shown as compare / base in K (1,000), truncated to whole thousands. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged or overlapping ranges (inconclusive).
JIT disabled (--jitless); predictable mode enabled (--predictable). Counts are not wall time. Exact counts, ranges and profiles are retained in artifacts.
Callgrind instruction counts (Ir) for the compare and base revisions. Values are shown as compare / base in K (1,000), truncated to whole thousands. Multi-part profiles use the part numbers from Gungraun and include an aggregated Total. New and Removed identify benchmarks that exist on only one side; the missing value is shown as a dash. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged.
Formatter
Benchmark
Ir (K)
Change
formatter/angular
73,639 / 73,639
0% ⚪
formatter/astro_config
4,348 / 4,348
0% ⚪
formatter/backbone
11,034 / 11,034
0% ⚪
formatter/effect_schema_ast
23,717 / 23,717
0% ⚪
formatter/hono_types
16,031 / 16,031
0% ⚪
formatter/jquery_mobile
95,000 / 95,000
0% ⚪
formatter/mootools
47,050 / 47,050
0% ⚪
formatter/three
255,137 / 255,137
0% ⚪
formatter/typescript
1,427,688 / 1,427,688
0% ⚪
formatter/underscore
9,873 / 9,873
0% ⚪
formatter/yui
46,446 / 46,446
0% ⚪
markdown_formatter/biome_readme
287 / 287
0% ⚪
markdown_formatter/nix_changelog
4,706 / 4,706
0% ⚪
markdown_formatter/prettier_options
1,062 / 1,062
0% ⚪
Generator
Benchmark
Ir (K)
Change
cal_com_tsx
50,264 / 50,264
0% ⚪
typescript
373,929 / 373,929
0% ⚪
Minifier
Benchmark
Ir (K)
Change
angular
19,086 / 19,086
0% ⚪
semantic
43 / 43
0% ⚪
typescript
385,762 / 385,762
0% ⚪
underscore
2,778 / 2,778
0% ⚪
Parser
Benchmark
Ir (K)
Change
markdown_parser/biome_readme
316 / 316
0% ⚪
markdown_parser/nix_changelog
8,110 / 8,110
0% ⚪
markdown_parser/prettier_options
1,601 / 1,601
0% ⚪
parser/angular
7,971 / 7,971
0% ⚪
parser/backbone
1,267 / 1,267
0% ⚪
parser/cal_com_tsx
25,103 / 25,103
0% ⚪
parser/hono_types
2,898 / 2,898
0% ⚪
parser/jquery
6,668 / 6,668
0% ⚪
parser/jquery_mobile
10,304 / 10,304
0% ⚪
parser/mootools
5,499 / 5,499
0% ⚪
parser/three
32,274 / 32,274
0% ⚪
parser/typescript
162,356 / 162,356
0% ⚪
parser/underscore
1,131 / 1,131
0% ⚪
parser/yui
5,176 / 5,176
0% ⚪
Semantic
Benchmark
Ir (K)
Change
analyze/cal_com_tsx
15,944 / 15,944
0% ⚪
analyze/typescript
129,369 / 129,369
0% ⚪
analyze/typescript_checker
55,495 / 55,495
0% ⚪
syntax_check/cal_com_tsx
26,799 / 26,799
0% ⚪
syntax_check/typescript
178,137 / 178,137
0% ⚪
syntax_check/typescript_checker
70,131 / 70,131
0% ⚪
Transform
Benchmark
Ir (K)
Change
transform/excalidraw_app
34,247 / 34,247
0% ⚪
transform/hono_types
12,716 / 12,716
0% ⚪
transform/kitchen_sink
112,547 / 112,547
0% ⚪
transform/radix_ui_adoption
346 / 346
0% ⚪
transform/three
127,189 / 127,189
0% ⚪
transform_v1/excalidraw_app
83,276 / 83,554
−0.333% 🟢
transform_v1/hono_types
589 / 589
−0.064% 🟢
transform_v1/kitchen_sink
163,798 / 164,897
−0.666% 🟢
transform_v1/radix_ui_adoption
676 / 677
−0.112% 🟢
transform_v1/three
271,087 / 272,521
−0.526% 🟢
Type strip
Benchmark
Ir (K)
Change
astro_config/Part 1
369 / 369
0% ⚪
astro_config/Part 2
158 / 158
0% ⚪
astro_config/Total
527 / 527
0% ⚪
effect_schema_ast/Part 1
2,985 / 2,985
0% ⚪
effect_schema_ast/Part 2
675 / 675
0% ⚪
effect_schema_ast/Total
3,661 / 3,661
0% ⚪
hono_types/Part 1
2,891 / 2,891
0% ⚪
hono_types/Part 2
112 / 112
0% ⚪
hono_types/Total
3,003 / 3,003
0% ⚪
Visit
Benchmark
Ir (K)
Change
traverse/cal_com_tsx
2,826 / 2,826
0% ⚪
traverse/typescript
25,822 / 25,822
0% ⚪
visit/cal_com_tsx
2,874 / 2,874
0% ⚪
visit/typescript
25,119 / 25,119
0% ⚪
visit_mut/cal_com_tsx
2,555 / 2,555
0% ⚪
visit_mut/typescript
24,288 / 24,288
0% ⚪
Benchmark results
gungraun::parser::bench_parser angular:(ANGULAR, Lang :: Js)
Baselines: |base
Instructions: 7971657|7971657 (No change)
gungraun::parser::bench_parser backbone:(BACKBONE, Lang :: Js)
Baselines: |base
Instructions: 1267593|1267593 (No change)
gungraun::parser::bench_parser jquery:(JQUERY, Lang :: Js)
Baselines: |base
Instructions: 6668819|6668819 (No change)
gungraun::parser::bench_parser jquery_mobile:(JQUERY_MOBILE, Lang :: Js)
Baselines: |base
Instructions: 10304129|10304129 (No change)
gungraun::parser::bench_parser mootools:(MOOTOOLS, Lang :: Js)
Baselines: |base
Instructions: 5499972|5499972 (No change)
gungraun::parser::bench_parser underscore:(UNDERSCORE, Lang :: Js)
Baselines: |base
Instructions: 1131858|1131858 (No change)
gungraun::parser::bench_parser three:(THREE, Lang :: Js)
Baselines: |base
Instructions: 32274652|32274652 (No change)
gungraun::parser::bench_parser yui:(YUI, Lang :: Js)
Baselines: |base
Instructions: 5176318|5176318 (No change)
gungraun::parser::bench_parser typescript:(TYPESCRIPT, Lang :: Js)
Baselines: |base
Instructions: 162356069|162356069 (No change)
gungraun::parser::bench_parser cal_com_tsx:(CAL_COM_TSX, Lang :: Tsx)
Baselines: |base
Instructions: 25103597|25103597 (No change)
gungraun::parser::bench_parser hono_types:(HONO_TYPES, Lang :: Ts)
Baselines: |base
Instructions: 2898684|2898684 (No change)
gungraun::parser::bench_markdown_parser biome_readme:(BIOME_README)
Baselines: |base
Instructions: 316308|316308 (No change)
gungraun::parser::bench_markdown_parser prettier_options:(PRETTIER_OPTIONS)
Baselines: |base
Instructions: 1601156|1601152 (+0.00025%) [+1.00000x]
gungraun::parser::bench_markdown_parser nix_changelog:(NIX_CHANGELOG)
Baselines: |base
Instructions: 8110561|8110561 (No change)
gungraun::semantic::bench_analyze typescript:(setup_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 129369107|129369107 (No change)
gungraun::semantic::bench_analyze cal_com_tsx:(setup_program(CAL_COM_TSX, Lang :: Tsx))
Baselines: |base
Instructions: 15944877|15944877 (No change)
gungraun::semantic::bench_analyze typescript_checker:(setup_program(TYPESCRIPT_CHECKER, Lang :: Ts))
Baselines: |base
Instructions: 55495186|55495186 (No change)
gungraun::semantic::bench_syntax_check typescript:(setup_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 178137059|178137059 (No change)
gungraun::semantic::bench_syntax_check cal_com_tsx:(setup_program(CAL_COM_TSX, Lang :: Tsx))
Baselines: |base
Instructions: 26799814|26799814 (No change)
gungraun::semantic::bench_syntax_check typescript_checker:(setup_program(TYPESCRIPT_CHECKER, Lang :: Ts))
Baselines: |base
Instructions: 70131017|70131017 (No change)
gungraun::generator::bench_generate typescript:(setup_generate(TYPESCRIPT, "typescript.js"))
Baselines: |base
Instructions: 373929107|373929107 (No change)
gungraun::generator::bench_generate cal_com_tsx:(setup_generate(CAL_COM_TSX, "cal.com.tsx"))
Baselines: |base
Instructions: 50264351|50264351 (No change)
gungraun::formatter::bench_formatter angular:(setup_formatter_program(ANGULAR, Lang :: Js))
Baselines: |base
Instructions: 73639553|73639553 (No change)
gungraun::formatter::bench_formatter backbone:(setup_formatter_program(BACKBONE, Lang :: Js))
Baselines: |base
Instructions: 11034841|11034841 (No change)
gungraun::formatter::bench_formatter jquery_mobile:(setup_formatter_program(JQUERY_MOBILE, Lang :: Js...
Baselines: |base
Instructions: 95000726|95000726 (No change)
gungraun::formatter::bench_formatter mootools:(setup_formatter_program(MOOTOOLS, Lang :: Js))
Baselines: |base
Instructions: 47050508|47050508 (No change)
gungraun::formatter::bench_formatter underscore:(setup_formatter_program(UNDERSCORE, Lang :: Js))
Baselines: |base
Instructions: 9873726|9873726 (No change)
gungraun::formatter::bench_formatter three:(setup_formatter_program(THREE, Lang :: Js))
Baselines: |base
Instructions: 255137678|255137678 (No change)
gungraun::formatter::bench_formatter yui:(setup_formatter_program(YUI, Lang :: Js))
Baselines: |base
Instructions: 46446032|46446032 (No change)
gungraun::formatter::bench_formatter typescript:(setup_formatter_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 1427688021|1427688021 (No change)
gungraun::formatter::bench_formatter astro_config:(setup_formatter_program(ASTRO_CONFIG, Lang :: Ts)...
Baselines: |base
Instructions: 4348501|4348501 (No change)
gungraun::formatter::bench_formatter effect_schema_ast:(setup_formatter_program(EFFECT_SCHEMA_AST, Lang :...
Baselines: |base
Instructions: 23717831|23717831 (No change)
gungraun::formatter::bench_formatter hono_types:(setup_formatter_program(HONO_TYPES, Lang :: Ts))
Baselines: |base
Instructions: 16031478|16031478 (No change)
gungraun::formatter::bench_markdown_formatter biome_readme:(parse_markdown(BIOME_README))
Baselines: |base
Instructions: 287109|287109 (No change)
gungraun::formatter::bench_markdown_formatter prettier_options:(parse_markdown(PRETTIER_OPTIONS))
Baselines: |base
Instructions: 1062336|1062336 (No change)
gungraun::formatter::bench_markdown_formatter nix_changelog:(parse_markdown(NIX_CHANGELOG))
Baselines: |base
Instructions: 4706162|4706162 (No change)
gungraun::minifier::bench_minifier underscore:(setup_minifier(UNDERSCORE))
Baselines: |base
Instructions: 2778116|2778116 (No change)
gungraun::minifier::bench_minifier angular:(setup_minifier(ANGULAR))
Baselines: |base
Instructions: 19086243|19086243 (No change)
gungraun::minifier::bench_minifier typescript:(setup_minifier(TYPESCRIPT))
Baselines: |base
Instructions: 385762338|385762338 (No change)
gungraun::minifier::bench_minifier semantic:(setup_minifier(MINIFIER_SEMANTIC))
Baselines: |base
Instructions: 43050|43050 (No change)
gungraun::transform::bench_transform three:(setup_transform(THREE, "three-0.138.3.js"))
Baselines: |base
Instructions: 127189966|127189966 (No change)
gungraun::transform::bench_transform excalidraw_app:(setup_transform(EXCALIDRAW_APP, "App.tsx"))
Baselines: |base
Instructions: 34247602|34247602 (No change)
gungraun::transform::bench_transform radix_ui_adoption:(setup_transform(RADIX_UI_ADOPTION, "RadixUIAdopti...
Baselines: |base
Instructions: 346655|346655 (No change)
gungraun::transform::bench_transform hono_types:(setup_transform(HONO_TYPES, "hono-types.ts"))
Baselines: |base
Instructions: 12716683|12716683 (No change)
gungraun::transform::bench_transform kitchen_sink:(setup_transform(KITCHEN_SINK, "kitchen-sink.tsx")...
Baselines: |base
Instructions: 112547382|112547382 (No change)
gungraun::transform::bench_transform_v1 three:(setup_transform_v1(THREE, "three-0.138.3.js"))
Baselines: |base
Instructions: 271087928|272521354 (-0.52599%) [-1.00529x]
gungraun::transform::bench_transform_v1 excalidraw_app:(setup_transform_v1(EXCALIDRAW_APP, "App.tsx"))
Baselines: |base
Instructions: 83276723|83554880 (-0.33290%) [-1.00334x]
gungraun::transform::bench_transform_v1 radix_ui_adoption:(setup_transform_v1(RADIX_UI_ADOPTION, "RadixUIAdo...
Baselines: |base
Instructions: 676403|677164 (-0.11238%) [-1.00113x]
gungraun::transform::bench_transform_v1 hono_types:(setup_transform_v1(HONO_TYPES, "hono-types.ts"))
Baselines: |base
Instructions: 589533|589913 (-0.06442%) [-1.00064x]
gungraun::transform::bench_transform_v1 kitchen_sink:(setup_transform_v1(KITCHEN_SINK, "kitchen-sink.ts...
Baselines: |base
Instructions: 163798657|164897521 (-0.66639%) [-1.00671x]
gungraun::type_strip::bench_type_strip astro_config:(ASTRO_CONFIG, type_strip_options(Lang :: Ts))
## pid: 9420 thread: 1 part: 1 |pid: 9345 thread: 1 part: 1
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00000
Baselines: |base
Instructions: 369418|369418 (No change)
## pid: 9420 thread: 1 part: 2 |pid: 9345 thread: 1 part: 2
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00000
Instructions: 158362|158362 (No change)
## Total
Instructions: 527780|527780 (No change)
gungraun::type_strip::bench_type_strip effect_schema_ast:(EFFECT_SCHEMA_AST, type_strip_options(Lang :: Ts)...
## pid: 9421 thread: 1 part: 1 |pid: 9346 thread: 1 part: 1
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00001
Baselines: |base
Instructions: 2985977|2985977 (No change)
## pid: 9421 thread: 1 part: 2 |pid: 9346 thread: 1 part: 2
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00001
Instructions: 675715|675715 (No change)
## Total
Instructions: 3661692|3661692 (No change)
gungraun::type_strip::bench_type_strip hono_types:(HONO_TYPES, type_strip_options(Lang :: Ts))
## pid: 9422 thread: 1 part: 1 |pid: 9347 thread: 1 part: 1
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00002
Baselines: |base
Instructions: 2891268|2891268 (No change)
## pid: 9422 thread: 1 part: 2 |pid: 9347 thread: 1 part: 2
Command:
/home/runner/work/_temp/gungraun-bin/head/gungraun|/home/runner/work/_temp/gungraun-bin/base/gungraun --gungraun-run d:d:000000 00006 00000 00002
Instructions: 112005|112005 (No change)
## Total
Instructions: 3003273|3003273 (No change)
gungraun::visit::bench_visit typescript:(setup_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 25119209|25119209 (No change)
gungraun::visit::bench_visit cal_com_tsx:(setup_program(CAL_COM_TSX, Lang :: Tsx))
Baselines: |base
Instructions: 2874310|2874310 (No change)
gungraun::visit::bench_visit_mut typescript:(setup_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 24288597|24288597 (No change)
gungraun::visit::bench_visit_mut cal_com_tsx:(setup_program(CAL_COM_TSX, Lang :: Tsx))
Baselines: |base
Instructions: 2555855|2555855 (No change)
gungraun::visit::bench_traverse typescript:(setup_program(TYPESCRIPT, Lang :: Js))
Baselines: |base
Instructions: 25822582|25822582 (No change)
gungraun::visit::bench_traverse cal_com_tsx:(setup_program(CAL_COM_TSX, Lang :: Tsx))
Baselines: |base
Instructions: 2826624|2826624 (No change)
Gungraun result: Ok. 59 without regressions; 0 regressed; 0 filtered; 59 benchmarks finished in 74.7142s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In
swc_next_ecma_transformer_v1, hygiene'sAnalyzerAndCollectorcreated an extra child block scope when visitingFunctionBody, unlike upstream SWC whereFunctionBodystatements belong directly to the function scope. As a result, top-levellet/constbindings in a function body were not checked for name conflicts against the enclosing function scope (such as parameter bindings or function-name usages recorded for default/rest parameters), causing SWC conformance mismatches onregressions/issues-9xxx/9198/1and9198/2and risking invalid parameter/lexical redeclaration collisions.Changes
AnalyzerAndCollector::visit_function_bodyincrates/swc_ecma_transformer_v1/src/common/rename/analyzer_and_collector.rssoFunctionBodyvisits its statements directly in the enclosing function scope, matching upstream SWC.tasks/testsuite/snapshots/transform_v1_swc.snap:Positive Passedincreased from465/2110to467/2110(regressions/issues-9xxx/9198/1and9198/2now pass) with no regressions across other suites.cargo fmt --check,cargo clippy -p swc_next_ecma_transformer_v1 --all-targets -- -D warnings,cargo test -p swc_next_ecma_transformer_v1, andconformance.