Skip to content

Commit

Permalink
Remove unnecessary variable
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Oct 14, 2022
1 parent 10ee63d commit 0976bb9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/scriptlets/xml-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
}

let shouldPruneResponse = true;
let shouldLogResponse = false;
// eslint-disable-next-line no-console
const log = console.log.bind(console);
if (!propsToRemove) {
// If "propsToRemove" is not defined, then response shouldn't be pruned
// but it should be logged in browser console
shouldPruneResponse = false;
shouldLogResponse = true;
}

const urlMatchRegexp = toRegExp(urlToMatch);
Expand Down Expand Up @@ -125,15 +123,12 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
if (thisArg.readyState === 4) {
const { response } = thisArg;
thisArg.removeEventListener('readystatechange', pruneResponse);
if (!shouldPruneResponse && shouldLogResponse) {
if (!shouldPruneResponse) {
if (isXML(response)) {
log(`XMLHttpRequest.open() URL: ${xhrURL}\nresponse: ${response}`);
}
} else {
shouldPruneResponse = true;
const prunedResponseContent = pruneXML(response);
// pruneXML set shouldPruneResponse to false
// in case if response shouldn't be pruned
if (shouldPruneResponse) {
Object.defineProperty(thisArg, 'response', {
value: prunedResponseContent,
Expand All @@ -143,6 +138,11 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
});
hit(source);
}
// In case if response shouldn't be pruned
// pruneXML sets shouldPruneResponse to false
// so it's necessary to set it to true again
// otherwise response will be only logged
shouldPruneResponse = true;
}
}
});
Expand All @@ -167,15 +167,12 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
if (urlMatchRegexp.test(fetchURL)) {
return nativeFetch.apply(this, args).then((response) => {
return response.text().then((text) => {
if (!shouldPruneResponse && shouldLogResponse) {
if (!shouldPruneResponse) {
if (isXML(text)) {
log(`fetch URL: ${fetchURL}\nresponse text: ${text}`);
}
return Reflect.apply(target, thisArg, args);
}
shouldPruneResponse = true;
// pruneXML set shouldPruneResponse to false
// in case if response shouldn't be pruned
const prunedText = pruneXML(text);
if (shouldPruneResponse) {
hit(source);
Expand All @@ -185,6 +182,11 @@ export function xmlPrune(source, propsToRemove, optionalProp = '', urlToMatch) {
headers: response.headers,
});
}
// In case if response shouldn't be pruned
// pruneXML sets shouldPruneResponse to false
// so it's necessary to set it to true again
// otherwise response will be only logged
shouldPruneResponse = true;
return Reflect.apply(target, thisArg, args);
});
});
Expand Down

0 comments on commit 0976bb9

Please sign in to comment.