diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-28 05:10:34 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76 (patch) | |
tree | 52cafb673165eff83d3c75938ff5298ffbd8a68c /packages/utils/src/abi_encoder/calldata | |
parent | 2e79ce26cbeacdeb0ea52b7c2e3da68e8055e7c6 (diff) | |
download | dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.gz dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.bz2 dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.lz dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.xz dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.tar.zst dexon-0x-contracts-f31d4ddffd8dd97f2b2dc226f4f132d1c3192c76.zip |
Replaced null/undefined checks with lodash
Diffstat (limited to 'packages/utils/src/abi_encoder/calldata')
4 files changed, 10 insertions, 8 deletions
diff --git a/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts b/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts index 1c49a8c6c..654cbe26c 100644 --- a/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts +++ b/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts @@ -1,4 +1,5 @@ import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; import * as Constants from '../../utils/constants'; @@ -24,7 +25,7 @@ export class Pointer extends CalldataBlock { public toBuffer(): Buffer { const destinationOffset = - this._aliasFor !== undefined ? this._aliasFor.getOffsetInBytes() : this._dependency.getOffsetInBytes(); + !_.isUndefined(this._aliasFor) ? this._aliasFor.getOffsetInBytes() : this._dependency.getOffsetInBytes(); const parentOffset = this._parent.getOffsetInBytes(); const parentHeaderSize = this._parent.getHeaderSizeInBytes(); const pointer: number = destinationOffset - (parentOffset + parentHeaderSize); diff --git a/packages/utils/src/abi_encoder/calldata/calldata.ts b/packages/utils/src/abi_encoder/calldata/calldata.ts index a662f30b9..e93d63803 100644 --- a/packages/utils/src/abi_encoder/calldata/calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/calldata.ts @@ -44,7 +44,7 @@ export class Calldata { */ public toString(): string { // Sanity check: root block must be set - if (this._root === undefined) { + if (_.isUndefined(this._root)) { throw new Error('expected root'); } // Optimize, if flag set @@ -103,7 +103,7 @@ export class Calldata { */ private _optimize(): void { // Step 1/1 Create a reverse iterator (starts from the end of the calldata to the beginning) - if (this._root === undefined) { + if (_.isUndefined(this._root)) { throw new Error('expected root'); } const iterator = new ReverseCalldataIterator(this._root); @@ -136,7 +136,7 @@ export class Calldata { */ private _toCondensedString(): string { // Sanity check: must have a root block. - if (this._root === undefined) { + if (_.isUndefined(this._root)) { throw new Error('expected root'); } // Construct an array of buffers (one buffer for each block). @@ -175,7 +175,7 @@ export class Calldata { */ private _toAnnotatedString(): string { // Sanity check: must have a root block. - if (this._root === undefined) { + if (_.isUndefined(this._root)) { throw new Error('expected root'); } // Constants for constructing annotated string diff --git a/packages/utils/src/abi_encoder/calldata/iterator.ts b/packages/utils/src/abi_encoder/calldata/iterator.ts index 8e2b16a5a..5307f7944 100644 --- a/packages/utils/src/abi_encoder/calldata/iterator.ts +++ b/packages/utils/src/abi_encoder/calldata/iterator.ts @@ -55,7 +55,7 @@ abstract class BaseIterator implements Iterable<CalldataBlock> { _.each(set.getMembers(), (member: CalldataBlock) => { // Traverse child if it is a unique pointer. // A pointer that is an alias for another pointer is ignored. - if (member instanceof CalldataBlocks.Pointer && member.getAlias() === undefined) { + if (member instanceof CalldataBlocks.Pointer && _.isUndefined(member.getAlias())) { const dependency = member.getDependency(); queue.mergeBack(BaseIterator._createQueue(dependency)); } @@ -74,7 +74,7 @@ abstract class BaseIterator implements Iterable<CalldataBlock> { return { next: () => { const nextBlock = this.nextBlock(); - if (nextBlock !== undefined) { + if (!_.isUndefined(nextBlock)) { return { value: nextBlock, done: false, diff --git a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts index b13cbdfd9..dfd4cfa72 100644 --- a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts @@ -1,4 +1,5 @@ import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; import * as Constants from '../utils/constants'; import { Queue } from '../utils/queue'; @@ -68,7 +69,7 @@ export class RawCalldata { public toAbsoluteOffset(relativeOffset: number): number { const scopeOffset = this._scopes.peekFront(); - if (scopeOffset === undefined) { + if (_.isUndefined(scopeOffset)) { throw new Error(`Tried to access undefined scope.`); } const absoluteOffset = relativeOffset + scopeOffset; |