feat(ivy): support generating view and content queries (#22330)
PR Close #22330
This commit is contained in:

committed by
Alex Eagle

parent
49f074f61d
commit
0451fd93df
@ -82,8 +82,11 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
||||
return null;
|
||||
}
|
||||
visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: EmitterVisitorContext): any {
|
||||
ctx.print(stmt, `var ${stmt.name} = `);
|
||||
stmt.value.visitExpression(this, ctx);
|
||||
ctx.print(stmt, `var ${stmt.name}`);
|
||||
if (stmt.value) {
|
||||
ctx.print(stmt, ' = ');
|
||||
stmt.value.visitExpression(this, ctx);
|
||||
}
|
||||
ctx.println(stmt, `;`);
|
||||
return null;
|
||||
}
|
||||
|
@ -756,14 +756,14 @@ export abstract class Statement {
|
||||
export class DeclareVarStmt extends Statement {
|
||||
public type: Type|null;
|
||||
constructor(
|
||||
public name: string, public value: Expression, type?: Type|null,
|
||||
public name: string, public value?: Expression, type?: Type|null,
|
||||
modifiers: StmtModifier[]|null = null, sourceSpan?: ParseSourceSpan|null) {
|
||||
super(modifiers, sourceSpan);
|
||||
this.type = type || value.type;
|
||||
this.type = type || (value && value.type) || null;
|
||||
}
|
||||
isEquivalent(stmt: Statement): boolean {
|
||||
return stmt instanceof DeclareVarStmt && this.name === stmt.name &&
|
||||
this.value.isEquivalent(stmt.value);
|
||||
(this.value ? !!stmt.value && this.value.isEquivalent(stmt.value) : !stmt.value);
|
||||
}
|
||||
visitStatement(visitor: StatementVisitor, context: any): any {
|
||||
return visitor.visitDeclareVarStmt(this, context);
|
||||
@ -1087,11 +1087,9 @@ export class AstTransformer implements StatementVisitor, ExpressionVisitor {
|
||||
}
|
||||
|
||||
visitDeclareVarStmt(stmt: DeclareVarStmt, context: any): any {
|
||||
const value = stmt.value && stmt.value.visitExpression(this, context);
|
||||
return this.transformStmt(
|
||||
new DeclareVarStmt(
|
||||
stmt.name, stmt.value.visitExpression(this, context), stmt.type, stmt.modifiers,
|
||||
stmt.sourceSpan),
|
||||
context);
|
||||
new DeclareVarStmt(stmt.name, value, stmt.type, stmt.modifiers, stmt.sourceSpan), context);
|
||||
}
|
||||
visitDeclareFunctionStmt(stmt: DeclareFunctionStmt, context: any): any {
|
||||
return this.transformStmt(
|
||||
@ -1275,7 +1273,9 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
|
||||
}
|
||||
|
||||
visitDeclareVarStmt(stmt: DeclareVarStmt, context: any): any {
|
||||
stmt.value.visitExpression(this, context);
|
||||
if (stmt.value) {
|
||||
stmt.value.visitExpression(this, context);
|
||||
}
|
||||
if (stmt.type) {
|
||||
stmt.type.visitType(this, context);
|
||||
}
|
||||
|
@ -95,7 +95,8 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
|
||||
debugAst(ast: o.Expression|o.Statement|o.Type): string { return debugOutputAstAsTypeScript(ast); }
|
||||
|
||||
visitDeclareVarStmt(stmt: o.DeclareVarStmt, ctx: _ExecutionContext): any {
|
||||
ctx.vars.set(stmt.name, stmt.value.visitExpression(this, ctx));
|
||||
const initialValue = stmt.value ? stmt.value.visitExpression(this, ctx) : undefined;
|
||||
ctx.vars.set(stmt.name, initialValue);
|
||||
if (stmt.hasModifier(o.StmtModifier.Exported)) {
|
||||
ctx.exports.push(stmt.name);
|
||||
}
|
||||
|
@ -161,8 +161,10 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
}
|
||||
ctx.print(stmt, ` ${stmt.name}`);
|
||||
this._printColonType(stmt.type, ctx);
|
||||
ctx.print(stmt, ` = `);
|
||||
stmt.value.visitExpression(this, ctx);
|
||||
if (stmt.value) {
|
||||
ctx.print(stmt, ` = `);
|
||||
stmt.value.visitExpression(this, ctx);
|
||||
}
|
||||
ctx.println(stmt, `;`);
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user