Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 3eb8cb7

Browse files
sqsfelixfbecker
authored andcommitted
chore: upgrade TypeScript and modernize practices (#202)
Upgrade TypeScript and modernize practices upgrade prettier to support new ECMAScript features upgrade @types/node to fix IteratorResult error ``` node_modules/@types/node/index.d.ts(169,11): error TS2300: Duplicate identifier 'IteratorResult'. node_modules/typescript/lib/lib.es2015.iterable.d.ts(41,6): error TS2300: Duplicate identifier 'IteratorResult'. ```
1 parent 6fdcb16 commit 3eb8cb7

File tree

10 files changed

+55
-58
lines changed

10 files changed

+55
-58
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@types/karma-webpack": "2.0.7",
4949
"@types/lodash": "4.14.149",
5050
"@types/mocha": "5.2.7",
51-
"@types/node": "10.9.4",
51+
"@types/node": "12.12.21",
5252
"@types/sinon": "7.0.13",
5353
"@types/webpack": "4.4.32",
5454
"@types/webpack-env": "1.15.0",
@@ -70,15 +70,15 @@
7070
"karma-sourcemap-loader": "^0.3.7",
7171
"karma-webpack": "^3.0.5",
7272
"mocha": "^6.1.4",
73-
"prettier": "^1.18.2",
73+
"prettier": "^1.19.1",
7474
"raw-loader": "^3.0.0",
7575
"rimraf": "^2.6.3",
7676
"semantic-release": "^15.6.3",
7777
"sinon": "^7.4.1",
7878
"sourcegraph": "^23.0.1",
7979
"ts-node": "^8.2.0",
8080
"tslint": "^5.20.0",
81-
"typescript": "^3.5.1",
81+
"typescript": "^3.7.4",
8282
"webpack": "^4.33.0",
8383
"webpack-cli": "^3.3.3"
8484
},

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface ErrorLike {
44
}
55

66
export const isErrorLike = (val: any): val is ErrorLike =>
7-
!!val && typeof val === 'object' && (!!val.stack || ('message' in val || 'code' in val)) && !('__typename' in val)
7+
!!val && typeof val === 'object' && (!!val.stack || 'message' in val || 'code' in val) && !('__typename' in val)
88

99
/**
1010
* Ensures a value is a proper Error, copying all properties if needed

src/hoverifier.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ describe('Hoverifier', () => {
587587

588588
const outputValues: {
589589
[key: string]: {
590-
hoverOrError: typeof LOADING | (HoverAttachment) | null | ErrorLike
590+
hoverOrError: typeof LOADING | HoverAttachment | null | ErrorLike
591591
actionsOrError: typeof LOADING | string[] | null | ErrorLike
592592
}
593593
} = {

src/hoverifier.ts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,7 @@ export function createHoverifier<C extends object, D, A>({
623623
/**
624624
* An Observable of scroll events on the document.
625625
*/
626-
const scrollEvents = fromEvent(document, 'scroll').pipe(
627-
observeOn(animationFrameScheduler),
628-
share()
629-
)
626+
const scrollEvents = fromEvent(document, 'scroll').pipe(observeOn(animationFrameScheduler), share())
630627

