Skip to content

Commit

Permalink
Null chaining for [] and ()
Browse files Browse the repository at this point in the history
  • Loading branch information
rcebulko committed May 13, 2021
1 parent 9540be7 commit dcf39a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/core/data-structures/finite-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ export class FiniteStateMachine {
this.state_ = newState;

const transition = this.statesToTransition_(oldState, newState);
const callback = this.transitions_[transition];

if (callback) {
callback();
}
this.transitions_[transition]?.();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/data-structures/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class LastAddedResolver {
this.count_ = 0;

if (opt_promises) {
for (let i = 0; i < opt_promises.length; i++) {
this.add(opt_promises[i]);
for (const promise of opt_promises) {
this.add(promise);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/core/data-structures/signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Signals {
* @return {!Promise<!TimestampDef>}
*/
whenSignal(name) {
let promiseStruct = this.promiseMap_ && this.promiseMap_[name];
let promiseStruct = this.promiseMap_?.[name];
if (!promiseStruct) {
const result = this.map_[name];
if (result != null) {
Expand Down Expand Up @@ -101,9 +101,9 @@ export class Signals {
// Do not duplicate signals.
return;
}
const time = opt_time == undefined ? Date.now() : opt_time;
const time = opt_time ?? Date.now();
this.map_[name] = time;
const promiseStruct = this.promiseMap_ && this.promiseMap_[name];
const promiseStruct = this.promiseMap_?.[name];
if (promiseStruct?.resolve) {
promiseStruct.resolve(time);
promiseStruct.resolve = undefined;
Expand All @@ -123,7 +123,7 @@ export class Signals {
return;
}
this.map_[name] = error;
const promiseStruct = this.promiseMap_ && this.promiseMap_[name];
const promiseStruct = this.promiseMap_?.[name];
if (promiseStruct?.reject) {
promiseStruct.reject(error);
promiseStruct.promise.catch(() => {});
Expand All @@ -141,7 +141,7 @@ export class Signals {
delete this.map_[name];
}
// Reset promise it has already been resolved.
const promiseStruct = this.promiseMap_ && this.promiseMap_[name];
const promiseStruct = this.promiseMap_?.[name];
if (promiseStruct && !promiseStruct.resolve) {
delete this.promiseMap_[name];
}
Expand Down
10 changes: 3 additions & 7 deletions src/core/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
export function duplicateErrorIfNecessary(error) {
const messageProperty = Object.getOwnPropertyDescriptor(error, 'message');
if (messageProperty && messageProperty.writable) {
if (messageProperty?.writable) {
return error;
}

Expand All @@ -44,8 +44,7 @@ export function duplicateErrorIfNecessary(error) {
export function createErrorVargs(var_args) {
let error = null;
let message = '';
for (let i = 0; i < arguments.length; i++) {
const arg = arguments[i];
for (const arg of arguments) {
if (arg instanceof Error && !error) {
error = duplicateErrorIfNecessary(arg);
} else {
Expand Down Expand Up @@ -74,10 +73,7 @@ export function rethrowAsync(var_args) {
setTimeout(() => {
// __AMP_REPORT_ERROR is installed globally per window in the entry point.
// It may not exist for Bento components without the runtime.
if (self.__AMP_REPORT_ERROR) {
self.__AMP_REPORT_ERROR(error);
}

self.__AMP_REPORT_ERROR?.(error);
throw error;
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/types/object/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export function tryParseJson(json, opt_onFailed) {
try {
return parseJson(json);
} catch (e) {
if (opt_onFailed) {
opt_onFailed(e);
}
opt_onFailed.?(e);
return null;
}
}
Expand Down

0 comments on commit dcf39a5

Please sign in to comment.