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
fix: do not mark computed React[...]
methods as pure
#14528
Conversation
4ea92cf
to
cc15e42
Compare
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>][] = [ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
React[...]
methods as pure
react-pure-annotations
marksReact[createElement]
as pure.Also improved typings.