style(compiler): reformat of codebase with new clang-format version (#36520)

This commit reformats the packages/compiler tree using the new version of
clang-format.

PR Close #36520
This commit is contained in:
Alex Rickabaugh
2020-04-08 10:14:18 -07:00
committed by atscott
parent 0a69a2832b
commit 83a9159063
193 changed files with 5904 additions and 4574 deletions

View File

@ -28,31 +28,39 @@ class _EmittedLine {
}
export class EmitterVisitorContext {
static createRoot(): EmitterVisitorContext { return new EmitterVisitorContext(0); }
static createRoot(): EmitterVisitorContext {
return new EmitterVisitorContext(0);
}
private _lines: _EmittedLine[];
private _classes: o.ClassStmt[] = [];
private _preambleLineCount = 0;
constructor(private _indent: number) { this._lines = [new _EmittedLine(_indent)]; }
constructor(private _indent: number) {
this._lines = [new _EmittedLine(_indent)];
}
/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get _currentLine(): _EmittedLine { return this._lines[this._lines.length - 1]; }
private get _currentLine(): _EmittedLine {
return this._lines[this._lines.length - 1];
}
println(from?: {sourceSpan: ParseSourceSpan | null}|null, lastPart: string = ''): void {
println(from?: {sourceSpan: ParseSourceSpan|null}|null, lastPart: string = ''): void {
this.print(from || null, lastPart, true);
}
lineIsEmpty(): boolean { return this._currentLine.parts.length === 0; }
lineIsEmpty(): boolean {
return this._currentLine.parts.length === 0;
}
lineLength(): number {
return this._currentLine.indent * _INDENT_WITH.length + this._currentLine.partsLength;
}
print(from: {sourceSpan: ParseSourceSpan | null}|null, part: string, newLine: boolean = false) {
print(from: {sourceSpan: ParseSourceSpan|null}|null, part: string, newLine: boolean = false) {
if (part.length > 0) {
this._currentLine.parts.push(part);
this._currentLine.partsLength += part.length;
@ -83,9 +91,13 @@ export class EmitterVisitorContext {
}
}
pushClass(clazz: o.ClassStmt) { this._classes.push(clazz); }
pushClass(clazz: o.ClassStmt) {
this._classes.push(clazz);
}
popClass(): o.ClassStmt { return this._classes.pop() !; }
popClass(): o.ClassStmt {
return this._classes.pop()!;
}
get currentClass(): o.ClassStmt|null {
return this._classes.length > 0 ? this._classes[this._classes.length - 1] : null;
@ -135,7 +147,7 @@ export class EmitterVisitorContext {
}
while (spanIdx < spans.length) {
const span = spans[spanIdx] !;
const span = spans[spanIdx]!;
const source = span.start.file;
const sourceLine = span.start.line;
const sourceCol = span.start.col;
@ -156,7 +168,9 @@ export class EmitterVisitorContext {
return map;
}
setPreambleLineCount(count: number) { return this._preambleLineCount = count; }
setPreambleLineCount(count: number) {
return this._preambleLineCount = count;
}
spanOf(line: number, column: number): ParseSourceSpan|null {
const emittedLine = this._lines[line - this._preambleLineCount];
@ -243,7 +257,9 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
if (stmt.multiline) {
ctx.println(stmt, `/* ${stmt.comment} */`);
} else {
stmt.comment.split('\n').forEach((line) => { ctx.println(stmt, `// ${line}`); });
stmt.comment.split('\n').forEach((line) => {
ctx.println(stmt, `// ${line}`);
});
}
return null;
}
@ -327,7 +343,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
expr.expr.visitExpression(this, ctx);
}
visitReadVarExpr(ast: o.ReadVarExpr, ctx: EmitterVisitorContext): any {
let varName = ast.name !;
let varName = ast.name!;
if (ast.builtin != null) {
switch (ast.builtin) {
case o.BuiltinVar.Super:
@ -337,10 +353,10 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
varName = 'this';
break;
case o.BuiltinVar.CatchError:
varName = CATCH_ERROR_VAR.name !;
varName = CATCH_ERROR_VAR.name!;
break;
case o.BuiltinVar.CatchStack:
varName = CATCH_STACK_VAR.name !;
varName = CATCH_STACK_VAR.name!;
break;
default:
throw new Error(`Unknown builtin variable ${ast.builtin}`);
@ -388,7 +404,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
ctx.print(ast, '? ');
ast.trueCase.visitExpression(this, ctx);
ctx.print(ast, ': ');
ast.falseCase !.visitExpression(this, ctx);
ast.falseCase!.visitExpression(this, ctx);
ctx.print(ast, `)`);
return null;
}

View File

@ -11,7 +11,9 @@ import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitor
import * as o from './output_ast';
export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
constructor() { super(false); }
constructor() {
super(false);
}
visitDeclareClassStmt(stmt: o.ClassStmt, ctx: EmitterVisitorContext): any {
ctx.pushClass(stmt);
this._visitClassConstructor(stmt, ctx);
@ -101,7 +103,7 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
visitInvokeFunctionExpr(expr: o.InvokeFunctionExpr, ctx: EmitterVisitorContext): string|null {
const fnExpr = expr.fn;
if (fnExpr instanceof o.ReadVarExpr && fnExpr.builtin === o.BuiltinVar.Super) {
ctx.currentClass !.parent !.visitExpression(this, ctx);
ctx.currentClass!.parent!.visitExpression(this, ctx);
ctx.print(expr, `.call(this`);
if (expr.args.length > 0) {
ctx.print(expr, `, `);

View File

@ -51,7 +51,7 @@ class JsEmitterVisitor extends AbstractJsEmitterVisitor {
}
ctx.print(ast, `${prefix}.`);
}
ctx.print(ast, name !);
ctx.print(ast, name!);
return null;
}
visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: EmitterVisitorContext): any {

View File

@ -24,7 +24,9 @@ export abstract class Type {
}
abstract visitType(visitor: TypeVisitor, context: any): any;
hasModifier(modifier: TypeModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
hasModifier(modifier: TypeModifier): boolean {
return this.modifiers!.indexOf(modifier) !== -1;
}
}
export enum BuiltinTypeName {
@ -60,7 +62,9 @@ export class ExpressionType extends Type {
export class ArrayType extends Type {
constructor(public of : Type, modifiers: TypeModifier[]|null = null) { super(modifiers); }
constructor(public of: Type, modifiers: TypeModifier[]|null = null) {
super(modifiers);
}
visitType(visitor: TypeVisitor, context: any): any {
return visitor.visitArrayType(this, context);
}
@ -73,7 +77,9 @@ export class MapType extends Type {
super(modifiers);
this.valueType = valueType || null;
}
visitType(visitor: TypeVisitor, context: any): any { return visitor.visitMapType(this, context); }
visitType(visitor: TypeVisitor, context: any): any {
return visitor.visitMapType(this, context);
}
}
export const DYNAMIC_TYPE = new BuiltinType(BuiltinTypeName.Dynamic);
@ -113,15 +119,15 @@ export enum BinaryOperator {
BiggerEquals
}
export function nullSafeIsEquivalent<T extends{isEquivalent(other: T): boolean}>(
base: T | null, other: T | null) {
export function nullSafeIsEquivalent<T extends {isEquivalent(other: T): boolean}>(
base: T|null, other: T|null) {
if (base == null || other == null) {
return base == other;
}
return base.isEquivalent(other);
}
export function areAllEquivalent<T extends{isEquivalent(other: T): boolean}>(
export function areAllEquivalent<T extends {isEquivalent(other: T): boolean}>(
base: T[], other: T[]) {
const len = base.length;
if (len !== other.length) {
@ -243,7 +249,9 @@ export abstract class Expression {
return new CastExpr(this, type, sourceSpan);
}
toStmt(): Statement { return new ExpressionStatement(this, null); }
toStmt(): Statement {
return new ExpressionStatement(this, null);
}
}
export enum BuiltinVar {
@ -272,7 +280,9 @@ export class ReadVarExpr extends Expression {
return e instanceof ReadVarExpr && this.name === e.name && this.builtin === e.builtin;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitReadVarExpr(this, context);
@ -299,7 +309,9 @@ export class TypeofExpr extends Expression {
return e instanceof TypeofExpr && e.expr.isEquivalent(this.expr);
}
isConstant(): boolean { return this.expr.isConstant(); }
isConstant(): boolean {
return this.expr.isConstant();
}
}
export class WrappedNodeExpr<T> extends Expression {
@ -311,7 +323,9 @@ export class WrappedNodeExpr<T> extends Expression {
return e instanceof WrappedNodeExpr && this.node === e.node;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitWrappedNodeExpr(this, context);
@ -330,7 +344,9 @@ export class WriteVarExpr extends Expression {
return e instanceof WriteVarExpr && this.name === e.name && this.value.isEquivalent(e.value);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitWriteVarExpr(this, context);
@ -340,7 +356,9 @@ export class WriteVarExpr extends Expression {
return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan);
}
toConstDecl(): DeclareVarStmt { return this.toDeclStmt(INFERRED_TYPE, [StmtModifier.Final]); }
toConstDecl(): DeclareVarStmt {
return this.toDeclStmt(INFERRED_TYPE, [StmtModifier.Final]);
}
}
@ -358,7 +376,9 @@ export class WriteKeyExpr extends Expression {
this.index.isEquivalent(e.index) && this.value.isEquivalent(e.value);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitWriteKeyExpr(this, context);
@ -380,7 +400,9 @@ export class WritePropExpr extends Expression {
this.name === e.name && this.value.isEquivalent(e.value);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitWritePropExpr(this, context);
@ -414,7 +436,9 @@ export class InvokeMethodExpr extends Expression {
this.name === e.name && this.builtin === e.builtin && areAllEquivalent(this.args, e.args);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitInvokeMethodExpr(this, context);
@ -434,7 +458,9 @@ export class InvokeFunctionExpr extends Expression {
areAllEquivalent(this.args, e.args) && this.pure === e.pure;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitInvokeFunctionExpr(this, context);
@ -454,7 +480,9 @@ export class InstantiateExpr extends Expression {
areAllEquivalent(this.args, e.args);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitInstantiateExpr(this, context);
@ -473,7 +501,9 @@ export class LiteralExpr extends Expression {
return e instanceof LiteralExpr && this.value === e.value;
}
isConstant() { return true; }
isConstant() {
return true;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitLiteralExpr(this, context);
@ -494,7 +524,9 @@ export class LocalizedString extends Expression {
return false;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitLocalizedString(this, context);
@ -521,8 +553,9 @@ export class LocalizedString extends Expression {
metaBlock = `${metaBlock}${ID_SEPARATOR}${this.metaBlock.customId}`;
}
if (this.metaBlock.legacyIds) {
this.metaBlock.legacyIds.forEach(
legacyId => { metaBlock = `${metaBlock}${LEGACY_ID_INDICATOR}${legacyId}`; });
this.metaBlock.legacyIds.forEach(legacyId => {
metaBlock = `${metaBlock}${LEGACY_ID_INDICATOR}${legacyId}`;
});
}
return createCookedRawString(metaBlock, this.messageParts[0]);
}
@ -588,7 +621,9 @@ export class ExternalExpr extends Expression {
this.value.moduleName === e.value.moduleName && this.value.runtime === e.value.runtime;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitExternalExpr(this, context);
@ -616,7 +651,9 @@ export class ConditionalExpr extends Expression {
this.trueCase.isEquivalent(e.trueCase) && nullSafeIsEquivalent(this.falseCase, e.falseCase);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitConditionalExpr(this, context);
@ -633,7 +670,9 @@ export class NotExpr extends Expression {
return e instanceof NotExpr && this.condition.isEquivalent(e.condition);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitNotExpr(this, context);
@ -649,7 +688,9 @@ export class AssertNotNull extends Expression {
return e instanceof AssertNotNull && this.condition.isEquivalent(e.condition);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitAssertNotNullExpr(this, context);
@ -665,7 +706,9 @@ export class CastExpr extends Expression {
return e instanceof CastExpr && this.value.isEquivalent(e.value);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitCastExpr(this, context);
@ -676,7 +719,9 @@ export class CastExpr extends Expression {
export class FnParam {
constructor(public name: string, public type: Type|null = null) {}
isEquivalent(param: FnParam): boolean { return this.name === param.name; }
isEquivalent(param: FnParam): boolean {
return this.name === param.name;
}
}
@ -692,7 +737,9 @@ export class FunctionExpr extends Expression {
areAllEquivalent(this.statements, e.statements);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitFunctionExpr(this, context);
@ -719,7 +766,9 @@ export class BinaryOperatorExpr extends Expression {
this.lhs.isEquivalent(e.lhs) && this.rhs.isEquivalent(e.rhs);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitBinaryOperatorExpr(this, context);
@ -739,7 +788,9 @@ export class ReadPropExpr extends Expression {
this.name === e.name;
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitReadPropExpr(this, context);
@ -763,7 +814,9 @@ export class ReadKeyExpr extends Expression {
this.index.isEquivalent(e.index);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitReadKeyExpr(this, context);
@ -782,7 +835,9 @@ export class LiteralArrayExpr extends Expression {
this.entries = entries;
}
isConstant() { return this.entries.every(e => e.isConstant()); }
isConstant() {
return this.entries.every(e => e.isConstant());
}
isEquivalent(e: Expression): boolean {
return e instanceof LiteralArrayExpr && areAllEquivalent(this.entries, e.entries);
@ -813,7 +868,9 @@ export class LiteralMapExpr extends Expression {
return e instanceof LiteralMapExpr && areAllEquivalent(this.entries, e.entries);
}
isConstant() { return this.entries.every(e => e.value.isConstant()); }
isConstant() {
return this.entries.every(e => e.value.isConstant());
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitLiteralMapExpr(this, context);
@ -829,7 +886,9 @@ export class CommaExpr extends Expression {
return e instanceof CommaExpr && areAllEquivalent(this.parts, e.parts);
}
isConstant() { return false; }
isConstant() {
return false;
}
visitExpression(visitor: ExpressionVisitor, context: any): any {
return visitor.visitCommaExpr(this, context);
@ -892,7 +951,9 @@ export abstract class Statement {
abstract visitStatement(visitor: StatementVisitor, context: any): any;
hasModifier(modifier: StmtModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
hasModifier(modifier: StmtModifier): boolean {
return this.modifiers!.indexOf(modifier) !== -1;
}
}
@ -965,7 +1026,9 @@ export class AbstractClassPart {
}
this.type = type || null;
}
hasModifier(modifier: StmtModifier): boolean { return this.modifiers !.indexOf(modifier) !== -1; }
hasModifier(modifier: StmtModifier): boolean {
return this.modifiers!.indexOf(modifier) !== -1;
}
}
export class ClassField extends AbstractClassPart {
@ -974,7 +1037,9 @@ export class ClassField extends AbstractClassPart {
public initializer?: Expression) {
super(type, modifiers);
}
isEquivalent(f: ClassField) { return this.name === f.name; }
isEquivalent(f: ClassField) {
return this.name === f.name;
}
}
@ -1044,7 +1109,9 @@ export class CommentStmt extends Statement {
constructor(public comment: string, public multiline = false, sourceSpan?: ParseSourceSpan|null) {
super(null, sourceSpan);
}
isEquivalent(stmt: Statement): boolean { return stmt instanceof CommentStmt; }
isEquivalent(stmt: Statement): boolean {
return stmt instanceof CommentStmt;
}
visitStatement(visitor: StatementVisitor, context: any): any {
return visitor.visitCommentStmt(this, context);
}
@ -1060,7 +1127,9 @@ export class JSDocCommentStmt extends Statement {
visitStatement(visitor: StatementVisitor, context: any): any {
return visitor.visitJSDocCommentStmt(this, context);
}
toString(): string { return serializeTags(this.tags); }
toString(): string {
return serializeTags(this.tags);
}
}
export class TryCatchStmt extends Statement {
@ -1105,11 +1174,17 @@ export interface StatementVisitor {
}
export class AstTransformer implements StatementVisitor, ExpressionVisitor {
transformExpr(expr: Expression, context: any): Expression { return expr; }
transformExpr(expr: Expression, context: any): Expression {
return expr;
}
transformStmt(stmt: Statement, context: any): Statement { return stmt; }
transformStmt(stmt: Statement, context: any): Statement {
return stmt;
}
visitReadVarExpr(ast: ReadVarExpr, context: any): any { return this.transformExpr(ast, context); }
visitReadVarExpr(ast: ReadVarExpr, context: any): any {
return this.transformExpr(ast, context);
}
visitWrappedNodeExpr(ast: WrappedNodeExpr<any>, context: any): any {
return this.transformExpr(ast, context);
@ -1148,7 +1223,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
const method = ast.builtin || ast.name;
return this.transformExpr(
new InvokeMethodExpr(
ast.receiver.visitExpression(this, context), method !,
ast.receiver.visitExpression(this, context), method!,
this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan),
context);
}
@ -1169,7 +1244,9 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
context);
}
visitLiteralExpr(ast: LiteralExpr, context: any): any { return this.transformExpr(ast, context); }
visitLiteralExpr(ast: LiteralExpr, context: any): any {
return this.transformExpr(ast, context);
}
visitLocalizedString(ast: LocalizedString, context: any): any {
return this.transformExpr(
@ -1188,7 +1265,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
new ConditionalExpr(
ast.condition.visitExpression(this, context),
ast.trueCase.visitExpression(this, context),
ast.falseCase !.visitExpression(this, context), ast.type, ast.sourceSpan),
ast.falseCase!.visitExpression(this, context), ast.type, ast.sourceSpan),
context);
}
@ -1284,7 +1361,7 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
}
visitDeclareClassStmt(stmt: ClassStmt, context: any): any {
const parent = stmt.parent !.visitExpression(this, context);
const parent = stmt.parent!.visitExpression(this, context);
const getters = stmt.getters.map(
getter => new ClassGetter(
getter.name, this.visitAllStatements(getter.body, context), getter.type,
@ -1341,14 +1418,18 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor {
visitType(ast: Type, context: any): any { return ast; }
visitType(ast: Type, context: any): any {
return ast;
}
visitExpression(ast: Expression, context: any): any {
if (ast.type) {
ast.type.visitType(this, context);
}
return ast;
}
visitBuiltinType(type: BuiltinType, context: any): any { return this.visitType(type, context); }
visitBuiltinType(type: BuiltinType, context: any): any {
return this.visitType(type, context);
}
visitExpressionType(type: ExpressionType, context: any): any {
type.value.visitExpression(this, context);
if (type.typeParams !== null) {
@ -1356,10 +1437,18 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
}
return this.visitType(type, context);
}
visitArrayType(type: ArrayType, context: any): any { return this.visitType(type, context); }
visitMapType(type: MapType, context: any): any { return this.visitType(type, context); }
visitWrappedNodeExpr(ast: WrappedNodeExpr<any>, context: any): any { return ast; }
visitTypeofExpr(ast: TypeofExpr, context: any): any { return this.visitExpression(ast, context); }
visitArrayType(type: ArrayType, context: any): any {
return this.visitType(type, context);
}
visitMapType(type: MapType, context: any): any {
return this.visitType(type, context);
}
visitWrappedNodeExpr(ast: WrappedNodeExpr<any>, context: any): any {
return ast;
}
visitTypeofExpr(ast: TypeofExpr, context: any): any {
return this.visitExpression(ast, context);
}
visitReadVarExpr(ast: ReadVarExpr, context: any): any {
return this.visitExpression(ast, context);
}
@ -1408,7 +1497,7 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
visitConditionalExpr(ast: ConditionalExpr, context: any): any {
ast.condition.visitExpression(this, context);
ast.trueCase.visitExpression(this, context);
ast.falseCase !.visitExpression(this, context);
ast.falseCase!.visitExpression(this, context);
return this.visitExpression(ast, context);
}
visitNotExpr(ast: NotExpr, context: any): any {
@ -1482,7 +1571,7 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
return stmt;
}
visitDeclareClassStmt(stmt: ClassStmt, context: any): any {
stmt.parent !.visitExpression(this, context);
stmt.parent!.visitExpression(this, context);
stmt.getters.forEach(getter => this.visitAllStatements(getter.body, context));
if (stmt.constructorMethod) {
this.visitAllStatements(stmt.constructorMethod.body, context);
@ -1505,8 +1594,12 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
stmt.error.visitExpression(this, context);
return stmt;
}
visitCommentStmt(stmt: CommentStmt, context: any): any { return stmt; }
visitJSDocCommentStmt(stmt: JSDocCommentStmt, context: any): any { return stmt; }
visitCommentStmt(stmt: CommentStmt, context: any): any {
return stmt;
}
visitJSDocCommentStmt(stmt: JSDocCommentStmt, context: any): any {
return stmt;
}
visitAllStatements(stmts: Statement[], context: any): void {
stmts.forEach(stmt => stmt.visitStatement(this, context));
}
@ -1551,7 +1644,7 @@ class _FindExternalReferencesVisitor extends RecursiveAstVisitor {
}
export function applySourceSpanToStatementIfNeeded(
stmt: Statement, sourceSpan: ParseSourceSpan | null): Statement {
stmt: Statement, sourceSpan: ParseSourceSpan|null): Statement {
if (!sourceSpan) {
return stmt;
}
@ -1560,7 +1653,7 @@ export function applySourceSpanToStatementIfNeeded(
}
export function applySourceSpanToExpressionIfNeeded(
expr: Expression, sourceSpan: ParseSourceSpan | null): Expression {
expr: Expression, sourceSpan: ParseSourceSpan|null): Expression {
if (!sourceSpan) {
return expr;
}
@ -1569,7 +1662,9 @@ export function applySourceSpanToExpressionIfNeeded(
}
class _ApplySourceSpanTransformer extends AstTransformer {
constructor(private sourceSpan: ParseSourceSpan) { super(); }
constructor(private sourceSpan: ParseSourceSpan) {
super();
}
private _clone(obj: any): any {
const clone = Object.create(obj.constructor.prototype);
for (let prop of Object.keys(obj)) {
@ -1596,25 +1691,25 @@ class _ApplySourceSpanTransformer extends AstTransformer {
}
export function variable(
name: string, type?: Type | null, sourceSpan?: ParseSourceSpan | null): ReadVarExpr {
name: string, type?: Type|null, sourceSpan?: ParseSourceSpan|null): ReadVarExpr {
return new ReadVarExpr(name, type, sourceSpan);
}
export function importExpr(
id: ExternalReference, typeParams: Type[] | null = null,
sourceSpan?: ParseSourceSpan | null): ExternalExpr {
id: ExternalReference, typeParams: Type[]|null = null,
sourceSpan?: ParseSourceSpan|null): ExternalExpr {
return new ExternalExpr(id, null, typeParams, sourceSpan);
}
export function importType(
id: ExternalReference, typeParams: Type[] | null = null,
typeModifiers: TypeModifier[] | null = null): ExpressionType|null {
id: ExternalReference, typeParams: Type[]|null = null,
typeModifiers: TypeModifier[]|null = null): ExpressionType|null {
return id != null ? expressionType(importExpr(id, typeParams, null), typeModifiers) : null;
}
export function expressionType(
expr: Expression, typeModifiers: TypeModifier[] | null = null,
typeParams: Type[] | null = null): ExpressionType {
expr: Expression, typeModifiers: TypeModifier[]|null = null,
typeParams: Type[]|null = null): ExpressionType {
return new ExpressionType(expr, typeModifiers, typeParams);
}
@ -1623,30 +1718,28 @@ export function typeofExpr(expr: Expression) {
}
export function literalArr(
values: Expression[], type?: Type | null,
sourceSpan?: ParseSourceSpan | null): LiteralArrayExpr {
values: Expression[], type?: Type|null, sourceSpan?: ParseSourceSpan|null): LiteralArrayExpr {
return new LiteralArrayExpr(values, type, sourceSpan);
}
export function literalMap(
values: {key: string, quoted: boolean, value: Expression}[],
type: MapType | null = null): LiteralMapExpr {
type: MapType|null = null): LiteralMapExpr {
return new LiteralMapExpr(
values.map(e => new LiteralMapEntry(e.key, e.value, e.quoted)), type, null);
}
export function not(expr: Expression, sourceSpan?: ParseSourceSpan | null): NotExpr {
export function not(expr: Expression, sourceSpan?: ParseSourceSpan|null): NotExpr {
return new NotExpr(expr, sourceSpan);
}
export function assertNotNull(
expr: Expression, sourceSpan?: ParseSourceSpan | null): AssertNotNull {
export function assertNotNull(expr: Expression, sourceSpan?: ParseSourceSpan|null): AssertNotNull {
return new AssertNotNull(expr, sourceSpan);
}
export function fn(
params: FnParam[], body: Statement[], type?: Type | null, sourceSpan?: ParseSourceSpan | null,
name?: string | null): FunctionExpr {
params: FnParam[], body: Statement[], type?: Type|null, sourceSpan?: ParseSourceSpan|null,
name?: string|null): FunctionExpr {
return new FunctionExpr(params, body, type, sourceSpan, name);
}
@ -1655,13 +1748,13 @@ export function ifStmt(condition: Expression, thenClause: Statement[], elseClaus
}
export function literal(
value: any, type?: Type | null, sourceSpan?: ParseSourceSpan | null): LiteralExpr {
value: any, type?: Type|null, sourceSpan?: ParseSourceSpan|null): LiteralExpr {
return new LiteralExpr(value, type, sourceSpan);
}
export function localizedString(
metaBlock: I18nMeta, messageParts: string[], placeholderNames: string[],
expressions: Expression[], sourceSpan?: ParseSourceSpan | null): LocalizedString {
expressions: Expression[], sourceSpan?: ParseSourceSpan|null): LocalizedString {
return new LocalizedString(metaBlock, messageParts, placeholderNames, expressions, sourceSpan);
}
@ -1684,13 +1777,12 @@ export const enum JSDocTagName {
*/
export type JSDocTag = {
// `tagName` is e.g. "param" in an `@param` declaration
tagName: JSDocTagName | string,
tagName: JSDocTagName|string,
// Any remaining text on the tag, e.g. the description
text?: string,
} | {
}|{
// no `tagName` for plain text documentation that occurs before any `@param` lines
tagName?: undefined,
text: string,
tagName?: undefined, text: string,
};
/*

View File

@ -15,7 +15,9 @@ export function interpretStatements(
const visitor = new StatementInterpreter(reflector);
visitor.visitAllStatements(statements, ctx);
const result: {[key: string]: any} = {};
ctx.exports.forEach((exportName) => { result[exportName] = ctx.vars.get(exportName); });
ctx.exports.forEach((exportName) => {
result[exportName] = ctx.vars.get(exportName);
});
return result;
}
@ -63,7 +65,7 @@ function createDynamicClass(
_classStmt.methods.forEach(function(method: o.ClassMethod) {
const paramNames = method.params.map(param => param.name);
// Note: use `function` instead of arrow function to capture `this`
propertyDescriptors[method.name !] = {
propertyDescriptors[method.name!] = {
writable: false,
configurable: false,
value: function(...args: any[]) {
@ -77,7 +79,9 @@ function createDynamicClass(
// Note: use `function` instead of arrow function to capture `this`
const ctor = function(this: Object, ...args: any[]) {
const instanceCtx = new _ExecutionContext(_ctx, this, _classStmt.name, _ctx.vars);
_classStmt.fields.forEach((field) => { (this as any)[field.name] = undefined; });
_classStmt.fields.forEach((field) => {
(this as any)[field.name] = undefined;
});
_executeFunctionStatements(
ctorParamNames, args, _classStmt.constructorMethod.body, instanceCtx, _visitor);
};
@ -88,7 +92,9 @@ function createDynamicClass(
class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
constructor(private reflector: CompileReflector) {}
debugAst(ast: o.Expression|o.Statement|o.Type): string { return debugOutputAstAsTypeScript(ast); }
debugAst(ast: o.Expression|o.Statement|o.Type): string {
return debugOutputAstAsTypeScript(ast);
}
visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: _ExecutionContext): any {
const initialValue = stmt.value ? stmt.value.visitExpression(this, ctx) : undefined;
@ -106,7 +112,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
currCtx.vars.set(expr.name, value);
return value;
}
currCtx = currCtx.parent !;
currCtx = currCtx.parent!;
}
throw new Error(`Not declared variable ${expr.name}`);
}
@ -117,7 +123,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
throw new Error('Cannot interpret a TypeofExpr');
}
visitReadVarExpr(ast: o.ReadVarExpr, ctx: _ExecutionContext): any {
let varName = ast.name !;
let varName = ast.name!;
if (ast.builtin != null) {
switch (ast.builtin) {
case o.BuiltinVar.Super:
@ -139,7 +145,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
if (currCtx.vars.has(varName)) {
return currCtx.vars.get(varName);
}
currCtx = currCtx.parent !;
currCtx = currCtx.parent!;
}
throw new Error(`Not declared variable ${varName}`);
}
@ -176,7 +182,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
throw new Error(`Unknown builtin method ${expr.builtin}`);
}
} else {
result = receiver[expr.name !].apply(receiver, args);
result = receiver[expr.name!].apply(receiver, args);
}
return result;
}
@ -184,7 +190,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
const args = this.visitAllExpressions(stmt.args, ctx);
const fnExpr = stmt.fn;
if (fnExpr instanceof o.ReadVarExpr && fnExpr.builtin === o.BuiltinVar.Super) {
ctx.instance !.constructor.prototype.constructor.apply(ctx.instance, args);
ctx.instance!.constructor.prototype.constructor.apply(ctx.instance, args);
return null;
} else {
const fn = stmt.fn.visitExpression(this, ctx);
@ -227,15 +233,23 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
visitThrowStmt(stmt: o.ThrowStmt, ctx: _ExecutionContext): any {
throw stmt.error.visitExpression(this, ctx);
}
visitCommentStmt(stmt: o.CommentStmt, context?: any): any { return null; }
visitJSDocCommentStmt(stmt: o.JSDocCommentStmt, context?: any): any { return null; }
visitCommentStmt(stmt: o.CommentStmt, context?: any): any {
return null;
}
visitJSDocCommentStmt(stmt: o.JSDocCommentStmt, context?: any): any {
return null;
}
visitInstantiateExpr(ast: o.InstantiateExpr, ctx: _ExecutionContext): any {
const args = this.visitAllExpressions(ast.args, ctx);
const clazz = ast.classExpr.visitExpression(this, ctx);
return new clazz(...args);
}
visitLiteralExpr(ast: o.LiteralExpr, ctx: _ExecutionContext): any { return ast.value; }
visitLocalizedString(ast: o.LocalizedString, context: any): any { return null; }
visitLiteralExpr(ast: o.LiteralExpr, ctx: _ExecutionContext): any {
return ast.value;
}
visitLocalizedString(ast: o.LocalizedString, context: any): any {
return null;
}
visitExternalExpr(ast: o.ExternalExpr, ctx: _ExecutionContext): any {
return this.reflector.resolveExternalReference(ast.value);
}

View File

@ -87,7 +87,9 @@ export class JitEvaluator {
* @param args The arguments to pass to the function being executed.
* @returns The return value of the executed function.
*/
executeFunction(fn: Function, args: any[]) { return fn(...args); }
executeFunction(fn: Function, args: any[]) {
return fn(...args);
}
}
/**
@ -98,7 +100,9 @@ export class JitEmitterVisitor extends AbstractJsEmitterVisitor {
private _evalArgValues: any[] = [];
private _evalExportedVars: string[] = [];
constructor(private reflector: CompileReflector) { super(); }
constructor(private reflector: CompileReflector) {
super();
}
createReturnStmt(ctx: EmitterVisitorContext) {
const stmt = new o.ReturnStatement(new o.LiteralMapExpr(this._evalExportedVars.map(

View File

@ -23,10 +23,10 @@ type Segment = {
export type SourceMap = {
version: number,
file?: string,
sourceRoot: string,
sources: string[],
sourcesContent: (string | null)[],
mappings: string,
sourceRoot: string,
sources: string[],
sourcesContent: (string|null)[],
mappings: string,
};
export class SourceMapGenerator {
@ -75,10 +75,12 @@ export class SourceMapGenerator {
}
/**
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get currentLine(): Segment[]|null { return this.lines.slice(-1)[0]; }
* @internal strip this from published d.ts files due to
* https://github.com/microsoft/TypeScript/issues/36216
*/
private get currentLine(): Segment[]|null {
return this.lines.slice(-1)[0];
}
toJSON(): SourceMap|null {
if (!this.hasMappings) {
@ -87,7 +89,7 @@ export class SourceMapGenerator {
const sourcesIndex = new Map<string, number>();
const sources: string[] = [];
const sourcesContent: (string | null)[] = [];
const sourcesContent: (string|null)[] = [];
Array.from(this.sourcesContent.keys()).forEach((url: string, i: number) => {
sourcesIndex.set(url, i);
@ -113,14 +115,14 @@ export class SourceMapGenerator {
if (segment.sourceUrl != null) {
// zero-based index into the “sources” list
segAsStr +=
toBase64VLQ(sourcesIndex.get(segment.sourceUrl) ! - lastSourceIndex);
lastSourceIndex = sourcesIndex.get(segment.sourceUrl) !;
toBase64VLQ(sourcesIndex.get(segment.sourceUrl)! - lastSourceIndex);
lastSourceIndex = sourcesIndex.get(segment.sourceUrl)!;
// the zero-based starting line in the original source
segAsStr += toBase64VLQ(segment.sourceLine0 ! - lastSourceLine0);
lastSourceLine0 = segment.sourceLine0 !;
segAsStr += toBase64VLQ(segment.sourceLine0! - lastSourceLine0);
lastSourceLine0 = segment.sourceLine0!;
// the zero-based starting column in the original source
segAsStr += toBase64VLQ(segment.sourceCol0 ! - lastSourceCol0);
lastSourceCol0 = segment.sourceCol0 !;
segAsStr += toBase64VLQ(segment.sourceCol0! - lastSourceCol0);
lastSourceCol0 = segment.sourceCol0!;
}
return segAsStr;

View File

@ -15,8 +15,7 @@ import * as o from './output_ast';
const _debugFilePath = '/debug/lib';
export function debugOutputAstAsTypeScript(ast: o.Statement | o.Expression | o.Type | any[]):
string {
export function debugOutputAstAsTypeScript(ast: o.Statement|o.Expression|o.Type|any[]): string {
const converter = new _TsEmitterVisitor();
const ctx = EmitterVisitorContext.createRoot();
const asts: any[] = Array.isArray(ast) ? ast : [ast];
@ -147,7 +146,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
reexports = [];
this.reexports.set(moduleName, reexports);
}
reexports.push({name: name !, as: stmt.name});
reexports.push({name: name!, as: stmt.name});
return null;
}
}
@ -175,7 +174,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
visitCastExpr(ast: o.CastExpr, ctx: EmitterVisitorContext): any {
ctx.print(ast, `(<`);
ast.type !.visitType(this, ctx);
ast.type!.visitType(this, ctx);
ctx.print(ast, `>`);
ast.value.visitExpression(this, ctx);
ctx.print(ast, `)`);
@ -422,7 +421,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
}
ctx.print(null, `${prefix}.`);
}
ctx.print(null, name !);
ctx.print(null, name!);
if (this.typeExpression > 0) {
// If we are in a type expression that refers to a generic type then supply
@ -433,7 +432,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
const suppliedParameters = typeParams || [];
if (suppliedParameters.length > 0) {
ctx.print(null, `<`);
this.visitAllObjects(type => type.visitType(this, ctx), typeParams !, ctx, ',');
this.visitAllObjects(type => type.visitType(this, ctx), typeParams!, ctx, ',');
ctx.print(null, `>`);
}
}

View File

@ -14,7 +14,7 @@ import * as o from './output_ast';
export const QUOTED_KEYS = '$quoted$';
export function convertValueToOutputAst(
ctx: OutputContext, value: any, type: o.Type | null = null): o.Expression {
ctx: OutputContext, value: any, type: o.Type|null = null): o.Expression {
return visitValue(value, new _ValueOutputAstTransformer(ctx), type);
}
@ -43,7 +43,9 @@ class _ValueOutputAstTransformer implements ValueTransformer {
return new o.LiteralMapExpr(entries, type);
}
visitPrimitive(value: any, type: o.Type): o.Expression { return o.literal(value, type); }
visitPrimitive(value: any, type: o.Type): o.Expression {
return o.literal(value, type);
}
visitOther(value: any, type: o.Type): o.Expression {
if (value instanceof o.Expression) {