mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(compiler): remove some unused output AST types (#44411)
This kind of output is no longer emitted into generated code, so the supporting output AST is removed. PR Close #44411
This commit is contained in:
parent
e0458a6d14
commit
f352c2bed9
5 changed files with 5 additions and 172 deletions
|
|
@ -108,17 +108,6 @@ export class ExpressionTranslatorVisitor<TStatement, TExpression> implements o.E
|
|||
stmt.leadingComments);
|
||||
}
|
||||
|
||||
visitTryCatchStmt(_stmt: o.TryCatchStmt, _context: Context): never {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
visitThrowStmt(stmt: o.ThrowStmt, context: Context): TStatement {
|
||||
return this.attachComments(
|
||||
this.factory.createThrowStatement(
|
||||
stmt.error.visitExpression(this, context.withExpressionMode)),
|
||||
stmt.leadingComments);
|
||||
}
|
||||
|
||||
visitReadVarExpr(ast: o.ReadVarExpr, _context: Context): TExpression {
|
||||
const identifier = this.factory.createIdentifier(ast.name!);
|
||||
this.setSourceMapRange(identifier, ast.sourceSpan);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export * from './ml_parser/tags';
|
|||
export {ParseTreeResult, TreeError} from './ml_parser/parser';
|
||||
export {LexerRange} from './ml_parser/lexer';
|
||||
export * from './ml_parser/xml_parser';
|
||||
export {ArrayType, AssertNotNull, DYNAMIC_TYPE, BinaryOperator, BinaryOperatorExpr, BuiltinType, BuiltinTypeName, BuiltinVar, CastExpr, ClassField, ClassMethod, ClassStmt, CommaExpr, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, Expression, ExpressionStatement, ExpressionType, ExpressionVisitor, ExternalExpr, ExternalReference, literalMap, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, MapType, NotExpr, NONE_TYPE, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, StatementVisitor, TaggedTemplateExpr, TemplateLiteral, TemplateLiteralElement, ThrowStmt, TryCatchStmt, Type, TypeVisitor, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, StmtModifier, Statement, STRING_TYPE, TypeofExpr, collectExternalReferences, jsDocComment, leadingComment, LeadingComment, JSDocComment, UnaryOperator, UnaryOperatorExpr, LocalizedString} from './output/output_ast';
|
||||
export {ArrayType, AssertNotNull, DYNAMIC_TYPE, BinaryOperator, BinaryOperatorExpr, BuiltinType, BuiltinTypeName, CastExpr, ClassField, ClassMethod, ClassStmt, CommaExpr, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, Expression, ExpressionStatement, ExpressionType, ExpressionVisitor, ExternalExpr, ExternalReference, literalMap, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, MapType, NotExpr, NONE_TYPE, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, StatementVisitor, TaggedTemplateExpr, TemplateLiteral, TemplateLiteralElement, Type, TypeVisitor, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, StmtModifier, Statement, STRING_TYPE, TypeofExpr, collectExternalReferences, jsDocComment, leadingComment, LeadingComment, JSDocComment, UnaryOperator, UnaryOperatorExpr, LocalizedString} from './output/output_ast';
|
||||
export {EmitterVisitorContext} from './output/abstract_emitter';
|
||||
export {JitEvaluator} from './output/output_jit';
|
||||
export * from './parse_util';
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ import {SourceMapGenerator} from './source_map';
|
|||
const _SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\r|\$/g;
|
||||
const _LEGAL_IDENTIFIER_RE = /^[$A-Z_][0-9A-Z_$]*$/i;
|
||||
const _INDENT_WITH = ' ';
|
||||
export const CATCH_ERROR_VAR = o.variable('error', null, null);
|
||||
export const CATCH_STACK_VAR = o.variable('stack', null, null);
|
||||
|
||||
class _EmittedLine {
|
||||
partsLength = 0;
|
||||
|
|
@ -259,16 +257,6 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
|||
return null;
|
||||
}
|
||||
|
||||
abstract visitTryCatchStmt(stmt: o.TryCatchStmt, ctx: EmitterVisitorContext): any;
|
||||
|
||||
visitThrowStmt(stmt: o.ThrowStmt, ctx: EmitterVisitorContext): any {
|
||||
this.printLeadingComments(stmt, ctx);
|
||||
ctx.print(stmt, `throw `);
|
||||
stmt.error.visitExpression(this, ctx);
|
||||
ctx.println(stmt, `;`);
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: EmitterVisitorContext): any;
|
||||
|
||||
visitWriteVarExpr(expr: o.WriteVarExpr, ctx: EmitterVisitorContext): any {
|
||||
|
|
@ -338,26 +326,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!;
|
||||
if (ast.builtin != null) {
|
||||
switch (ast.builtin) {
|
||||
case o.BuiltinVar.Super:
|
||||
varName = 'super';
|
||||
break;
|
||||
case o.BuiltinVar.This:
|
||||
varName = 'this';
|
||||
break;
|
||||
case o.BuiltinVar.CatchError:
|
||||
varName = CATCH_ERROR_VAR.name!;
|
||||
break;
|
||||
case o.BuiltinVar.CatchStack:
|
||||
varName = CATCH_STACK_VAR.name!;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown builtin variable ${ast.builtin}`);
|
||||
}
|
||||
}
|
||||
ctx.print(ast, varName);
|
||||
ctx.print(ast, ast.name);
|
||||
return null;
|
||||
}
|
||||
visitInstantiateExpr(ast: o.InstantiateExpr, ctx: EmitterVisitorContext): any {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
|
||||
import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitorContext, escapeIdentifier} from './abstract_emitter';
|
||||
import {AbstractEmitterVisitor, EmitterVisitorContext, escapeIdentifier} from './abstract_emitter';
|
||||
import * as o from './output_ast';
|
||||
|
||||
/**
|
||||
|
|
@ -91,17 +91,6 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
|||
throw new Error('Cannot emit a WrappedNodeExpr in Javascript.');
|
||||
}
|
||||
|
||||
override visitReadVarExpr(ast: o.ReadVarExpr, ctx: EmitterVisitorContext): string|null {
|
||||
if (ast.builtin === o.BuiltinVar.This) {
|
||||
ctx.print(ast, 'self');
|
||||
} else if (ast.builtin === o.BuiltinVar.Super) {
|
||||
throw new Error(
|
||||
`'super' needs to be handled at a parent ast node, not at the variable level!`);
|
||||
} else {
|
||||
super.visitReadVarExpr(ast, ctx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
override visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: EmitterVisitorContext): any {
|
||||
ctx.print(stmt, `var ${stmt.name}`);
|
||||
if (stmt.value) {
|
||||
|
|
@ -115,22 +104,6 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
|||
ast.value.visitExpression(this, ctx);
|
||||
return null;
|
||||
}
|
||||
override 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.print(expr, `.call(this`);
|
||||
if (expr.args.length > 0) {
|
||||
ctx.print(expr, `, `);
|
||||
this.visitAllExpressions(expr.args, ctx, ',');
|
||||
}
|
||||
ctx.print(expr, `)`);
|
||||
} else {
|
||||
super.visitInvokeFunctionExpr(expr, ctx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
override visitTaggedTemplateExpr(ast: o.TaggedTemplateExpr, ctx: EmitterVisitorContext): any {
|
||||
// The following convoluted piece of code is effectively the downlevelled equivalent of
|
||||
// ```
|
||||
|
|
@ -172,23 +145,6 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
|||
ctx.println(stmt, `}`);
|
||||
return null;
|
||||
}
|
||||
override visitTryCatchStmt(stmt: o.TryCatchStmt, ctx: EmitterVisitorContext): any {
|
||||
ctx.println(stmt, `try {`);
|
||||
ctx.incIndent();
|
||||
this.visitAllStatements(stmt.bodyStmts, ctx);
|
||||
ctx.decIndent();
|
||||
ctx.println(stmt, `} catch (${CATCH_ERROR_VAR.name}) {`);
|
||||
ctx.incIndent();
|
||||
const catchStmts =
|
||||
[<o.Statement>CATCH_STACK_VAR.set(CATCH_ERROR_VAR.prop('stack')).toDeclStmt(null, [
|
||||
o.StmtModifier.Final
|
||||
])].concat(stmt.catchStmts);
|
||||
this.visitAllStatements(catchStmts, ctx);
|
||||
ctx.decIndent();
|
||||
ctx.println(stmt, `}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
override visitLocalizedString(ast: o.LocalizedString, ctx: EmitterVisitorContext): any {
|
||||
// The following convoluted piece of code is effectively the downlevelled equivalent of
|
||||
// ```
|
||||
|
|
|
|||
|
|
@ -260,30 +260,13 @@ export abstract class Expression {
|
|||
}
|
||||
}
|
||||
|
||||
export enum BuiltinVar {
|
||||
This,
|
||||
Super,
|
||||
CatchError,
|
||||
CatchStack
|
||||
}
|
||||
|
||||
export class ReadVarExpr extends Expression {
|
||||
public name: string|null;
|
||||
public builtin: BuiltinVar|null;
|
||||
|
||||
constructor(name: string|BuiltinVar, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
||||
constructor(public name: string, type?: Type|null, sourceSpan?: ParseSourceSpan|null) {
|
||||
super(type, sourceSpan);
|
||||
if (typeof name === 'string') {
|
||||
this.name = name;
|
||||
this.builtin = null;
|
||||
} else {
|
||||
this.name = null;
|
||||
this.builtin = name;
|
||||
}
|
||||
}
|
||||
|
||||
override isEquivalent(e: Expression): boolean {
|
||||
return e instanceof ReadVarExpr && this.name === e.name && this.builtin === e.builtin;
|
||||
return e instanceof ReadVarExpr && this.name === e.name;
|
||||
}
|
||||
|
||||
override isConstant() {
|
||||
|
|
@ -295,9 +278,6 @@ export class ReadVarExpr extends Expression {
|
|||
}
|
||||
|
||||
set(value: Expression): WriteVarExpr {
|
||||
if (!this.name) {
|
||||
throw new Error(`Built in variable ${this.builtin} can not be assigned to.`);
|
||||
}
|
||||
return new WriteVarExpr(this.name, value, null, this.sourceSpan);
|
||||
}
|
||||
}
|
||||
|
|
@ -1007,10 +987,6 @@ export interface ExpressionVisitor {
|
|||
visitTypeofExpr(ast: TypeofExpr, context: any): any;
|
||||
}
|
||||
|
||||
export const THIS_EXPR = new ReadVarExpr(BuiltinVar.This, null, null);
|
||||
export const SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super, null, null);
|
||||
export const CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError, null, null);
|
||||
export const CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack, null, null);
|
||||
export const NULL_EXPR = new LiteralExpr(null, null, null);
|
||||
export const TYPED_NULL_EXPR = new LiteralExpr(null, INFERRED_TYPE, null);
|
||||
|
||||
|
|
@ -1205,36 +1181,6 @@ export class IfStmt extends Statement {
|
|||
}
|
||||
}
|
||||
|
||||
export class TryCatchStmt extends Statement {
|
||||
constructor(
|
||||
public bodyStmts: Statement[], public catchStmts: Statement[],
|
||||
sourceSpan: ParseSourceSpan|null = null, leadingComments?: LeadingComment[]) {
|
||||
super([], sourceSpan, leadingComments);
|
||||
}
|
||||
override isEquivalent(stmt: Statement): boolean {
|
||||
return stmt instanceof TryCatchStmt && areAllEquivalent(this.bodyStmts, stmt.bodyStmts) &&
|
||||
areAllEquivalent(this.catchStmts, stmt.catchStmts);
|
||||
}
|
||||
override visitStatement(visitor: StatementVisitor, context: any): any {
|
||||
return visitor.visitTryCatchStmt(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ThrowStmt extends Statement {
|
||||
constructor(
|
||||
public error: Expression, sourceSpan: ParseSourceSpan|null = null,
|
||||
leadingComments?: LeadingComment[]) {
|
||||
super([], sourceSpan, leadingComments);
|
||||
}
|
||||
override isEquivalent(stmt: ThrowStmt): boolean {
|
||||
return stmt instanceof TryCatchStmt && this.error.isEquivalent(stmt.error);
|
||||
}
|
||||
override visitStatement(visitor: StatementVisitor, context: any): any {
|
||||
return visitor.visitThrowStmt(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export interface StatementVisitor {
|
||||
visitDeclareVarStmt(stmt: DeclareVarStmt, context: any): any;
|
||||
visitDeclareFunctionStmt(stmt: DeclareFunctionStmt, context: any): any;
|
||||
|
|
@ -1242,8 +1188,6 @@ export interface StatementVisitor {
|
|||
visitReturnStmt(stmt: ReturnStatement, context: any): any;
|
||||
visitDeclareClassStmt(stmt: ClassStmt, context: any): any;
|
||||
visitIfStmt(stmt: IfStmt, context: any): any;
|
||||
visitTryCatchStmt(stmt: TryCatchStmt, context: any): any;
|
||||
visitThrowStmt(stmt: ThrowStmt, context: any): any;
|
||||
}
|
||||
|
||||
export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
||||
|
|
@ -1478,22 +1422,6 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
|||
context);
|
||||
}
|
||||
|
||||
visitTryCatchStmt(stmt: TryCatchStmt, context: any): any {
|
||||
return this.transformStmt(
|
||||
new TryCatchStmt(
|
||||
this.visitAllStatements(stmt.bodyStmts, context),
|
||||
this.visitAllStatements(stmt.catchStmts, context), stmt.sourceSpan,
|
||||
stmt.leadingComments),
|
||||
context);
|
||||
}
|
||||
|
||||
visitThrowStmt(stmt: ThrowStmt, context: any): any {
|
||||
return this.transformStmt(
|
||||
new ThrowStmt(
|
||||
stmt.error.visitExpression(this, context), stmt.sourceSpan, stmt.leadingComments),
|
||||
context);
|
||||
}
|
||||
|
||||
visitAllStatements(stmts: Statement[], context: any): Statement[] {
|
||||
return stmts.map(stmt => stmt.visitStatement(this, context));
|
||||
}
|
||||
|
|
@ -1672,15 +1600,6 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
|
|||
this.visitAllStatements(stmt.falseCase, context);
|
||||
return stmt;
|
||||
}
|
||||
visitTryCatchStmt(stmt: TryCatchStmt, context: any): any {
|
||||
this.visitAllStatements(stmt.bodyStmts, context);
|
||||
this.visitAllStatements(stmt.catchStmts, context);
|
||||
return stmt;
|
||||
}
|
||||
visitThrowStmt(stmt: ThrowStmt, context: any): any {
|
||||
stmt.error.visitExpression(this, context);
|
||||
return stmt;
|
||||
}
|
||||
visitAllStatements(stmts: Statement[], context: any): void {
|
||||
stmts.forEach(stmt => stmt.visitStatement(this, context));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue