Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce transform-block-scoping loops output size #15746

Merged
merged 4 commits into from Jul 18, 2023

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Jul 4, 2023

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Improved performance and size of transform-block-scoping for loops.
There will be a small impact on the readability of the output when the comments are not preserved.

@liuxingbaoyu liuxingbaoyu added the PR: Output optimization 🔬 A type of pull request used for our changelog categories label Jul 4, 2023
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 4, 2023

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/54894/

@nicolo-ribaudo
Copy link
Member

Do we have a test with multiple labels?

outer: while (t) {
  inner: while (t2) {
    for (let i = 0; i < 3; i++) {
      later(() => i);
      if (test1) break outer;
      else if (test2) break inner;
      else if (test3) continue outer;
      else if (test4) continue inner;
      else if (test5) break;
      else if (test6) continue;
    }
  }
}

@liuxingbaoyu
Copy link
Member Author

Do we have a test with multiple labels?

There might be something similar in the execution test, I added it in the outputs.

Comment on lines 136 to 139
const declarations = varPath.get("declarations");
declarations[declarations.length - 1]
.get("init")
.unwrapFunctionEnvironment();
Copy link
Member

Choose a reason for hiding this comment

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

We can simplify this back to what it was if we push the new variables to the end of varPath instead of unshifting them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it would look better if we put the variable first?

Copy link
Member

Choose a reason for hiding this comment

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

It would look similar, but it's slightly simpler code on our end :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds very reasonable!


var gen5 = foo3();
expect(gen5.next().value).toBe("iteration");
expect(gen5.next({what: "three"}).done).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you duplicate this test to an executable test case (exec.js)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, this is actually a copy of packages\babel-core\test\fixtures\transformation\regenerator\destructuring\exec.js. I put it here for easy fix, maybe let me just add a note to clarify?

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case can you move the packages\babel-core\test\fixtures\transformation\regenerator\destructuring\exec.js to packages/babel-plugin-transform-block-scoping/test/fixtures/regression/complex? They should have been moved to plugin specific test folders.

Copy link
Member Author

Choose a reason for hiding this comment

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

image
From what I understand it is ideally positioned?🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

The test cases here were added long before Babel plugins are separated from Babel core: https://github.com/babel/babel/blob/d4debc3c855dd4e797de3dbe8bcffe47d325dcb3/test/fixtures/transformation/regenerator/destructuring/exec.js

Since then most test cases have been moved to plugins. IMO the babel-core test cases should focus on core's behaviour, like providing plugin pass to plugin visitors, defining NodePath#hub or merging configs. In this case we already copy this test to the plugin's test folder (as input/output tests) and we generally do not separate exec.js with input.js. So I think the exec.js should be moved, too.

I can open a PR to move all such cases out of babel-core to avoid such confusing test fixtures structures.

@liuxingbaoyu
Copy link
Member Author

liuxingbaoyu commented Jul 7, 2023

It occurred to me, is it possible for us to support .get("a.-1")?

@nicolo-ribaudo
Copy link
Member

Well, in new node versions you can do .get("a").at(-1). We could just polyfill it.

@nicolo-ribaudo
Copy link
Member

Could you rebase, since we merged #15766?

@nicolo-ribaudo nicolo-ribaudo changed the title Improve transform-block-scoping performance and size for loops Reduce transform-block-scoping loops output size Jul 18, 2023
@nicolo-ribaudo nicolo-ribaudo merged commit b798a69 into babel:main Jul 18, 2023
57 checks passed
@liuxingbaoyu
Copy link
Member Author

@nicolo-ribaudo Thank you! Sorry I forgot it.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Output optimization 🔬 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants