Skip to content

Commit a21ea4e

Browse files
alexeyrclaude
andcommitted
Address CodeRabbit review feedback
- Use Map in contextStore to avoid prototype key collisions - Use block body in forEach callback in nest-test - Assert setState callback was invoked in withState-test Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent c243f44 commit a21ea4e

File tree

9 files changed

+19
-23
lines changed

9 files changed

+19
-23
lines changed

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
plugins: [['@babel/proposal-class-properties', { loose: true }]],
2+
plugins: [['@babel/transform-class-properties', { loose: true }]],
33
presets: [['@babel/env', { loose: true }], '@babel/react'],
44
}
55

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"devDependencies": {
4242
"@babel/cli": "^7.22.0",
4343
"@babel/core": "^7.22.0",
44-
"@babel/plugin-proposal-class-properties": "^7.18.0",
44+
"@babel/plugin-transform-class-properties": "^7.25.0",
4545
"@babel/plugin-transform-runtime": "^7.22.0",
4646
"@babel/preset-env": "^7.22.0",
4747
"@babel/preset-react": "^7.22.0",

src/packages/recompose/__tests__/branch-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ test('branch third argument should not cause console error', () => {
6060

6161
render(<BranchedComponent />)
6262

63-
expect(console.error.mock.calls.length > 0).toBe(false)
63+
expect(console.error).not.toHaveBeenCalled()
6464
})

src/packages/recompose/__tests__/nest-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ test('nest nests components from outer to inner', () => {
1515
// nest(A,B,C) creates nested divs, all with pass="through"
1616
const divs = container.querySelectorAll('div')
1717
expect(divs.length).toBe(3)
18-
divs.forEach(div => expect(div.getAttribute('pass')).toBe('through'))
18+
divs.forEach(div => {
19+
expect(div.getAttribute('pass')).toBe('through')
20+
})
1921
expect(container.textContent).toBe('Child')
2022
})

src/packages/recompose/__tests__/withHandlers-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test('withHandlers warns if handler is not a higher-order function', () => {
6767

6868
const { container } = render(<Button />)
6969

70-
// React 16 dev mode re-throws errors from event handlers via
70+
// React dev mode re-throws errors from event handlers via
7171
// invokeGuardedCallbackDev, causing an uncaught error in jsdom.
7272
// Suppress it so we can check the console.error warning instead.
7373
const onError = event => event.preventDefault()

src/packages/recompose/__tests__/withState-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test('withState accepts setState() callback', () => {
5656
act(() => {
5757
updateCounter(18, callback)
5858
})
59+
expect(callback).toHaveBeenCalledTimes(1)
5960
})
6061

6162
test('withState also accepts initialState as function of props', () => {

src/packages/recompose/__tests__/withStateHandlers-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ test('withStateHandlers initial state must be function or object or null or unde
8686
const Counter = withStateHandlers(1, {})(component)
8787
jest.spyOn(console, 'error').mockImplementation(() => {})
8888
render(<Counter />)
89-
expect(console.error.mock.calls.length > 0).toBe(true)
89+
expect(console.error).toHaveBeenCalled()
9090
})
9191

9292
test('withStateHandlers have access to props', () => {
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { createContext } from 'react'
22

3-
const store = {}
3+
const store = new Map()
44

55
export const getOrCreateContext = key => {
6-
if (!store[key]) {
7-
store[key] = createContext(undefined)
8-
if (process.env.NODE_ENV !== 'production') {
9-
store[key].displayName = key
10-
}
6+
const existing = store.get(key)
7+
if (existing) return existing
8+
const ctx = createContext(undefined)
9+
if (process.env.NODE_ENV !== 'production') {
10+
ctx.displayName = key
1111
}
12-
return store[key]
12+
store.set(key, ctx)
13+
return ctx
1314
}

yarn.lock

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
lru-cache "^5.1.1"
9999
semver "^6.3.1"
100100

101-
"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.28.6":
101+
"@babel/helper-create-class-features-plugin@^7.28.6":
102102
version "7.28.6"
103103
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.28.6.tgz#611ff5482da9ef0db6291bcd24303400bca170fb"
104104
integrity sha512-dTOdvsjnG3xNT9Y0AUg1wAl38y+4Rl4sf9caSQZOXdNqVn+H+HbbJ4IyyHaIqNR6SW9oJpA/RuRjsjCw2IdIow==
@@ -313,14 +313,6 @@
313313
"@babel/helper-plugin-utils" "^7.28.6"
314314
"@babel/traverse" "^7.28.6"
315315

316-
"@babel/plugin-proposal-class-properties@^7.18.0":
317-
version "7.18.6"
318-
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz#b110f59741895f7ec21a6fff696ec46265c446a3"
319-
integrity sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==
320-
dependencies:
321-
"@babel/helper-create-class-features-plugin" "^7.18.6"
322-
"@babel/helper-plugin-utils" "^7.18.6"
323-
324316
"@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2":
325317
version "7.21.0-placeholder-for-preset-env.2"
326318
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz#7844f9289546efa9febac2de4cfe358a050bd703"
@@ -499,7 +491,7 @@
499491
dependencies:
500492
"@babel/helper-plugin-utils" "^7.28.6"
501493

502-
"@babel/plugin-transform-class-properties@^7.28.6":
494+
"@babel/plugin-transform-class-properties@^7.25.0", "@babel/plugin-transform-class-properties@^7.28.6":
503495
version "7.28.6"
504496
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-class-properties/-/plugin-transform-class-properties-7.28.6.tgz#d274a4478b6e782d9ea987fda09bdb6d28d66b72"
505497
integrity sha512-dY2wS3I2G7D697VHndN91TJr8/AAfXQNt5ynCTI/MpxMsSzHp+52uNivYT5wCPax3whc47DR8Ba7cmlQMg24bw==

0 commit comments

Comments
 (0)