Skip to content

Commit 5d30424

Browse files
committed
fork impl instead of checking an invariant every call
1 parent 31ba7bf commit 5d30424

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,25 @@ export default {
7070
/**
7171
* SourceCode#getText that also works down to ESLint 3.0.0
7272
*/
73-
function getSource(node) {
74-
if (typeof context.getSource === 'function') {
75-
return context.getSource(node);
76-
} else {
77-
return context.sourceCode.getText(node);
78-
}
79-
}
73+
const getSource =
74+
typeof context.getSource === 'function'
75+
? node => {
76+
return context.getSource(node);
77+
}
78+
: node => {
79+
return context.sourceCode.getText(node);
80+
};
8081
/**
8182
* SourceCode#getScope that also works down to ESLint 3.0.0
8283
*/
83-
function getScope(node) {
84-
if (typeof context.getScope === 'function') {
85-
return context.getScope();
86-
} else {
87-
return context.sourceCode.getScope(node);
88-
}
89-
}
84+
const getScope =
85+
typeof context.getScope === 'function'
86+
? () => {
87+
return context.getScope();
88+
}
89+
: node => {
90+
return context.sourceCode.getScope(node);
91+
};
9092

9193
const scopeManager = context.getSourceCode().scopeManager;
9294

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,25 @@ export default {
151151
/**
152152
* SourceCode#getText that also works down to ESLint 3.0.0
153153
*/
154-
function getSource(node) {
155-
if (typeof context.getSource === 'function') {
156-
return context.getSource(node);
157-
} else {
158-
return context.sourceCode.getText(node);
159-
}
160-
}
154+
const getSource =
155+
typeof context.getSource === 'function'
156+
? node => {
157+
return context.getSource(node);
158+
}
159+
: node => {
160+
return context.sourceCode.getText(node);
161+
};
161162
/**
162163
* SourceCode#getScope that also works down to ESLint 3.0.0
163164
*/
164-
function getScope(node) {
165-
if (typeof context.getScope === 'function') {
166-
return context.getScope();
167-
} else {
168-
return context.sourceCode.getScope(node);
169-
}
170-
}
165+
const getScope =
166+
typeof context.getScope === 'function'
167+
? () => {
168+
return context.getScope();
169+
}
170+
: node => {
171+
return context.sourceCode.getScope(node);
172+
};
171173

172174
return {
173175
// Maintain code segment path stack as we traverse.

0 commit comments

Comments
 (0)