Skip to content

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

Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom
JLHwung:improve-react-pure-annotations
May 17, 2022
Merged

fix: do not mark computed React[...] methods as pure#14528
nicolo-ribaudo merged 1 commit intobabel:mainfrom
JLHwung:improve-react-pure-annotations

Conversation

@JLHwung
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

// code elimination.
// See https://reactjs.org/docs/react-api.html
const PURE_CALLS = new Map([
const PURE_CALLS: [string, Set<string>][] = [
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

4 participants