Tidied up a bit
Brian Vaughn committed
Jun 17, 2019 at 14:49 UTC
6c03f6abbdc2d9154ac908ff648d50a2a4d7ddb6
4 files changed
+43
-36
src/__tests__/inspectedElementContext-test.js
+1
@@ -335,6 +335,7 @@ describe('InspectedElementContext', () => {
335
expect(typed_array[meta.inspectable]).toBe(false);
336
expect(typed_array[meta.name]).toBe('Uint8Array');
337
expect(typed_array[meta.type]).toBe('typed_array');
338
+ expect(date[meta.inspectable]).toBe(false);
339
expect(date[meta.type]).toBe('date');
340
341
done();
src/__tests__/legacy/inspectElement-test.js
+7
@@ -124,20 +124,27 @@ describe('InspectedElementContext', () => {
124
typed_array,
125
date,
126
} = inspectedElement.value.props;
127
+ expect(html_element[meta.inspectable]).toBe(false);
128
expect(html_element[meta.name]).toBe('DIV');
129
expect(html_element[meta.type]).toBe('html_element');
130
+ expect(fn[meta.inspectable]).toBe(false);
131
expect(fn[meta.name]).toBe('exmapleFunction');
132
expect(fn[meta.type]).toBe('function');
133
+ expect(symbol[meta.inspectable]).toBe(false);
134
expect(symbol[meta.name]).toBe('Symbol(symbol)');
135
expect(symbol[meta.type]).toBe('symbol');
136
+ expect(react_element[meta.inspectable]).toBe(false);
137
expect(react_element[meta.name]).toBe('span');
138
expect(react_element[meta.type]).toBe('react_element');
139
expect(array_buffer[meta.size]).toBe(3);
140
+ expect(array_buffer[meta.inspectable]).toBe(false);
141
expect(array_buffer[meta.name]).toBe('ArrayBuffer');
142
expect(array_buffer[meta.type]).toBe('array_buffer');
143
expect(typed_array[meta.size]).toBe(3);
144
+ expect(typed_array[meta.inspectable]).toBe(false);
145
expect(typed_array[meta.name]).toBe('Uint8Array');
146
expect(typed_array[meta.type]).toBe('typed_array');
147
+ expect(date[meta.inspectable]).toBe(false);
148
expect(date[meta.type]).toBe('date');
149
150
done();
src/backend/legacy/renderer.js
+14
-16
@@ -562,22 +562,20 @@ export function attach(
562
});
563
}
564
565
- function isKeyedPathWhitelisted(
566
- key: string
567
- ): (path: Array<string | number>) => boolean {
568
- return (path: Array<string | number>) =>
569
- isPathWhitelisted([key].concat(path));
570
- }
571
-
572
- function isPathWhitelisted(path: Array<string | number>): boolean {
573
- let current = currentlyInspectedPaths;
574
- for (let i = 0; i < path.length; i++) {
575
- current = current[path[i]];
565
+ function createIsPathWhitelisted(key: string) {
566
+ return function isPathWhitelisted(path: Array<string | number>): boolean {
567
+ let current = currentlyInspectedPaths[key];
568
if (!current) {
569
return false;
570
}
579
- }
580
- return true;
571
+ for (let i = 0; i < path.length; i++) {
572
+ current = current[path[i]];
573
+ if (!current) {
574
+ return false;
575
+ }
576
+ }
577
+ return true;
578
+ };
579
}
580
581
function inspectElement(
@@ -603,15 +601,15 @@ export function attach(
601
602
inspectedElement.context = cleanForBridge(
603
inspectedElement.context,
606
- isKeyedPathWhitelisted('context')
604
+ createIsPathWhitelisted('context')
605
);
606
inspectedElement.props = cleanForBridge(
607
inspectedElement.props,
610
- isKeyedPathWhitelisted('props')
608
+ createIsPathWhitelisted('props')
609
);
610
inspectedElement.state = cleanForBridge(
611
inspectedElement.state,
614
- isKeyedPathWhitelisted('state')
612
+ createIsPathWhitelisted('state')
613
);
614
615
return {
src/backend/renderer.js
+21
-20
@@ -2147,26 +2147,27 @@ export function attach(
2147
});
2148
}
2149
2150
- function isKeyedPathWhitelisted(
2151
- key: string,
2152
- isHooks: boolean
2153
- ): (path: Array<string | number>) => boolean {
2154
- return (path: Array<string | number>) =>
2155
- isPathWhitelisted([key].concat(path)) ||
2150
+ function createIsPathWhitelisted(isHooksPath: boolean, key: string | null) {
2151
+ return function isPathWhitelisted(path: Array<string | number>): boolean {
2152
// Dehydrating the 'subHooks' property makes the HooksTree UI a lot more complicated,
2153
// so it's easiest for now if we just don't break on this boundary.
2158
- (isHooks && path[path.length - 1] === 'subHooks');
2159
- }
2154
+ if (isHooksPath && path[path.length - 1] === 'subHooks') {
2155
+ return true;
2156
+ }
2157
2161
- function isPathWhitelisted(path: Array<string | number>): boolean {
2162
- let current = currentlyInspectedPaths;
2163
- for (let i = 0; i < path.length; i++) {
2164
- current = current[path[i]];
2158
+ let current =
2159
+ key === null ? currentlyInspectedPaths : currentlyInspectedPaths[key];
2160
if (!current) {
2161
return false;
2162
}
2168
- }
2169
- return true;
2163
+ for (let i = 0; i < path.length; i++) {
2164
+ current = current[path[i]];
2165
+ if (!current) {
2166
+ return false;
2167
+ }
2168
+ }
2169
+ return true;
2170
+ };
2171
}
2172
2173
function inspectElement(
@@ -2190,7 +2191,7 @@ export function attach(
2191
((mostRecentlyInspectedElement: any): InspectedElement),
2192
path
2193
),
2193
- isPathWhitelisted,
2194
+ createIsPathWhitelisted(path[0] === 'hooks', null),
2195
path
2196
),
2197
};
@@ -2228,23 +2229,23 @@ export function attach(
2229
2230
cleanedInspectedElement.context = cleanForBridge(
2231
cleanedInspectedElement.context,
2231
- isKeyedPathWhitelisted('context', false)
2232
+ createIsPathWhitelisted(false, 'context')
2233
);
2234
cleanedInspectedElement.events = cleanForBridge(
2235
cleanedInspectedElement.events,
2235
- isKeyedPathWhitelisted('events', false)
2236
+ createIsPathWhitelisted(false, 'events')
2237
);
2238
cleanedInspectedElement.hooks = cleanForBridge(
2239
cleanedInspectedElement.hooks,
2239
- isKeyedPathWhitelisted('hooks', true)
2240
+ createIsPathWhitelisted(true, 'hooks')
2241
);
2242
cleanedInspectedElement.props = cleanForBridge(
2243
cleanedInspectedElement.props,
2243
- isKeyedPathWhitelisted('props', false)
2244
+ createIsPathWhitelisted(false, 'props')
2245
);
2246
cleanedInspectedElement.state = cleanForBridge(
2247
cleanedInspectedElement.state,
2247
- isKeyedPathWhitelisted('state', false)
2248
+ createIsPathWhitelisted(false, 'state')
2249
);
2250
2251
return {