Skip to content

Commit 1048a43

Browse files
mydeaLms24
andauthored
ref: Use optional chaining where possible (#14954)
This PR updates our code to use optional chaining, where possible. This was mostly search-and-replace by `xx && xx.` regex, so there may def. be some remaining places, but this should cover a good amount of usage. --------- Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
1 parent 6779dfe commit 1048a43

File tree

123 files changed

+216
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+216
-232
lines changed

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/customOnErrorHandler/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const oldOnError = window.onerror;
22

33
window.onerror = function () {
44
console.log('custom error');
5-
oldOnError && oldOnError.apply(this, arguments);
5+
oldOnError?.apply(this, arguments);
66
};
77

88
window.doSomethingWrong();

dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Sentry.init({
1313
// Also, no SDK has mock utils for FlagUsedHandler's.
1414
const MockLaunchDarkly = {
1515
initialize(_clientId, context, options) {
16-
const flagUsedHandler = options && options.inspectors ? options.inspectors[0].method : undefined;
16+
const flagUsedHandler = options.inspectors ? options.inspectors[0].method : undefined;
1717

1818
return {
1919
variation(key, defaultValue) {

dev-packages/browser-integration-tests/suites/old-sdk-interop/acs/getCurrentScope/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const sentryCarrier = window && window.__SENTRY__;
1+
const sentryCarrier = window?.__SENTRY__;
22

33
/**
44
* Simulate an old pre v8 SDK obtaining the hub from the global sentry carrier

dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/isOlderThan/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const sentryCarrier = window && window.__SENTRY__;
1+
const sentryCarrier = window?.__SENTRY__;
22

33
/**
44
* Simulate an old pre v8 SDK obtaining the hub from the global sentry carrier

dev-packages/e2e-tests/test-applications/create-remix-app-express-legacy/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

dev-packages/e2e-tests/test-applications/create-remix-app-express/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

dev-packages/e2e-tests/test-applications/create-remix-app-legacy/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

dev-packages/e2e-tests/test-applications/create-remix-app-v2-legacy/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

dev-packages/e2e-tests/test-applications/create-remix-app-v2/app/routes/navigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function LoaderError() {
1414

1515
return (
1616
<div>
17-
<h1>{data && data.test ? data.test : 'Not Found'}</h1>
17+
<h1>{data?.test ? data.test : 'Not Found'}</h1>
1818
</div>
1919
);
2020
}

0 commit comments

Comments
 (0)