Skip to content

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Mar 22, 2025

No description provided.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Mar 22, 2025
Copy link
Contributor Author

camc314 commented Mar 22, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines 213 to 215
let block_stmt_scope_id =
ctx.insert_scope_below_statements(&new_stmts, ScopeFlags::empty());

// TODO: make this less hacky
for stmt in &new_stmts {
match stmt {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really hate how i've done this, but it works for now.

why does ctx.insert_scope_below_statements not move the scopes of the symbols it sees? this seems like something obvious it should do (although there's probably a great reason why it doesn't), because i can't think of a situation where you would be inserting a scope but not moving the symbols scopes inside it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use Scoping data instead? Loop through the bindings of the scope and move any symbols which are block scoped.

But I may well be wrong and that doesn't work.

Unfortunately may also need to deal with BindingIdentifiers in TS* nodes e.g. TSEnumDeclaration. TS transform will remove them anyway, but if this transform moves those nodes first, the bindings need to be moved too, to avoid confusing the TS transform.

Copy link
Member

@overlookmotel overlookmotel Mar 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah feck I think I am wrong. Presumably that wouldn't work if it's a Function, because bindings for function params shouldn't be moved. Or maybe it's OK because function params aren't block scoped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies. i thought about replying, but forgot to!

Yes it's exactly that reason.

in this example, we've gone from:

function f(arg0) {
    using test = arg0();
}

to

function f(arg0) {
  try {
    var _usingCtx = babelHelpers.usingCtx();
    const x = _usingCtx.u(arg0());
  } catch (_) {
    _usingCtx.e = _;
  } finally {
    _usingCtx.d();
  }
}

so only the bindings inside the function body (note arg0 is in the scope but shouldn't be moved), should be moved.

My thought's are that id's be super helpful if ChildScopeCollector also returned binding ids as well as wel as the socpes that it moved. but may have to flesh it out a bit more

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at ChildScopeCollector is used currently. it is never used in a scenario where the scope or bindings would change. it feels reasonable to adjust it as described above.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 22, 2025

CodSpeed Instrumentation Performance Report

Merging #9962 will degrade performances by 3.41%

Comparing c/03-22-fix_transformer_using_fix_bindings_scope_mismatches (5274758) with main (778b044)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 34 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
formatter[antd.js] 7.9 ms 7.6 ms +3.88%
formatter[typescript.js] 7.2 ms 7.4 ms -3.41%

@camc314 camc314 changed the base branch from c/03-22-fix_transfomer_using_remove_use_of_child_ids to graphite-base/9962 March 22, 2025 11:12
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch from b1be057 to afbdb39 Compare March 22, 2025 11:16
@camc314 camc314 force-pushed the graphite-base/9962 branch from fd4b0c7 to 3cfc9f1 Compare March 22, 2025 11:16
@camc314 camc314 changed the base branch from graphite-base/9962 to c/03-22-fix_transfomer_using_remove_use_of_child_ids March 22, 2025 11:16
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 3cfc9f1 to f76a83b Compare March 22, 2025 11:20
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch 2 times, most recently from 2e5682a to 6084dcd Compare March 22, 2025 11:21
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch 2 times, most recently from 5973bbd to 7dffe96 Compare March 24, 2025 12:28
@camc314 camc314 changed the base branch from c/03-22-fix_transfomer_using_remove_use_of_child_ids to graphite-base/9962 March 24, 2025 12:30
@camc314 camc314 force-pushed the graphite-base/9962 branch from 5973bbd to 1a9e4fe Compare March 30, 2025 12:36
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch from 6084dcd to 77c12ff Compare March 30, 2025 12:36
@camc314 camc314 changed the base branch from graphite-base/9962 to c/03-22-fix_transfomer_using_remove_use_of_child_ids March 30, 2025 12:36
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch 2 times, most recently from dfaaa38 to d1a8a52 Compare April 3, 2025 19:52
@camc314 camc314 force-pushed the c/03-22-fix_transfomer_using_remove_use_of_child_ids branch from 1a9e4fe to 5e6c074 Compare April 3, 2025 19:52
@camc314 camc314 changed the base branch from c/03-22-fix_transfomer_using_remove_use_of_child_ids to graphite-base/9962 April 3, 2025 20:12
@camc314 camc314 force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch from d1a8a52 to 412b3fb Compare April 3, 2025 20:13
@camc314 camc314 changed the base branch from graphite-base/9962 to c/04-03-fix_transformer_transform_using_declarations_in_try_block April 3, 2025 20:13
@graphite-app graphite-app bot changed the base branch from c/04-03-fix_transformer_transform_using_declarations_in_try_block to graphite-base/9962 April 4, 2025 01:05
@graphite-app graphite-app bot force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch from 412b3fb to 85ad8b4 Compare April 4, 2025 01:14
@graphite-app graphite-app bot force-pushed the graphite-base/9962 branch from ffc3de1 to 778b044 Compare April 4, 2025 01:14
@graphite-app graphite-app bot changed the base branch from graphite-base/9962 to main April 4, 2025 01:15
@graphite-app graphite-app bot force-pushed the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch from 85ad8b4 to 5274758 Compare April 4, 2025 01:15
@camc314 camc314 closed this Jul 3, 2025
@Boshen Boshen deleted the c/03-22-fix_transformer_using_fix_bindings_scope_mismatches branch August 30, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants