Skip to content

Commit

Permalink
Changed <>-style type assertions to as.
Browse files Browse the repository at this point in the history
Easier to grep for and remove as newer versions of TS make them unnecessary.
  • Loading branch information
Arnavion committed Mar 10, 2016
1 parent 35310a5 commit 212f376
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
26 changes: 13 additions & 13 deletions src/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class ParserRun {

if (whiteSpaceOrTextNode.value instanceof parts.Text && current.value[current.value.length - 1] instanceof parts.Text) {
// Merge consecutive text parts into one part
const previousTextPart = <parts.Text>current.value[current.value.length - 1];
current.value[current.value.length - 1] = new parts.Text(previousTextPart.value + (<parts.Text>whiteSpaceOrTextNode.value).value);
const previousTextPart = current.value[current.value.length - 1] as parts.Text;
current.value[current.value.length - 1] = new parts.Text(previousTextPart.value + (whiteSpaceOrTextNode.value as parts.Text).value);
}
else {
current.value.push(whiteSpaceOrTextNode.value);
Expand All @@ -113,7 +113,7 @@ class ParserRun {
}

else if (part instanceof parts.Text && inDrawingMode) {
current.value[i] = new parts.DrawingInstructions(<parts.drawing.Instruction[]>parse(part.value, "drawingInstructions"));
current.value[i] = new parts.DrawingInstructions(parse(part.value, "drawingInstructions") as parts.drawing.Instruction[]);
}
});

Expand Down Expand Up @@ -211,8 +211,8 @@ class ParserRun {
// Merge consecutive comment parts into one part
current.value[current.value.length - 1] =
new parts.Comment(
(<parts.Comment>current.value[current.value.length - 1]).value +
(<parts.Comment>childNode.value).value
(current.value[current.value.length - 1] as parts.Comment).value +
(childNode.value as parts.Comment).value
);
}
else {
Expand Down Expand Up @@ -1323,8 +1323,8 @@ class ParserRun {
// Merge consecutive comment parts into one part
transformTags[transformTags.length - 1] =
new parts.Comment(
(<parts.Comment>transformTags[transformTags.length - 1]).value +
(<parts.Comment>childNode.value).value
(transformTags[transformTags.length - 1] as parts.Comment).value +
(childNode.value as parts.Comment).value
);
}
else {
Expand Down Expand Up @@ -1502,7 +1502,7 @@ class ParserRun {
break;
}

const newType = (<parts.Text>typePart.value).value;
const newType = (typePart.value as parts.Text).value;
switch (newType) {
case "m":
case "l":
Expand Down Expand Up @@ -1868,7 +1868,7 @@ class ParserRun {
commandsNode.value += next;
}

current.value = new parts.VectorClip((scaleNode !== null) ? scaleNode.value : 1, <parts.drawing.Instruction[]>parse(commandsNode.value, "drawingInstructions"), tagName === "clip");
current.value = new parts.VectorClip((scaleNode !== null) ? scaleNode.value : 1, parse(commandsNode.value, "drawingInstructions") as parts.drawing.Instruction[], tagName === "clip");
}

if (this.read(current, ")") === null) {
Expand All @@ -1894,8 +1894,8 @@ function makeTagParserFunction(
valueParser: (current: ParseNode) => ParseNode,
required: boolean
): void {
(<any>ParserRun.prototype)[`parse_tag_${ tagName }`] = function (parent: ParseNode): ParseNode {
const self = <ParserRun>this;
(ParserRun.prototype as any)[`parse_tag_${ tagName }`] = function (parent: ParseNode): ParseNode {
const self = this as ParserRun;
const current = new ParseNode(parent);

if (self.read(current, tagName) === null) {
Expand Down Expand Up @@ -1953,8 +1953,8 @@ makeTagParserFunction("4a", parts.ShadowAlpha, ParserRun.prototype.parse_alpha,
makeTagParserFunction("4c", parts.ShadowColor, ParserRun.prototype.parse_color, false);

for (const key of Object.keys(ParserRun.prototype)) {
if (key.indexOf("parse_") === 0 && typeof (<any>ParserRun.prototype)[key] === "function") {
rules.set(key.substr("parse_".length), (<any>ParserRun.prototype)[key]);
if (key.indexOf("parse_") === 0 && typeof (ParserRun.prototype as any)[key] === "function") {
rules.set(key.substr("parse_".length), (ParserRun.prototype as any)[key]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function getTtfNames(attachment: Attachment): Set<string> {
* @return {!function(new(): T)}
*/
function struct<T>(clazz: { new (): T; read(reader: DataReader): T; }): { new (): T; read(reader: DataReader): T; } {
const fields: StructMemberDefinition[] = (<any>clazz).__fields;
const fields: StructMemberDefinition[] = (clazz as any).__fields;

clazz.read = (reader: DataReader) => {
const result: any = new clazz();
Expand Down
4 changes: 2 additions & 2 deletions src/parts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ const addToString = function (ctor: Function, ctorName: string) {
ctor.prototype.toString = function () {
return (
ctorName + " { " +
propertyNames.map(name => `${ name }: ${ (<any>this)[name] }`).join(", ") +
propertyNames.map(name => `${ name }: ${ (this as any)[name] }`).join(", ") +
((propertyNames.length > 0) ? " " : "") +
"}"
);
Expand All @@ -1323,7 +1323,7 @@ for (const key of Object.keys(exports)) {
}

for (const key of Object.keys(drawing)) {
const value: any = (<any>drawing)[key];
const value: any = (drawing as any)[key];
if (value instanceof Function) {
addToString(value, `Drawing${ key }`);
registerClass(value);
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class RendererSettings {
static makeFontMapFromStyleElement(linkStyle: LinkStyle): Map<string, string> {
const fontMap = new Map<string, string>();

const styleSheet = <CSSStyleSheet>linkStyle.sheet;
const styleSheet = linkStyle.sheet as CSSStyleSheet;
for (let i = 0; i < styleSheet.cssRules.length; i++) {
const rule = styleSheet.cssRules[i];

Expand Down Expand Up @@ -156,7 +156,7 @@ export class RendererSettings {
enableSvg = RendererSettings._testSupportsSvg(),
fallbackFonts = 'Arial, Helvetica, sans-serif, "Segoe UI Symbol"',
useAttachedFonts = false,
} = <RendererSettings>object;
} = object as RendererSettings;

const result = new RendererSettings();
result.fontMap = fontMap;
Expand Down Expand Up @@ -196,7 +196,7 @@ export class RendererSettings {
catch (ex) {
if (debugMode) {
if (ex instanceof DOMException) {
const domException = <DOMException>ex;
const domException = ex as DOMException;
if (domException.code === DOMException.NO_MODIFICATION_ALLOWED_ERR) {
console.log("Setting SVGFEMorphologyElement.radiusX.baseVal threw NoModificationAllowedError. This browser doesn't support SVG DOM correctly.");
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderers/web/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export class WebRenderer extends NullRenderer implements EventSource<string> {
super(ass, clock, (() => {
if (!(_libjassSubsWrapper instanceof HTMLDivElement)) {
const temp = settings;
settings = <any>_libjassSubsWrapper;
_libjassSubsWrapper = <any>temp;
settings = _libjassSubsWrapper as any;
_libjassSubsWrapper = temp as any;
console.warn("WebRenderer's constructor now takes libjassSubsWrapper as the third parameter and settings as the fourth parameter. Please update the caller.");
}

Expand Down Expand Up @@ -904,7 +904,7 @@ export class WebRenderer extends NullRenderer implements EventSource<string> {
applyAnimationDelays(result);
const animatedDescendants = result.querySelectorAll('[style*="animation:"]');
for (let i = 0; i < animatedDescendants.length; i++) {
applyAnimationDelays(<HTMLElement>animatedDescendants[i]);
applyAnimationDelays(animatedDescendants[i] as HTMLElement);
}

const layer = dialogue.layer;
Expand Down Expand Up @@ -952,7 +952,7 @@ export class WebRenderer extends NullRenderer implements EventSource<string> {
// Workaround for IE
const dialogueAnimationStylesElement = result.getElementsByTagName("style")[0];
if (dialogueAnimationStylesElement !== undefined) {
const sheet = <CSSStyleSheet>dialogueAnimationStylesElement.sheet;
const sheet = dialogueAnimationStylesElement.sheet as CSSStyleSheet;
if (sheet.cssRules.length === 0) {
sheet.cssText = dialogueAnimationStylesElement.textContent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/ass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class ASS {
result._stylesFormatSpecifier = this._stylesFormatSpecifier;
result._dialoguesFormatSpecifier = this._dialoguesFormatSpecifier;

result._classTag = (<any>ASS.prototype)._classTag;
result._classTag = (ASS.prototype as any)._classTag;

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/dialogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class Dialogue {
* Parses this dialogue's parts from the raw parts string.
*/
private _parsePartsString(): void {
this._parts = <parts.Part[]>parse(this._rawPartsString, "dialogueParts");
this._parts = parse(this._rawPartsString, "dialogueParts") as parts.Part[];

this._alignment = this._style.alignment;

Expand Down
10 changes: 5 additions & 5 deletions src/types/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export class Style {

this._rotationZ = valueOrDefault(template, "angle", parseFloat, value => !isNaN(value), "0");

this._primaryColor = valueOrDefault(template, "primarycolour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00FFFFFF");
this._secondaryColor = valueOrDefault(template, "secondarycolour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00FFFF00");
this._outlineColor = valueOrDefault(template, "outlinecolour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");
this._shadowColor = valueOrDefault(template, "backcolour", str => <Color>parse(str, "colorWithAlpha"), null, "&H80000000");
this._primaryColor = valueOrDefault(template, "primarycolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00FFFFFF");
this._secondaryColor = valueOrDefault(template, "secondarycolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00FFFF00");
this._outlineColor = valueOrDefault(template, "outlinecolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00000000");
this._shadowColor = valueOrDefault(template, "backcolour", str => parse(str, "colorWithAlpha") as Color, null, "&H80000000");

this._outlineThickness = valueOrDefault(template, "outline", parseFloat, value => value >= 0, "2");
this._borderStyle = valueOrDefault(template, "borderstyle", parseInt, value => (<any>BorderStyle)[(<any>BorderStyle)[value]] === value, "1");
this._borderStyle = valueOrDefault(template, "borderstyle", parseInt, value => (BorderStyle as any)[(BorderStyle as any)[value]] === value, "1");

this._shadowDepth = valueOrDefault(template, "shadow", parseFloat, value => value >= 0, "3");

Expand Down
4 changes: 2 additions & 2 deletions src/utility/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class SimpleMap<K, V> {
return `'${ key }`;
}

if ((<any>key).id !== undefined) {
return `!${ (<any>key).id }`;
if ((key as any).id !== undefined) {
return `!${ (key as any).id }`;
}

return null;
Expand Down
10 changes: 5 additions & 5 deletions src/utility/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class SimplePromise<T> {
const resultCapability = new DeferredPromise<U>();

if (typeof onFulfilled !== "function") {
onFulfilled = (value: T) => <U><any>value;
onFulfilled = (value: T) => value as any as U;
}

if (typeof onRejected !== "function") {
Expand Down Expand Up @@ -278,24 +278,24 @@ class SimplePromise<T> {
}

if (resolution === null || (typeof resolution !== "object" && typeof resolution !== "function")) {
this._fulfill(<T>resolution);
this._fulfill(resolution as T);
return;
}

try {
var then = (<Thenable<T>>resolution).then;
var then = (resolution as Thenable<T>).then;
}
catch (ex) {
this._reject(ex);
return;
}

if (typeof then !== "function") {
this._fulfill(<T>resolution);
this._fulfill(resolution as T);
return;
}

enqueueJob(() => this._resolveWithThenable(<Thenable<T>>resolution, then));
enqueueJob(() => this._resolveWithThenable(resolution as Thenable<T>, then));
};

const reject = (reason: any): void => {
Expand Down
8 changes: 4 additions & 4 deletions src/webworker/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class WorkerChannelImpl implements WorkerChannel {
private _pendingRequests = new Map<number, DeferredPromise<any>>();

constructor(private _comm: WorkerCommunication) {
this._comm.addEventListener("message", ev => this._onMessage(<string>ev.data), false);
this._comm.addEventListener("message", ev => this._onMessage(ev.data as string), false);
}

/**
Expand Down Expand Up @@ -183,10 +183,10 @@ export class WorkerChannelImpl implements WorkerChannel {
* @param {string} rawMessage
*/
private _onMessage(rawMessage: string): void {
const message = <{ command: WorkerCommands }>deserialize(rawMessage);
const message = deserialize(rawMessage) as { command: WorkerCommands };

if (message.command === WorkerCommands.Response) {
const responseMessage = <WorkerResponseMessage><any>message;
const responseMessage = message as any as WorkerResponseMessage;

const deferred = this._pendingRequests.get(responseMessage.requestId);
if (deferred !== undefined) {
Expand All @@ -200,7 +200,7 @@ export class WorkerChannelImpl implements WorkerChannel {
}
}
else {
const requestMessage = <WorkerRequestMessage>message;
const requestMessage = message as WorkerRequestMessage;
const requestId = requestMessage.requestId;

const commandCallback = getWorkerCommandHandler(requestMessage.command);
Expand Down

0 comments on commit 212f376

Please sign in to comment.