diff --git a/package.json b/package.json index c416e4f469..f2591d0383 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "ts-loader": "^4.5.0", "tslint": "^5.9.1", "tslint-consistent-codestyle": "^1.13.0", - "typescript": "2.8.3", + "typescript": "3.0", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "webpack": "^4.17.1", diff --git a/src/Buffer.ts b/src/Buffer.ts index 81b8a517dc..9487be4a67 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -5,7 +5,7 @@ import { CircularList } from './common/CircularList'; import { CharData, ITerminal, IBuffer, IBufferLine } from './Types'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './common/EventEmitter'; import { IMarker } from 'xterm'; import { BufferLine } from './BufferLine'; diff --git a/src/BufferSet.ts b/src/BufferSet.ts index 4b5ca2d13b..c91ab751f1 100644 --- a/src/BufferSet.ts +++ b/src/BufferSet.ts @@ -5,7 +5,7 @@ import { ITerminal, IBufferSet } from './Types'; import { Buffer } from './Buffer'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './common/EventEmitter'; /** * The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 8615daf8e7..74fc72db8a 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -6,7 +6,7 @@ import { IMouseZoneManager } from './ui/Types'; import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkHoverEventTypes, ILinkMatcherOptions, ILinkifier, ITerminal, IBufferLine } from './Types'; import { MouseZone } from './ui/MouseZoneManager'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './common/EventEmitter'; import { CHAR_DATA_ATTR_INDEX } from './Buffer'; /** diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 2dd92c5b62..bfb5717732 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -3,11 +3,12 @@ * @license MIT */ -import { ITerminal, ISelectionManager, IBuffer, CharData, XtermListener, IBufferLine } from './Types'; +import { ITerminal, ISelectionManager, IBuffer, CharData, IBufferLine } from './Types'; +import { XtermListener } from './common/Types'; import { MouseHelper } from './utils/MouseHelper'; import * as Browser from './shared/utils/Browser'; import { CharMeasure } from './ui/CharMeasure'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './common/EventEmitter'; import { SelectionModel } from './SelectionModel'; import { CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_CODE_INDEX } from './Buffer'; import { AltClickHandler } from './handlers/AltClickHandler'; diff --git a/src/Terminal.ts b/src/Terminal.ts index 3927d8b5da..ef9cb9ab68 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -27,7 +27,7 @@ import { IRenderer } from './renderer/Types'; import { BufferSet } from './BufferSet'; import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; import { CompositionHelper } from './CompositionHelper'; -import { EventEmitter } from './EventEmitter'; +import { EventEmitter } from './common/EventEmitter'; import { Viewport } from './Viewport'; import { rightClickHandler, moveTextAreaUnderMouseCursor, pasteHandler, copyHandler } from './handlers/Clipboard'; import { C0 } from './common/data/EscapeSequences'; diff --git a/src/Types.ts b/src/Types.ts index 21c6c57105..df3f1a7984 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -7,11 +7,10 @@ import { Terminal as PublicTerminal, ITerminalOptions as IPublicTerminalOptions, import { IColorSet, IRenderer } from './renderer/Types'; import { IMouseZoneManager } from './ui/Types'; import { ICharset } from './core/Types'; +import { ICircularList } from './common/Types'; export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean; -export type XtermListener = (...args: any[]) => void; - export type CharData = [number, string, number, number]; export type LineData = CharData[]; @@ -294,19 +293,6 @@ export interface IBufferSet extends IEventEmitter { activateAltBuffer(): void; } -export interface ICircularList extends IEventEmitter { - length: number; - maxLength: number; - - get(index: number): T; - set(index: number, value: T): void; - push(value: T): void; - pop(): T; - splice(start: number, deleteCount: number, ...items: T[]): void; - trimStart(count: number): void; - shiftElements(start: number, count: number, offset: number): void; -} - export interface ISelectionManager { selectionText: string; selectionStart: [number, number]; diff --git a/src/common/CircularList.ts b/src/common/CircularList.ts index ca83d6e172..542dbf12ab 100644 --- a/src/common/CircularList.ts +++ b/src/common/CircularList.ts @@ -3,15 +3,15 @@ * @license MIT */ -import { EventEmitter } from '../EventEmitter'; -import { ICircularList } from '../Types'; +import { EventEmitter } from './EventEmitter'; +import { ICircularList } from './Types'; /** * Represents a circular list; a list with a maximum size that wraps around when push is called, * overriding values at the start of the list. */ export class CircularList extends EventEmitter implements ICircularList { - protected _array: T[]; + protected _array: (T | undefined)[]; private _startIndex: number; private _length: number; @@ -36,7 +36,7 @@ export class CircularList extends EventEmitter implements ICircularList { // Reconstruct array, starting at index 0. Only transfer values from the // indexes 0 to length. - const newArray = new Array(newMaxLength); + const newArray = new Array(newMaxLength); for (let i = 0; i < Math.min(newMaxLength, this.length); i++) { newArray[i] = this._array[this._getCyclicIndex(i)]; } @@ -66,7 +66,7 @@ export class CircularList extends EventEmitter implements ICircularList { * @param index The index of the value to get. * @return The value corresponding to the index. */ - public get(index: number): T { + public get(index: number): T | undefined { return this._array[this._getCyclicIndex(index)]; } @@ -78,7 +78,7 @@ export class CircularList extends EventEmitter implements ICircularList { * @param index The index to set. * @param value The value to set. */ - public set(index: number, value: T): void { + public set(index: number, value: T | undefined): void { this._array[this._getCyclicIndex(index)] = value; } @@ -104,7 +104,7 @@ export class CircularList extends EventEmitter implements ICircularList { * Removes and returns the last value on the list. * @return The popped value. */ - public pop(): T { + public pop(): T | undefined { return this._array[this._getCyclicIndex(this._length-- - 1)]; } diff --git a/src/EventEmitter.test.ts b/src/common/EventEmitter.test.ts similarity index 100% rename from src/EventEmitter.test.ts rename to src/common/EventEmitter.test.ts diff --git a/src/EventEmitter.ts b/src/common/EventEmitter.ts similarity index 94% rename from src/EventEmitter.ts rename to src/common/EventEmitter.ts index 0de5999ae1..ae8f0069dc 100644 --- a/src/EventEmitter.ts +++ b/src/common/EventEmitter.ts @@ -5,7 +5,7 @@ import { XtermListener } from './Types'; import { IEventEmitter, IDisposable } from 'xterm'; -import { Disposable } from './common/Lifecycle'; +import { Disposable } from './Lifecycle'; export class EventEmitter extends Disposable implements IEventEmitter, IDisposable { private _events: {[type: string]: XtermListener[]}; @@ -30,14 +30,15 @@ export class EventEmitter extends Disposable implements IEventEmitter, IDisposab public addDisposableListener(type: string, handler: XtermListener): IDisposable { // TODO: Rename addDisposableEventListener to more easily disambiguate from Dom listener this.on(type, handler); + let disposed = false; return { dispose: () => { - if (!handler) { + if (disposed) { // Already disposed return; } this.off(type, handler); - handler = null; + disposed = true; } }; } diff --git a/src/common/Types.ts b/src/common/Types.ts index 98cb296d3e..aabe721eb5 100644 --- a/src/common/Types.ts +++ b/src/common/Types.ts @@ -3,6 +3,10 @@ * @license MIT */ +import { IEventEmitter } from 'xterm'; + +export type XtermListener = (...args: any[]) => void; + /** * A keyboard event interface which does not depend on the DOM, KeyboardEvent implicitly extends * this event. @@ -16,3 +20,16 @@ export interface IKeyboardEvent { key: string; type: string; } + +export interface ICircularList extends IEventEmitter { + length: number; + maxLength: number; + + get(index: number): T | undefined; + set(index: number, value: T): void; + push(value: T): void; + pop(): T | undefined; + splice(start: number, deleteCount: number, ...items: T[]): void; + trimStart(count: number): void; + shiftElements(start: number, count: number, offset: number): void; +} diff --git a/src/handlers/AltClickHandler.ts b/src/handlers/AltClickHandler.ts index aa942f3e72..8226fd96ca 100644 --- a/src/handlers/AltClickHandler.ts +++ b/src/handlers/AltClickHandler.ts @@ -3,7 +3,8 @@ * @license MIT */ -import { ITerminal, ICircularList, IBufferLine } from '../Types'; +import { ITerminal, IBufferLine } from '../Types'; +import { ICircularList } from '../common/Types'; import { C0 } from '../common/data/EscapeSequences'; const enum Direction { diff --git a/src/renderer/Renderer.ts b/src/renderer/Renderer.ts index a6189efc33..0232887766 100644 --- a/src/renderer/Renderer.ts +++ b/src/renderer/Renderer.ts @@ -10,7 +10,7 @@ import { ColorManager } from './ColorManager'; import { IRenderLayer, IColorSet, IRenderer, IRenderDimensions, ICharacterJoinerRegistry } from './Types'; import { ITerminal, CharacterJoinerHandler } from '../Types'; import { LinkRenderLayer } from './LinkRenderLayer'; -import { EventEmitter } from '../EventEmitter'; +import { EventEmitter } from '../common/EventEmitter'; import { RenderDebouncer } from '../ui/RenderDebouncer'; import { ScreenDprMonitor } from '../ui/ScreenDprMonitor'; import { ITheme } from 'xterm'; diff --git a/src/renderer/dom/DomRenderer.ts b/src/renderer/dom/DomRenderer.ts index b3f69ffcd5..9a2ef46983 100644 --- a/src/renderer/dom/DomRenderer.ts +++ b/src/renderer/dom/DomRenderer.ts @@ -6,7 +6,7 @@ import { IRenderer, IRenderDimensions, IColorSet } from '../Types'; import { ITerminal, CharacterJoinerHandler } from '../../Types'; import { ITheme } from 'xterm'; -import { EventEmitter } from '../../EventEmitter'; +import { EventEmitter } from '../../common/EventEmitter'; import { ColorManager } from '../ColorManager'; import { RenderDebouncer } from '../../ui/RenderDebouncer'; import { BOLD_CLASS, ITALIC_CLASS, CURSOR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory } from './DomRendererRowFactory'; diff --git a/src/ui/CharMeasure.ts b/src/ui/CharMeasure.ts index 5ad1de76ae..7d1e5e48af 100644 --- a/src/ui/CharMeasure.ts +++ b/src/ui/CharMeasure.ts @@ -4,7 +4,7 @@ */ import { ICharMeasure, ITerminalOptions } from '../Types'; -import { EventEmitter } from '../EventEmitter'; +import { EventEmitter } from '../common/EventEmitter'; /** * Utility class that measures the size of a character. Measurements are done in diff --git a/src/utils/TestUtils.test.ts b/src/utils/TestUtils.test.ts index b9bb034822..32a7e9bc03 100644 --- a/src/utils/TestUtils.test.ts +++ b/src/utils/TestUtils.test.ts @@ -4,7 +4,8 @@ */ import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from '../renderer/Types'; -import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ICircularList, ILinkifier, IMouseHelper, ILinkMatcherOptions, XtermListener, CharacterJoinerHandler, IBufferLine } from '../Types'; +import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferLine } from '../Types'; +import { ICircularList, XtermListener } from '../common/Types'; import { Buffer } from '../Buffer'; import * as Browser from '../shared/utils/Browser'; import { ITheme, IDisposable, IMarker } from 'xterm'; diff --git a/yarn.lock b/yarn.lock index 7e28a3c107..f12043f770 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5868,9 +5868,9 @@ typedarray@^0.0.6, typedarray@~0.0.5: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@2.8.3: - version "2.8.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" +typescript@3.0: + version "3.0.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8" uglify-es@^3.3.4: version "3.3.9"