631628
/**
632629
* Returns the highlighted range for the given hover result and position.
@@ -674,9 +671,10 @@ export function createHoverifier<C extends object, D, A>({
674671
scrollBoundaries,
675672
...rest
676673
}: Omit<InternalHoverifierState<C, D, A>, 'mouseIsMoving' | 'hoverOverlayIsFixed'> &
677-
Omit<EventOptions<C>, 'resolveContext' | 'dom'> & { codeView: HTMLElement }): Observable<
678-
Omit<InternalHoverifierState<C, D, A>, 'mouseIsMoving' | 'hoverOverlayIsFixed'> & { codeView: HTMLElement }
679-
> => {
674+
Omit<EventOptions<C>, 'resolveContext' | 'dom'> & { codeView: HTMLElement }): Observable<Omit<
675+
InternalHoverifierState<C, D, A>,
676+
'mouseIsMoving' | 'hoverOverlayIsFixed'
677+
> & { codeView: HTMLElement }> => {
680678
const result = of({ hoveredTokenElement, ...rest })
681679
if (!hoveredTokenElement || !scrollBoundaries) {
682680
return result
@@ -702,20 +700,18 @@ export function createHoverifier<C extends object, D, A>({
702700
* For every position, emits an Observable with new values for the `hoverOrError` state.
703701
* This is a higher-order Observable (Observable that emits Observables).
704702
*/
705-
const hoverObservables: Observable<
706-
Observable<{
707-
eventType: SupportedMouseEvent | 'jump'
708-
dom: DOMFunctions
709-
target: HTMLElement
710-
adjustPosition?: PositionAdjuster<C>
711-
codeView: HTMLElement
712-
codeViewId: symbol
713-
scrollBoundaries?: HTMLElement[]
714-
hoverOrError?: typeof LOADING | (HoverAttachment & D) | ErrorLike | null
715-
position?: HoveredToken & C
716-
part?: DiffPart
717-
}>
718-
> = resolvedPositions.pipe(
703+
const hoverObservables: Observable<Observable<{
704+
eventType: SupportedMouseEvent | 'jump'
705+
dom: DOMFunctions
706+
target: HTMLElement
707+
adjustPosition?: PositionAdjuster<C>
708+
codeView: HTMLElement
709+
codeViewId: symbol
710+
scrollBoundaries?: HTMLElement[]
711+
hoverOrError?: typeof LOADING | (HoverAttachment & D) | ErrorLike | null
712+
position?: HoveredToken & C
713+
part?: DiffPart
714+
}>> = resolvedPositions.pipe(
719715
map(({ position, codeViewId, ...rest }) => {
720716
if (!position) {
721717
return of({ hoverOrError: null, position: undefined, part: undefined, codeViewId, ...rest })
@@ -728,14 +724,7 @@ export function createHoverifier<C extends object, D, A>({
728724
// 1. Reset the hover content, so no old hover content is displayed at the new position while getting
729725
// 2. Show a loader if the hover hasn't returned after 100ms
730726
// 3. Show the hover once it returned
731-
return merge(
732-
[undefined],
733-
of(LOADING).pipe(
734-
delay(LOADER_DELAY),
735-
takeUntil(hover)
736-
),
737-
hover
738-
).pipe(
727+
return merge([undefined], of(LOADING).pipe(delay(LOADER_DELAY), takeUntil(hover)), hover).pipe(
739728
map(hoverOrError => ({
740729
...rest,
741730
codeViewId,

src/overlay_position.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('overlay_position', () => {
4747
position: absolute;
4848
}
4949
`
50-
document.head!.appendChild(style)
50+
document.head.appendChild(style)
5151

5252
relativeElement = document.createElement('div')
5353
relativeElement.className = 'relative-element'

src/testutils/dom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const createSourcegraphCodeView = (): CodeViewProps => {
187187
*/
188188
export class DOM {
189189
/** The inserted nodes. We save them so that we can remove them on cleanup. */
190-
private nodes = new Set<Element>()
190+
private readonly nodes = new Set<Element>()
191191

192192
/**
193193
* Creates and inserts the generated test cases into the DOM
@@ -211,7 +211,7 @@ export class DOM {
211211
public createElementFromString(html: string): HTMLDivElement {
212212
const element = createElementFromString(html)
213213
this.insert(element)
214-
return element as HTMLDivElement
214+
return element
215215
}
216216

217217
/**

src/testutils/fixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function createStubHoverProvider(
2626
hover: Partial<HoverAttachment> = {},
2727
delayTime?: number
2828
): HoverProvider<{}, {}> {
29-
return () => of(createHoverAttachment(hover)).pipe(delay(delayTime || 0))
29+
return () => of(createHoverAttachment(hover)).pipe(delay(delayTime ?? 0))
3030
}
3131

3232
/**
@@ -37,5 +37,5 @@ export function createStubHoverProvider(
3737
* @param delayTime optionally delay the fetch
3838
*/
3939
export function createStubActionsProvider<A>(actions: A[], delayTime?: number): ActionsProvider<{}, A> {
40-
return () => of(actions).pipe(delay(delayTime || 0))
40+
return () => of(actions).pipe(delay(delayTime ?? 0))
4141
}

src/token_position.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,14 @@ describe('token_positions', () => {
304304
position: { line: 2, endLine: 4 },
305305
getCodeElementFromLineNumber: (codeView, line) => codeView.children[line - 1] as HTMLElement,
306306
})
307-
assert.deepStrictEqual(codeElements.map(({ line, element }) => ({ line, content: element.textContent })), [
308-
{ line: 2, content: 'Line 2' },
309-
{ line: 3, content: 'Line 3' },
310-
{ line: 4, content: 'Line 4' },
311-
])
307+
assert.deepStrictEqual(
308+
codeElements.map(({ line, element }) => ({ line, content: element.textContent })),
309+
[
310+
{ line: 2, content: 'Line 2' },
311+
{ line: 3, content: 'Line 3' },
312+
{ line: 4, content: 'Line 4' },
313+
]
314+
)
312315
})
313316

314317
it('returns all code elements within a given range on a diff code view')

src/token_position.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function convertNode(parentNode: HTMLElement): void {
109109
const isLastNode = i === parentNode.childNodes.length - 1
110110

111111
if (node.nodeType === Node.TEXT_NODE) {
112-
let nodeText = node.textContent || ''
112+
let nodeText = node.textContent ?? ''
113113
if (nodeText === '') {
114114
continue
115115
}
@@ -160,7 +160,7 @@ const enum TokenType {
160160
* @param node The node containing the token.
161161
*/
162162
function getTokenType(node: Node): TokenType {
163-
const text = node.textContent || ''
163+
const text = node.textContent ?? ''
164164
if (text.length === 0) {
165165
return TokenType.Other
166166
}
@@ -271,7 +271,7 @@ export function findElementWithOffset(
271271
// Find the text node that is at the given offset.
272272
let targetNode: Node | undefined
273273
for (const [i, node] of textNodes.entries()) {
274-
const text = node.textContent || ''
274+
const text = node.textContent ?? ''
275275
if (offsetStep <= offset && offsetStep + text.length > offset) {
276276
targetNode = node
277277
nodeIndex = i
@@ -392,7 +392,7 @@ export function locateTarget(
392392
return { line }
393393
}
394394

395-
const part = getDiffCodePart && getDiffCodePart(codeElement)
395+
const part = getDiffCodePart?.(codeElement)
396396
let ignoreFirstCharacter = !!isFirstCharacterDiffIndicator && isFirstCharacterDiffIndicator(codeElement)
397397

398398
let character = 1
@@ -489,7 +489,7 @@ export const getTokenAtPosition = (
489489
return undefined
490490
}
491491
// On diff pages, account for the +/- indicator
492-
if (isFirstCharacterDiffIndicator && isFirstCharacterDiffIndicator(codeElement)) {
492+
if (isFirstCharacterDiffIndicator?.(codeElement)) {
493493
character++
494494
}
495495

yarn.lock

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@
486486
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.8.tgz#e469b4bf9d1c9832aee4907ba8a051494357c12c"
487487
integrity sha512-aX+gFgA5GHcDi89KG5keey2zf0WfZk/HAQotEamsK2kbey+8yGKcson0hbK8E+v0NArlCJQCqMP161YhV6ZXLg==
488488

489-
"@types/node@10.9.4":
490-
version "10.9.4"
491-
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.9.4.tgz#0f4cb2dc7c1de6096055357f70179043c33e9897"
492-
integrity sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw==
489+
"@types/node@12.12.21":
490+
version "12.12.21"
491+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.21.tgz#aa44a6363291c7037111c47e4661ad210aded23f"
492+
integrity sha512-8sRGhbpU+ck1n0PGAUgVrWrWdjSW2aqNeyC15W88GRsMpSwzv6RJGlLhE7s2RhVSOdyDmxbqlWSeThq4/7xqlA==
493493

494494
"@types/normalize-package-data@^2.4.0":
495495
version "2.4.0"
@@ -5906,11 +5906,16 @@ prepend-http@^1.0.1:
59065906
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
59075907
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
59085908

5909-
prettier@^1.17.0, prettier@^1.18.2:
5909+
prettier@^1.17.0:
59105910
version "1.18.2"
59115911
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"
59125912
integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==
59135913

5914+
prettier@^1.19.1:
5915+
version "1.19.1"
5916+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
5917+
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
5918+
59145919
process-nextick-args@~2.0.0:
59155920
version "2.0.0"
59165921
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa"
@@ -7470,10 +7475,10 @@ typedarray@^0.0.6:
74707475
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
74717476
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
74727477

7473-
typescript@^3.5.1:
7474-
version "3.5.1"
7475-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.1.tgz#ba72a6a600b2158139c5dd8850f700e231464202"
7476-
integrity sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw==
7478+
typescript@^3.7.4:
7479+
version "3.7.4"
7480+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
7481+
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==
74777482

74787483
uglify-js@^3.1.4:
74797484
version "3.4.9"

0 commit comments

Comments
 (0)