Merge pull request #9020 from overleaf/bg-decaff-guard

decaff cleanup of __guard__ calls

GitOrigin-RevId: 0d61e4d44a2fda19285674040ba92e500deae78d
This commit is contained in:
Brian Gough
2022-07-29 08:03:23 +00:00
committed by Copybot
parent ac9cd2c96b
commit 8960e56e20
10 changed files with 13 additions and 133 deletions
@@ -9,7 +9,6 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@@ -93,12 +92,7 @@ module.exports = UpdateCompressor = {
},
compressRawUpdates(lastPreviousUpdate, rawUpdates) {
if (
__guard__(
lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined,
x => x.length
) > 1
) {
if (lastPreviousUpdate?.op?.length > 1) {
// if the last previous update was an array op, don't compress onto it.
// The avoids cases where array length changes but version number doesn't
return [lastPreviousUpdate].concat(
@@ -331,9 +325,3 @@ module.exports = UpdateCompressor = {
return ops
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}
+1 -13
View File
@@ -7,7 +7,6 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
@@ -37,12 +36,7 @@ module.exports = UpdateTrimmer = {
return callback(error)
}
logger.debug({ project_id, details }, 'got details')
if (
__guard__(
details != null ? details.features : undefined,
x => x.versioning
)
) {
if (details?.features?.versioning) {
return MongoManager.setProjectMetaData(
project_id,
{ preserveHistory: true },
@@ -71,9 +65,3 @@ module.exports = UpdateTrimmer = {
)
},
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null
? transform(value)
: undefined
}
@@ -99,12 +99,7 @@ module.exports = UpdatesManager = {
}
if (rawUpdates[0] != null && rawUpdates[0].v !== lastVersion + 1) {
const ts = __guard__(
lastCompressedUpdate != null
? lastCompressedUpdate.meta
: undefined,
x1 => x1.end_ts
)
const ts = lastCompressedUpdate?.meta?.end_ts
const last_timestamp = ts != null ? new Date(ts) : 'unknown time'
error = new Error(
`Tried to apply raw op at version ${rawUpdates[0].v} to last compressed update with version ${lastVersion} from ${last_timestamp}`