dillon1000/react

Commit

Add an optional validation to bail out on capitalized function calls

Some components stop being components over time and are used as regular 
functions instead, but they may have lingering hook calls. Those hook calls make 
it so the capitalized function calling them do not error (they appear to be a 
function to existing eslint rules), but they are nonetheless unsafe to memoize. 
This diff adds a conservative option to bail out on all capitalized function 
calls. 

There are a handful of known-non-component capitalized functions, like 
`Boolean`, `String`, and `Number`. This diff also adds the ability to supply 
capitalized function names that should not be considered in this analysis. 

I added three tests: 

1. Ensure an error occurs in the obvious case 

2. Ensure an error occurs when the value is aliased simply 

3. Ensure the allowlist works 

This is my first commit so please go hard on me. I was unsure about where this 
code should live, so please nitpick.
Browse files
Changed paths10 files
First-parent comparison
M compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/Validation/ValidateNoCapitalizedCalls.ts AddedM compiler/packages/babel-plugin-react-forget/src/Validation/index.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capitalized-function-allowlist.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capitalized-function-allowlist.js AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.capitalized-function-call-aliased.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.capitalized-function-call-aliased.js AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.capitalized-function-call.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.capitalized-function-call.js Added
Patch

Files changed

Rendering syntax-highlighted changes…