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

fix: do not mark computed React[...] methods as pure #14528

Merged
merged 1 commit into from May 17, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented May 5, 2022

Q                       A
Fixed Issues? react-pure-annotations marks React[createElement] as pure.
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Also improved typings.

@JLHwung JLHwung added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label May 5, 2022
@JLHwung JLHwung force-pushed the improve-react-pure-annotations branch from 4ea92cf to cc15e42 Compare May 5, 2022 12:45
@babel-bot
Copy link
Collaborator

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


// Mapping of React top-level methods that are pure.
// This plugin adds a /*#__PURE__#/ annotation to calls to these methods,
// so that terser and other minifiers can safely remove them during dead
// code elimination.
// See https://reactjs.org/docs/react-api.html
const PURE_CALLS = new Map([
const PURE_CALLS: [string, Set<string>][] = [
Copy link
Member

Choose a reason for hiding this comment

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

This is not a map anymore because we never relied on O(1) access, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we always loop through the structure, better just use array for that purpose.

}
const object = calleePath.get("object");
const callee = calleePath.node;
if (!callee.computed && t.isIdentifier(callee.property)) {
Copy link
Member

Choose a reason for hiding this comment

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

Note: this computed check is the only real fix, everything else is a minor refactor.

@nicolo-ribaudo nicolo-ribaudo changed the title fix: do not mark pure for computed React methods fix: do not mark computed React[...] methods as pure May 17, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 4266fef into babel:main May 17, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the improve-react-pure-annotations branch May 17, 2022 14:01
@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 Aug 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2022
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: Bug Fix 🐛 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