Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function compileComponentFromRender2(outputCtx, component, render3Ast, reflector, bindingParser, directiveTypeBySel, pipeTypeByName) {
var name = compile_metadata_1.identifierName(component.type);
name || util_1.error("Cannot resolver the name of " + component.type);
var definitionField = outputCtx.constantPool.propertyNameOf(2 /* Component */);
var summary = component.toSummary();
// Compute the R3ComponentMetadata from the CompileDirectiveMetadata
var meta = tslib_1.__assign({}, directiveMetadataFromGlobalMetadata(component, outputCtx, reflector), { selector: component.selector, template: { nodes: render3Ast.nodes }, directives: [], pipes: typeMapToExpressionMap(pipeTypeByName, outputCtx), viewQueries: queriesFromGlobalMetadata(component.viewQueries, outputCtx), wrapDirectivesAndPipesInClosure: false, styles: (summary.template && summary.template.styles) || EMPTY_ARRAY, encapsulation: (summary.template && summary.template.encapsulation) || core.ViewEncapsulation.Emulated, interpolation: interpolation_config_1.DEFAULT_INTERPOLATION_CONFIG, animations: null, viewProviders: component.viewProviders.length > 0 ? new o.WrappedNodeExpr(component.viewProviders) : null, relativeContextFilePath: '', i18nUseExternalIds: true });
var res = compileComponentFromMetadata(meta, outputCtx.constantPool, bindingParser);
// Create the partial class to be merged with the actual class.
outputCtx.statements.push(new o.ClassStmt(name, null, [new o.ClassField(definitionField, o.INFERRED_TYPE, [o.StmtModifier.Static], res.expression)], [], new o.ClassMethod(null, [], []), []));
}
exports.compileComponentFromRender2 = compileComponentFromRender2;
// The type to instantiate via constructor invocation. If there is no delegated factory, meaning
// this type is always created by constructor invocation, then this is the type-to-create
// parameter provided by the user (t) if specified, or the current type if not. If there is a
// delegated factory (which is used to create the current type) then this is only the type-to-
// create parameter (t).
var typeForCtor = !isDelegatedMetadata(meta) ? new o.BinaryOperatorExpr(o.BinaryOperator.Or, t, meta.type) : t;
var ctorExpr = null;
if (meta.deps !== null) {
// There is a constructor (either explicitly or implicitly defined).
ctorExpr = new o.InstantiateExpr(typeForCtor, injectDependencies(meta.deps, meta.injectFn));
}
else {
var baseFactory = o.variable("\u0275" + meta.name + "_BaseFactory");
var getInheritedFactory = o.importExpr(r3_identifiers_1.Identifiers.getInheritedFactory);
var baseFactoryStmt = baseFactory.set(getInheritedFactory.callFn([meta.type])).toDeclStmt(o.INFERRED_TYPE, [
o.StmtModifier.Exported, o.StmtModifier.Final
]);
statements.push(baseFactoryStmt);
// There is no constructor, use the base class' factory to construct typeForCtor.
ctorExpr = baseFactory.callFn([typeForCtor]);
}
var ctorExprFinal = ctorExpr;
var body = [];
var retExpr = null;
function makeConditionalFactory(nonCtorExpr) {
var r = o.variable('r');
body.push(r.set(o.NULL_EXPR).toDeclStmt());
body.push(o.ifStmt(t, [r.set(ctorExprFinal).toStmt()], [r.set(nonCtorExpr).toStmt()]));
return r;
}
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
var delegateFactory = o.variable("\u0275" + meta.name + "_BaseFactory");
// check for a reexport
var _a = stmt.value.value, name_1 = _a.name, moduleName = _a.moduleName;
if (moduleName) {
var reexports = this.reexports.get(moduleName);
if (!reexports) {
reexports = [];
this.reexports.set(moduleName, reexports);
}
reexports.push({ name: name_1, as: stmt.name });
return null;
}
}
if (stmt.hasModifier(o.StmtModifier.Exported)) {
ctx.print(stmt, "export ");
}
if (stmt.hasModifier(o.StmtModifier.Final)) {
ctx.print(stmt, "const");
}
else {
ctx.print(stmt, "var");
}
ctx.print(stmt, " " + stmt.name);
this._printColonType(stmt.type, ctx);
if (stmt.value) {
ctx.print(stmt, " = ");
stmt.value.visitExpression(this, ctx);
}
ctx.println(stmt, ";");
return null;
};
_TsEmitterVisitor.prototype.visitWrappedNodeExpr = function (ast, ctx) {
var body = [];
var retExpr = null;
function makeConditionalFactory(nonCtorExpr) {
var r = o.variable('r');
body.push(r.set(o.NULL_EXPR).toDeclStmt());
body.push(o.ifStmt(t, [r.set(ctorExprFinal).toStmt()], [r.set(nonCtorExpr).toStmt()]));
return r;
}
if (isDelegatedMetadata(meta) && meta.delegateType === R3FactoryDelegateType.Factory) {
var delegateFactory = o.variable("\u0275" + meta.name + "_BaseFactory");
var getFactoryOf = o.importExpr(r3_identifiers_1.Identifiers.getFactoryOf);
if (meta.delegate.isEquivalent(meta.type)) {
throw new Error("Illegal state: compiling factory that delegates to itself");
}
var delegateFactoryStmt = delegateFactory.set(getFactoryOf.callFn([meta.delegate])).toDeclStmt(o.INFERRED_TYPE, [
o.StmtModifier.Exported, o.StmtModifier.Final
]);
statements.push(delegateFactoryStmt);
retExpr = makeConditionalFactory(delegateFactory.callFn([]));
}
else if (isDelegatedMetadata(meta)) {
// This type is created with a delegated factory. If a type parameter is not specified, call
// the factory instead.
var delegateArgs = injectDependencies(meta.delegateDeps, meta.injectFn);
// Either call `new delegate(...)` or `delegate(...)` depending on meta.useNewForDelegate.
var factoryExpr = new (meta.delegateType === R3FactoryDelegateType.Class ?
o.InstantiateExpr :
o.InvokeFunctionExpr)(meta.delegate, delegateArgs);
retExpr = makeConditionalFactory(factoryExpr);
}
else if (isExpressionFactoryMetadata(meta)) {
// TODO(alxhub): decide whether to lower the value here or in the caller
definitionMapValues.push({ key: 'factory', value: templateFactory, quoted: false });
// e.g. `pure: true`
if (pipe.pure) {
definitionMapValues.push({ key: 'pure', value: o.literal(true), quoted: false });
}
var className = compile_metadata_1.identifierName(pipe.type);
className || util_1.error("Cannot resolve the name of " + pipe.type);
var definitionField = outputCtx.constantPool.propertyNameOf(3 /* Pipe */);
var definitionFunction = o.importExpr(r3_identifiers_1.Identifiers.definePipe).callFn([o.literalMap(definitionMapValues)]);
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */ [new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */ [o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */ [],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */ []));
}
exports.compilePipe = compilePipe;
function createContentQueriesRefreshFunction(meta) {
if (meta.queries.length > 0) {
var statements_1 = [];
var typeName = meta.name;
var parameters = [
new o.FnParam('dirIndex', o.NUMBER_TYPE),
new o.FnParam('queryStartIndex', o.NUMBER_TYPE),
];
var directiveInstanceVar_1 = o.variable('instance');
// var $tmp$: any;
var temporary_1 = util_3.temporaryAllocator(statements_1, util_3.TEMPORARY_NAME);
// const $instance$ = $r3$.ɵload(dirIndex);
statements_1.push(directiveInstanceVar_1.set(o.importExpr(r3_identifiers_1.Identifiers.load).callFn([o.variable('dirIndex')]))
.toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Final]));
meta.queries.forEach(function (query, idx) {
var loadQLArg = o.variable('queryStartIndex');
var getQueryList = o.importExpr(r3_identifiers_1.Identifiers.loadQueryList).callFn([
idx > 0 ? loadQLArg.plus(o.literal(idx)) : loadQLArg
]);
var assignToTemporary = temporary_1().set(getQueryList);
var callQueryRefresh = o.importExpr(r3_identifiers_1.Identifiers.queryRefresh).callFn([assignToTemporary]);
var updateDirective = directiveInstanceVar_1.prop(query.propertyName)
.set(query.first ? temporary_1().prop('first') : temporary_1());
var refreshQueryAndUpdateDirective = callQueryRefresh.and(updateDirective);
statements_1.push(refreshQueryAndUpdateDirective.toStmt());
});
return o.fn(parameters, statements_1, o.INFERRED_TYPE, null, typeName ? typeName + "_ContentQueriesRefresh" : null);
}
return null;
}
parentBindingScope.nestedScope(function (lhsVar, expression) {
_this._bindingCode.push(lhsVar.set(expression).toDeclStmt(o.INFERRED_TYPE, [o.StmtModifier.Final]));
});
this._valueConverter = new ValueConverter(constantPool, function () { return _this.allocateDataSlot(); }, function (numSlots) { return _this._pureFunctionSlots += numSlots; }, function (name, localName, slot, value) {
InjectableCompiler.prototype.compile = function (injectable, ctx) {
if (this.alwaysGenerateDef || injectable.providedIn !== undefined) {
var className = compile_metadata_1.identifierName(injectable.type);
var clazz = new o.ClassStmt(className, null, [
new o.ClassField('ngInjectableDef', o.INFERRED_TYPE, [o.StmtModifier.Static], this.injectableDef(injectable, ctx)),
], [], new o.ClassMethod(null, [], []), []);
ctx.statements.push(clazz);
}
};
return InjectableCompiler;
StatementInterpreter.prototype.visitDeclareVarStmt = function (stmt, ctx) {
var 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);
}
return null;
};
StatementInterpreter.prototype.visitWriteVarExpr = function (expr, ctx) {
JitEmitterVisitor.prototype.visitDeclareClassStmt = function (stmt, ctx) {
if (stmt.hasModifier(o.StmtModifier.Exported)) {
this._evalExportedVars.push(stmt.name);
}
return _super.prototype.visitDeclareClassStmt.call(this, stmt, ctx);
};
return JitEmitterVisitor;