Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ConstantPool.prototype.getLiteralFactory = function (literal) {
// Create a pure function that builds an array of a mix of constant and variable expressions
if (literal instanceof o.LiteralArrayExpr) {
var argumentsForKey = literal.entries.map(function (e) { return e.isConstant() ? e : o.literal(null); });
var key = this.keyOf(o.literalArr(argumentsForKey));
return this._getLiteralFactory(key, literal.entries, function (entries) { return o.literalArr(entries); });
}
else {
var expressionForKey = o.literalMap(literal.entries.map(function (e) { return ({
key: e.key,
value: e.value.isConstant() ? e.value : o.literal(null),
quoted: e.quoted
}); }));
var key = this.keyOf(expressionForKey);
return this._getLiteralFactory(key, literal.entries.map(function (e) { return e.value; }), function (entries) { return o.literalMap(entries.map(function (value, index) { return ({
key: literal.entries[index].key,
value: value,
quoted: literal.entries[index].quoted
}); })); });
}
};
ConstantPool.prototype._getLiteralFactory = function (key, values, resultMap) {
return new expression_converter_1.BuiltinFunctionCall(map.span, this.visitAll(map.values), function (values) {
// If the literal has calculated (non-literal) elements transform it into
// calls to literal factories that compose the literal and will cache intermediate
// values. Otherwise, just return an literal array that contains the values.
var literal = o.literalMap(values.map(function (value, index) { return ({ key: map.keys[index].key, value: value, quoted: map.keys[index].quoted }); }));
return values.every(function (a) { return a.isConstant(); }) ?
_this.constantPool.getConstLiteral(literal, true) :
getLiteralFactory(_this.constantPool, literal, _this.allocatePureFunctionSlots);
});
};
compileStyles(meta.styles, style_compiler_1.CONTENT_ATTR, style_compiler_1.HOST_ATTR) :
meta.styles;
var strings = styleValues.map(function (str) { return o.literal(str); });
definitionMap.set('styles', o.literalArr(strings));
}
else if (meta.encapsulation === core.ViewEncapsulation.Emulated) {
// If there is no style, don't generate css selectors on elements
meta.encapsulation = core.ViewEncapsulation.None;
}
// Only set view encapsulation if it's not the default value
if (meta.encapsulation !== core.ViewEncapsulation.Emulated) {
definitionMap.set('encapsulation', o.literal(meta.encapsulation));
}
// e.g. `animation: [trigger('123', [])]`
if (meta.animations !== null) {
definitionMap.set('data', o.literalMap([{ key: 'animation', value: meta.animations, quoted: false }]));
}
// Only set the change detection flag if it's defined and it's not the default.
if (changeDetection != null && changeDetection !== core.ChangeDetectionStrategy.Default) {
definitionMap.set('changeDetection', o.literal(changeDetection));
}
// On the type side, remove newlines from the selector as it will need to fit into a TypeScript
// string literal, which must be on one line.
var selectorForType = (meta.selector || '').replace(/\n/g, '');
var expression = o.importExpr(r3_identifiers_1.Identifiers.defineComponent).callFn([definitionMap.toLiteralMap()]);
var type = createTypeForDef(meta, r3_identifiers_1.Identifiers.ComponentDefWithMeta);
return { expression: expression, type: type, statements: statements };
}
exports.compileComponentFromMetadata = compileComponentFromMetadata;
function compilePipeFromMetadata(metadata) {
var definitionMapValues = [];
// e.g. `name: 'myPipe'`
definitionMapValues.push({ key: 'name', value: o.literal(metadata.pipeName), quoted: false });
// e.g. `type: MyPipe`
definitionMapValues.push({ key: 'type', value: metadata.type, quoted: false });
var templateFactory = r3_factory_1.compileFactoryFunction({
name: metadata.name,
type: metadata.type,
deps: metadata.deps,
injectFn: r3_identifiers_1.Identifiers.directiveInject,
});
definitionMapValues.push({ key: 'factory', value: templateFactory.factory, quoted: false });
// e.g. `pure: true`
definitionMapValues.push({ key: 'pure', value: o.literal(metadata.pure), quoted: false });
var expression = o.importExpr(r3_identifiers_1.Identifiers.definePipe).callFn([o.literalMap(definitionMapValues)]);
var type = new o.ExpressionType(o.importExpr(r3_identifiers_1.Identifiers.PipeDefWithMeta, [
new o.ExpressionType(metadata.type),
new o.ExpressionType(new o.LiteralExpr(metadata.pipeName)),
]));
return { expression: expression, type: type, statements: templateFactory.statements };
}
exports.compilePipeFromMetadata = compilePipeFromMetadata;
ConstantPool.prototype.getLiteralFactory = function (literal) {
// Create a pure function that builds an array of a mix of constant and variable expressions
if (literal instanceof o.LiteralArrayExpr) {
var argumentsForKey = literal.entries.map(function (e) { return e.isConstant() ? e : o.literal(null); });
var key = this.keyOf(o.literalArr(argumentsForKey));
return this._getLiteralFactory(key, literal.entries, function (entries) { return o.literalArr(entries); });
}
else {
var expressionForKey = o.literalMap(literal.entries.map(function (e) { return ({
key: e.key,
value: e.value.isConstant() ? e.value : o.literal(null),
quoted: e.quoted
}); }));
var key = this.keyOf(expressionForKey);
return this._getLiteralFactory(key, literal.entries.map(function (e) { return e.value; }), function (entries) { return o.literalMap(entries.map(function (value, index) { return ({
key: literal.entries[index].key,
value: value,
quoted: literal.entries[index].quoted
}); })); });
}
};
ConstantPool.prototype._getLiteralFactory = function (key, values, resultMap) {
createLiteralMapConverter: function (keys) { return function (values) {
var entries = keys.map(function (k, i) { return ({
key: k.key,
value: values[i],
quoted: k.quoted,
}); });
var map = o.literalMap(entries);
// Note: The old view compiler used to use an `any` type
// for maps.
return _this.options.fullTemplateTypeCheck ? map : map.cast(o.DYNAMIC_TYPE);
}; },
createPipeConverter: function (name, argCount) { return function (args) {
function mapToExpression(map, keepDeclared) {
return o.literalMap(Object.getOwnPropertyNames(map).map(function (key) {
var _a, _b;
// canonical syntax: `dirProp: publicProp`
// if there is no `:`, use dirProp = elProp
var value = map[key];
var declaredName;
var publicName;
var minifiedName;
if (Array.isArray(value)) {
_a = tslib_1.__read(value, 2), publicName = _a[0], declaredName = _a[1];
}
else {
_b = tslib_1.__read(util_1.splitAtColon(key, [key, value]), 2), declaredName = _b[0], publicName = _b[1];
}
minifiedName = declaredName;
return {
key: minifiedName,
function mapToMapExpression(map) {
var result = Object.keys(map).map(function (key) { return ({ key: key, value: map[key], quoted: false }); });
return o.literalMap(result);
}
exports.mapToMapExpression = mapToMapExpression;
function mapToMapExpression(map) {
var result = Object.keys(map).map(function (key) { return ({ key: key, value: map[key], quoted: false }); });
return o.literalMap(result);
}
exports.mapToMapExpression = mapToMapExpression;
function compileModuleFactory(outputCtx, module, backPatchReferenceOf, resolver) {
var ngModuleFactoryVar = compile_metadata_1.identifierName(module.type) + "NgFactory";
var parentInjector = 'parentInjector';
var createFunction = o.fn([new o.FnParam(parentInjector, o.DYNAMIC_TYPE)], [new o.IfStmt(o.THIS_EXPR.prop(r3_identifiers_1.Identifiers.PATCH_DEPS).notIdentical(o.literal(true, o.INFERRED_TYPE)), [
o.THIS_EXPR.prop(r3_identifiers_1.Identifiers.PATCH_DEPS).set(o.literal(true, o.INFERRED_TYPE)).toStmt(),
backPatchReferenceOf(module.type).callFn([]).toStmt()
])], o.INFERRED_TYPE, null, ngModuleFactoryVar + "_Create");
var moduleFactoryLiteral = o.literalMap([
{ key: 'moduleType', value: outputCtx.importExpr(module.type.reference), quoted: false },
{ key: 'create', value: createFunction, quoted: false }
]);
outputCtx.statements.push(o.variable(ngModuleFactoryVar).set(moduleFactoryLiteral).toDeclStmt(o.DYNAMIC_TYPE, [
o.StmtModifier.Exported, o.StmtModifier.Final
]));
}
exports.compileModuleFactory = compileModuleFactory;