How to use the @angular/compiler/src/output/output_ast.literal function in @angular/compiler

To help you get started, we’ve selected a few @angular/compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / compiler-builds / src / render3 / view / template.js View on Github external
function getLiteralFactory(constantPool, literal, allocateSlots) {
        var _a = constantPool.getLiteralFactory(literal), literalFactory = _a.literalFactory, literalFactoryArguments = _a.literalFactoryArguments;
        // Allocate 1 slot for the result plus 1 per argument
        var startSlot = allocateSlots(1 + literalFactoryArguments.length);
        literalFactoryArguments.length > 0 || util_1.error("Expected arguments to a literal factory function");
        var _b = pureFunctionCallInfo(literalFactoryArguments), identifier = _b.identifier, isVarLength = _b.isVarLength;
        // Literal factories are pure functions that only need to be re-invoked when the parameters
        // change.
        var args = [
            o.literal(startSlot),
            literalFactory,
        ];
        if (isVarLength) {
            args.push(o.literalArr(literalFactoryArguments));
        }
        else {
            args.push.apply(args, tslib_1.__spread(literalFactoryArguments));
        }
        return o.importExpr(identifier).callFn(args);
    }
    var BindingScope = /** @class */ (function () {
github angular / compiler-builds / src / render3 / view / styling_builder.js View on Github external
params: function (convertFn) {
                        // params => stylingProp(propName, value)
                        var params = [];
                        params.push(o.literal(input.name));
                        var convertResult = convertFn(value);
                        if (Array.isArray(convertResult)) {
                            params.push.apply(params, tslib_1.__spread(convertResult));
                        }
                        else {
                            params.push(convertResult);
                        }
                        if (allowUnits && input.unit) {
                            params.push(o.literal(input.unit));
                        }
                        return params;
                    }
                };
github angular / compiler-builds / src / render3 / r3_pipe_compiler.js View on Github external
definitionMapValues.push({ key: 'name', value: o.literal(pipe.name), quoted: false });
        // e.g. `type: MyPipe`
        definitionMapValues.push({ key: 'type', value: outputCtx.importExpr(pipe.type.reference), quoted: false });
        // e.g. `factory: function MyPipe_Factory() { return new MyPipe(); }`
        var deps = r3_factory_1.dependenciesFromGlobalMetadata(pipe.type, outputCtx, reflector);
        var templateFactory = r3_factory_1.compileFactoryFunction({
            name: compile_metadata_1.identifierName(pipe.type),
            fnOrClass: outputCtx.importExpr(pipe.type.reference), deps: deps,
            useNew: true,
            injectFn: r3_identifiers_1.Identifiers.directiveInject,
            useOptionalParam: false,
        });
        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 */ []));
github angular / compiler-builds / src / render3 / view / styling_builder.js View on Github external
StylingBuilder.prototype.populateInitialStylingAttrs = function (attrs) {
            // [CLASS_MARKER, 'foo', 'bar', 'baz' ...]
            if (this._initialClassValues.length) {
                attrs.push(o.literal(1 /* Classes */));
                for (var i = 0; i < this._initialClassValues.length; i++) {
                    attrs.push(o.literal(this._initialClassValues[i]));
                }
            }
            // [STYLE_MARKER, 'width', '200px', 'height', '100px', ...]
            if (this._initialStyleValues.length) {
                attrs.push(o.literal(2 /* Styles */));
                for (var i = 0; i < this._initialStyleValues.length; i += 2) {
                    attrs.push(o.literal(this._initialStyleValues[i]), o.literal(this._initialStyleValues[i + 1]));
                }
            }
        };
        /**
github johandb / svg-drawing-tool / node_modules / @angular / compiler / src / render3 / view / util.js View on Github external
                var selectors = selector.split(',').map(function (token) { return o.literal(token.trim()); });
                predicate_1.push.apply(predicate_1, tslib_1.__spread(selectors));
github johandb / svg-drawing-tool / node_modules / @angular / compiler / src / constant_pool.js View on Github external
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);
github johandb / svg-drawing-tool / node_modules / @angular / compiler / src / render3 / view / util.js View on Github external
function asLiteral(value) {
        if (Array.isArray(value)) {
            return o.literalArr(value.map(asLiteral));
        }
        return o.literal(value, o.INFERRED_TYPE);
    }
    exports.asLiteral = asLiteral;
github angular / compiler-builds / src / render3 / r3_module_compiler.js View on Github external
function convertMetaToOutput(meta, ctx) {
        if (Array.isArray(meta)) {
            return o.literalArr(meta.map(function (entry) { return convertMetaToOutput(entry, ctx); }));
        }
        if (meta instanceof static_symbol_1.StaticSymbol) {
            return ctx.importExpr(meta);
        }
        if (meta == null) {
            return o.literal(meta);
        }
        throw new Error("Internal error: Unsupported or unknown metadata: " + meta);
    }
    function compileNgModule(ctx, ngModule, injectableCompiler) {
github johandb / svg-drawing-tool / node_modules / @angular / compiler / src / render3 / util.js View on Github external
function convertMetaToOutput(meta, ctx) {
        if (Array.isArray(meta)) {
            return o.literalArr(meta.map(function (entry) { return convertMetaToOutput(entry, ctx); }));
        }
        if (meta instanceof static_symbol_1.StaticSymbol) {
            return ctx.importExpr(meta);
        }
        if (meta == null) {
            return o.literal(meta);
        }
        throw new Error("Internal error: Unsupported or unknown metadata: " + meta);
    }
    exports.convertMetaToOutput = convertMetaToOutput;