Skip to content

Commit 51366b0

Browse files
authored
Merge pull request #9 from oslabs-beta/louis/new-feature
added optional chaining and nullish colaescing in helper.ts and linkFiber.ts
2 parents 4a15165 + 37018a2 commit 51366b0

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/backend/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export const getHooksNames = (elementType: string): Array<string> => {
9696
* Check within each function declaration if there are hook declarations */
9797
ast.forEach(functionDec => {
9898
let declarationBody: any;
99-
if (functionDec.expression && functionDec.expression.body) declarationBody = functionDec.expression.body.body; // check if functionDec.expression.body exists, then set declarationBody to functionDec's body
100-
else declarationBody = functionDec.body ? functionDec.body.body : [];
99+
if (functionDec.expression?.body) declarationBody = functionDec.expression.body.body; // check if functionDec.expression.body exists, then set declarationBody to functionDec's body
100+
else declarationBody = functionDec.body?.body ?? [];
101101
// Traverse through the function's funcDecs and Expression Statements
102102
declarationBody.forEach((elem: any) => {
103103
// Hooks will always be contained in a variable declaration
@@ -114,7 +114,7 @@ export const getHooksNames = (elementType: string): Array<string> => {
114114
} else {
115115
// hook.init.object is '_useState2', '_useState4', etc.
116116
// eslint-disable-next-line no-lonely-if
117-
if (hook.init.object && hook.init.object.name) {
117+
if (hook.init.object?.name) {
118118
const varName: any = hook.init.object.name;
119119
if (!hooksNames[varName] && varName.match(/_use/)) {
120120
hooksNames[varName] = hook.id.name;

src/backend/linkFiber.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
110110
*/
111111
function traverseHooks(memoizedState: any): HookStates {
112112
const hooksStates: HookStates = [];
113-
while (memoizedState && memoizedState.queue) {
113+
while (memoizedState?.queue) {
114114
// the !== null conditional is necessary here for correctly displaying react hooks because TypeScript recognizes 0 and "" as null - DO NOT REMOVE
115115
if (memoizedState.memoizedState !== null) {
116116
hooksStates.push({
@@ -279,11 +279,7 @@ function createTree(
279279

280280
// We want to add this fiber node to the snapshot
281281
if (componentFound || newState === 'stateless' && !newState.hooksState) {
282-
if (
283-
currentFiber.child
284-
&& currentFiber.child.stateNode
285-
&& currentFiber.child.stateNode.setAttribute
286-
) {
282+
if (currentFiber.child?.stateNode?.setAttribute) {
287283
rtid = `fromLinkFiber${rtidCounter}`;
288284
// rtid = rtidCounter;
289285
// check if rtid is already present

0 commit comments

Comments
 (0)