Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Optional Chaining (?.) #4

Merged
merged 2 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/bin/arrow2csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function batchesToString(state: ToStringState, schema: Schema) {
},
transform(batch: RecordBatch, _enc: string, cb: (error?: Error, data?: any) => void) {

batch = !(state.schema && state.schema.length) ? batch : batch.select(...state.schema);
batch = !state.schema?.length ? batch : batch.select(...state.schema);

if (state.closed) { return cb(undefined, null); }

Expand Down
4 changes: 2 additions & 2 deletions js/src/io/node/iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class IterableReadable<T extends Uint8Array | any> extends Readable {
}
if (!this.push(r.value) || size <= 0) { break; }
}
if ((r && r.done || !this.readable) && (this.push(null) || true)) {
if ((r?.done || !this.readable) && (this.push(null) || true)) {
it.return && it.return();
}
return !this.readable;
Expand Down Expand Up @@ -105,7 +105,7 @@ class AsyncIterableReadable<T extends Uint8Array | any> extends Readable {
}
if (!this.push(r.value) || size <= 0) { break; }
}
if ((r && r.done || !this.readable) && (this.push(null) || true)) {
if ((r?.done || !this.readable) && (this.push(null) || true)) {
it.return && it.return();
}
return !this.readable;
Expand Down
2 changes: 1 addition & 1 deletion js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class Table<T extends { [key: string]: DataType } = any>

const chunks = selectArgs<RecordBatch<T>>(RecordBatch, args);

if (!schema && !(schema = chunks[0] && chunks[0].schema)) {
if (!schema && !(schema = chunks[0]?.schema)) {
throw new TypeError('Table must be initialized with a Schema or at least one RecordBatch');
}

Expand Down
2 changes: 1 addition & 1 deletion js/src/util/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function _selectFieldArgs<T extends { [key: string]: DataType }>(vals: any[], re
({ [idx]: field = idx } = keys);
if (val instanceof DataType && (values[++valueIndex] = val)) {
fields[++fieldIndex] = Field.new(field, val as DataType, true) as Field<T[keyof T]>;
} else if (val && val.type && (values[++valueIndex] = val)) {
} else if (val?.type && (values[++valueIndex] = val)) {
val instanceof Data && (values[valueIndex] = val = Vector.new(val) as Vector);
fields[++fieldIndex] = Field.new(field, val.type, true) as Field<T[keyof T]>;
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/util/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export async function* toArrayBufferViewAsyncIterator<T extends TypedArray>(Arra
yield* pump((function*(it: Iterator<any>) {
let r: IteratorResult<any> = <any> null;
do {
r = it.next(yield r && r.value);
r = it.next(yield r?.value);
} while (!r.done);
})(source[Symbol.iterator]()));
};
Expand Down
4 changes: 2 additions & 2 deletions js/test/Arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Object.defineProperty(Object, Symbol.hasInstance, {
writable: true,
configurable: true,
value(inst: any) {
return inst && inst.constructor && inst.constructor.name === 'Object';
return inst?.constructor && inst.constructor.name === 'Object';
}
});
Object.defineProperty(ArrayBuffer, Symbol.hasInstance, {
writable: true,
configurable: true,
value(inst: any) {
return inst && inst.constructor && inst.constructor.name === 'ArrayBuffer';
return inst?.constructor && inst.constructor.name === 'ArrayBuffer';
}
});

Expand Down
2 changes: 1 addition & 1 deletion js/test/unit/builders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function validateVector<T extends DataType>(vals: (T['TValue'] | null)[],
// debugger;
// vec.get(i);
throw new Error([
`${(vec as any).VectorName}[${i}]: ${e && e.stack || e}`,
`${(vec as any).VectorName}[${i}]: ${e?.stack || e}`,
`nulls: [${nullVals.join(', ')}]`,
`values: [${vals.join(', ')}]`,
].join('\n'));
Expand Down