mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:31:54 +00:00
More optional chaining (#6891)
* More optional chaining * Set target in tsconfig to transpile optional chaining
This commit is contained in:
parent
36a0d9ba0b
commit
765884306e
@ -2,7 +2,7 @@ import path from 'path'
|
||||
import webpack from 'webpack'
|
||||
|
||||
export default ({ config }: { config: webpack.Configuration }) => {
|
||||
if (!config.module || !config.resolve || !config.resolve.extensions) {
|
||||
if (!config.module || !config.resolve?.extensions) {
|
||||
throw new Error('unexpected config')
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import extensionInfo from '../../src/extension/manifest.spec.json'
|
||||
* @returns The current extension version from extension.info.json.
|
||||
*/
|
||||
export function generateBundleUID(): string {
|
||||
if (!extensionInfo || !extensionInfo.version) {
|
||||
if (!extensionInfo?.version) {
|
||||
throw new Error('Could not resolve extension version from manifest.')
|
||||
}
|
||||
return extensionInfo.version
|
||||
|
||||
@ -76,22 +76,25 @@ async function main(): Promise<void> {
|
||||
|
||||
// Add style sheet and wait for it to load to avoid rendering unstyled elements (which causes an
|
||||
// annoying flash/jitter when the stylesheet loads shortly thereafter).
|
||||
let styleSheet = document.getElementById('ext-style-sheet') as HTMLLinkElement | null
|
||||
// If does not exist, create
|
||||
if (!styleSheet) {
|
||||
styleSheet = document.createElement('link')
|
||||
styleSheet.id = 'ext-style-sheet'
|
||||
styleSheet.rel = 'stylesheet'
|
||||
styleSheet.type = 'text/css'
|
||||
styleSheet.href = browser.extension.getURL('css/style.bundle.css')
|
||||
}
|
||||
const styleSheet = (() => {
|
||||
let styleSheet = document.getElementById('ext-style-sheet') as HTMLLinkElement | null
|
||||
// If does not exist, create
|
||||
if (!styleSheet) {
|
||||
styleSheet = document.createElement('link')
|
||||
styleSheet.id = 'ext-style-sheet'
|
||||
styleSheet.rel = 'stylesheet'
|
||||
styleSheet.type = 'text/css'
|
||||
styleSheet.href = browser.extension.getURL('css/style.bundle.css')
|
||||
}
|
||||
return styleSheet
|
||||
})()
|
||||
// If not loaded yet, wait for it to load
|
||||
if (!styleSheet.sheet) {
|
||||
await new Promise(resolve => {
|
||||
styleSheet!.addEventListener('load', resolve, { once: true })
|
||||
styleSheet.addEventListener('load', resolve, { once: true })
|
||||
// If not appended yet, append to <head>
|
||||
if (!styleSheet!.parentNode) {
|
||||
document.head.appendChild(styleSheet!)
|
||||
if (!styleSheet.parentNode) {
|
||||
document.head.appendChild(styleSheet)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ export const createFileLineContainerToolbarMount: NonNullable<CodeView['getToolb
|
||||
mountEl.className = className
|
||||
const rawURLLink = codeViewElement.querySelector('#raw-url')
|
||||
const buttonGroup = rawURLLink?.closest('.BtnGroup')
|
||||
if (!buttonGroup || !buttonGroup.parentNode) {
|
||||
if (!buttonGroup?.parentNode) {
|
||||
throw new Error('File actions not found')
|
||||
}
|
||||
buttonGroup.parentNode.insertBefore(mountEl, buttonGroup)
|
||||
|
||||
@ -60,7 +60,7 @@ const getLineNumberFromCodeElement = (codeElement: HTMLElement): number => {
|
||||
const getCodeCellFromTarget = (target: HTMLElement): HTMLTableCellElement | null => {
|
||||
const cell = target.closest('td.blob-code') as HTMLTableCellElement
|
||||
// Handle rows with the [ ↕ ] button that expands collapsed unchanged lines
|
||||
if (!cell || cell.parentElement!.classList.contains('js-expandable-line')) {
|
||||
if (!cell?.parentElement?.classList.contains('js-expandable-line')) {
|
||||
return null
|
||||
}
|
||||
return cell
|
||||
|
||||
@ -63,7 +63,7 @@ export const resolveSnippetFileInfo = (codeView: HTMLElement): Observable<FileIn
|
||||
throw new Error('Could not find commit link in snippet code view')
|
||||
}
|
||||
const commitIDMatch = commitLinkElement.href.match(COMMIT_HASH_REGEX)
|
||||
if (!commitIDMatch || !commitIDMatch[1]) {
|
||||
if (!commitIDMatch?.[1]) {
|
||||
throw new Error(`Could not parse commitID from snippet commit link href: ${commitLinkElement.href}`)
|
||||
}
|
||||
const commitID = commitIDMatch[1]
|
||||
|
||||
@ -56,7 +56,7 @@ export function createDumpRouter(backend: Backend): express.Router {
|
||||
async (req: express.Request, res: express.Response): Promise<void> => {
|
||||
const { repository, id } = req.params
|
||||
const dump = await backend.dump(parseInt(id, 10))
|
||||
if (!dump || dump.repository !== decodeURIComponent(repository)) {
|
||||
if (dump?.repository !== decodeURIComponent(repository)) {
|
||||
throw Object.assign(new Error('LSIF dump not found'), { status: 404 })
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ export function createDumpRouter(backend: Backend): express.Router {
|
||||
async (req: express.Request, res: express.Response): Promise<void> => {
|
||||
const { repository, id } = req.params
|
||||
const dump = await backend.dump(parseInt(id, 10))
|
||||
if (!dump || dump.repository !== decodeURIComponent(repository)) {
|
||||
if (dump?.repository !== decodeURIComponent(repository)) {
|
||||
throw Object.assign(new Error('LSIF dump not found'), { status: 404 })
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ export function getComputedContextProperty(
|
||||
return !!component
|
||||
}
|
||||
if (key.startsWith('resource.')) {
|
||||
if (!component || component.type !== 'CodeEditor') {
|
||||
if (component?.type !== 'CodeEditor') {
|
||||
return null
|
||||
}
|
||||
// TODO(sqs): Define these precisely. If the resource is in a repository, what is the "path"? Is it the
|
||||
@ -73,7 +73,7 @@ export function getComputedContextProperty(
|
||||
}
|
||||
}
|
||||
if (key.startsWith('component.')) {
|
||||
if (!component || component.type !== 'CodeEditor') {
|
||||
if (component?.type !== 'CodeEditor') {
|
||||
return null
|
||||
}
|
||||
const prop = key.slice('component.'.length)
|
||||
@ -99,7 +99,7 @@ export function getComputedContextProperty(
|
||||
}
|
||||
}
|
||||
if (key.startsWith('panel.activeView.')) {
|
||||
if (!component || component.type !== 'panelView') {
|
||||
if (component?.type !== 'panelView') {
|
||||
return null
|
||||
}
|
||||
const prop = key.slice('panel.activeView.'.length)
|
||||
|
||||
@ -90,7 +90,7 @@ export function extensionIDsFromSettings(settings: SettingsCascadeOrError): stri
|
||||
if (isErrorLike(settings.final)) {
|
||||
throw asError(settings.final)
|
||||
}
|
||||
if (!settings.final || !settings.final.extensions) {
|
||||
if (!settings.final?.extensions) {
|
||||
return []
|
||||
}
|
||||
return Object.keys(settings.final.extensions)
|
||||
|
||||
@ -65,12 +65,7 @@ export function queryConfiguredRegistryExtensions(
|
||||
})
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (
|
||||
!data ||
|
||||
!data.extensionRegistry ||
|
||||
!data.extensionRegistry.extensions ||
|
||||
!data.extensionRegistry.extensions.nodes
|
||||
) {
|
||||
if (!data?.extensionRegistry?.extensions?.nodes) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.extensionRegistry.extensions.nodes.map(
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
{ "path": "dev/release" },
|
||||
],
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"target": "es2019",
|
||||
"module": "commonjs",
|
||||
"allowJs": false,
|
||||
"moduleResolution": "node",
|
||||
|
||||
@ -24,12 +24,7 @@ export function deleteRegistryExtensionWithConfirmation(extension: GQL.ID): Obse
|
||||
{ extension }
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (
|
||||
!data ||
|
||||
!data.extensionRegistry ||
|
||||
!data.extensionRegistry.deleteExtension ||
|
||||
(errors && errors.length > 0)
|
||||
) {
|
||||
if (!data?.extensionRegistry?.deleteExtension || (errors && errors.length > 0)) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
}),
|
||||
@ -59,12 +54,7 @@ export function queryViewerRegistryPublishers(): Observable<GQL.RegistryPublishe
|
||||
}
|
||||
`).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (
|
||||
!data ||
|
||||
!data.extensionRegistry ||
|
||||
!data.extensionRegistry.viewerPublishers ||
|
||||
(errors && errors.length > 0)
|
||||
) {
|
||||
if (!data?.extensionRegistry?.viewerPublishers || (errors && errors.length > 0)) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.extensionRegistry.viewerPublishers.map(p => ({
|
||||
|
||||
@ -116,7 +116,7 @@ function fetchViewerSettings(): Observable<GQL.ISettingsCascade> {
|
||||
${settingsCascadeFragment}
|
||||
`).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (!data || !data.viewerSettings) {
|
||||
if (!data?.viewerSettings) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.viewerSettings
|
||||
|
||||
@ -299,7 +299,7 @@ describe('Search regression test suite', () => {
|
||||
Array.from(document.querySelectorAll('.e2e-search-result'))
|
||||
.map(el => {
|
||||
const header = el.querySelector('[data-testid="result-container-header"')
|
||||
if (!header || !header.textContent) {
|
||||
if (!header?.textContent) {
|
||||
return null
|
||||
}
|
||||
const components = header.textContent.split(/\s/)
|
||||
|
||||
@ -126,17 +126,10 @@ export function waitForRepo(
|
||||
// and we have no guarantee that all the repositories from that external service
|
||||
// will exist when the add-external-service endpoint returns.
|
||||
tap(({ repository }) => {
|
||||
if (!repository || !repository.mirrorInfo || !repository.mirrorInfo.cloned) {
|
||||
if (!repository?.mirrorInfo?.cloned) {
|
||||
throw new CloneInProgressError(repoName)
|
||||
}
|
||||
if (
|
||||
mustBeIndexed &&
|
||||
!(
|
||||
repository.textSearchIndex &&
|
||||
repository.textSearchIndex.status &&
|
||||
repository.textSearchIndex.status.updatedAt
|
||||
)
|
||||
) {
|
||||
if (mustBeIndexed && !repository?.textSearchIndex?.status?.updatedAt) {
|
||||
throw new CloneInProgressError(repoName)
|
||||
}
|
||||
}),
|
||||
@ -602,7 +595,7 @@ export function createOrganization(
|
||||
mightContainPrivateInfo: false,
|
||||
}).pipe(
|
||||
mergeMap(({ data, errors }) => {
|
||||
if (!data || !data.createOrganization) {
|
||||
if (!data?.createOrganization) {
|
||||
eventLogger.log('NewOrgFailed')
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
@ -723,7 +716,7 @@ export function addExternalService(
|
||||
mightContainPrivateInfo: true,
|
||||
}).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (!data || !data.addExternalService || (errors && errors.length > 0)) {
|
||||
if (!data?.addExternalService || (errors && errors.length > 0)) {
|
||||
eventLogger.log('AddExternalServiceFailed')
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
|
||||
@ -163,13 +163,7 @@ const fetchHighlightedFile = memoizeObservable(
|
||||
ctx
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (
|
||||
!data ||
|
||||
!data.repository ||
|
||||
!data.repository.commit ||
|
||||
!data.repository.commit.file ||
|
||||
!data.repository.commit.file.highlight
|
||||
) {
|
||||
if (!data?.repository?.commit?.file?.highlight) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
const file = data.repository.commit.file
|
||||
@ -221,13 +215,7 @@ export const fetchFileExternalLinks = memoizeObservable(
|
||||
ctx
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (
|
||||
!data ||
|
||||
!data.repository ||
|
||||
!data.repository.commit ||
|
||||
!data.repository.commit.file ||
|
||||
!data.repository.commit.file.externalURLs
|
||||
) {
|
||||
if (!data?.repository?.commit?.file?.externalURLs) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.repository.commit.file.externalURLs
|
||||
@ -260,7 +248,7 @@ export const fetchTree = memoizeObservable(
|
||||
args
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (!data || errors || !data.repository || !data.repository.commit || !data.repository.commit.tree) {
|
||||
if (errors || !data?.repository?.commit?.tree) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.repository.commit.tree
|
||||
@ -296,7 +284,7 @@ export const fetchTreeEntries = memoizeObservable(
|
||||
args
|
||||
).pipe(
|
||||
map(({ data, errors }) => {
|
||||
if (!data || errors || !data.repository || !data.repository.commit || !data.repository.commit.tree) {
|
||||
if (errors || !data?.repository?.commit?.tree) {
|
||||
throw createAggregateError(errors)
|
||||
}
|
||||
return data.repository.commit.tree
|
||||
|
||||
Loading…
Reference in New Issue
Block a user