/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { CompilerConfig } from '@angular/compiler'; import { Compiler, Injector, MissingTranslationStrategy, ViewEncapsulation } from '@angular/core'; export const COMPILER_PROVIDERS = [{ provide: Compiler, useFactory: () => new Compiler() }]; /** * @publicApi * * @deprecated * Ivy JIT mode doesn't require accessing this symbol. * See [JIT API changes due to ViewEngine deprecation](guide/deprecations#jit-api-changes) for * additional context. */ export class JitCompilerFactory { /** @internal */ constructor(defaultOptions) { const compilerOptions = { useJit: true, defaultEncapsulation: ViewEncapsulation.Emulated, missingTranslation: MissingTranslationStrategy.Warning, }; this._defaultOptions = [compilerOptions, ...defaultOptions]; } createCompiler(options = []) { const opts = _mergeOptions(this._defaultOptions.concat(options)); const injector = Injector.create({ providers: [ COMPILER_PROVIDERS, { provide: CompilerConfig, useFactory: () => { return new CompilerConfig({ // let explicit values from the compiler options overwrite options // from the app providers useJit: opts.useJit, // let explicit values from the compiler options overwrite options // from the app providers defaultEncapsulation: opts.defaultEncapsulation, missingTranslation: opts.missingTranslation, preserveWhitespaces: opts.preserveWhitespaces, }); }, deps: [] }, opts.providers ] }); return injector.get(Compiler); } } function _mergeOptions(optionsArr) { return { useJit: _lastDefined(optionsArr.map(options => options.useJit)), defaultEncapsulation: _lastDefined(optionsArr.map(options => options.defaultEncapsulation)), providers: _mergeArrays(optionsArr.map(options => options.providers)), missingTranslation: _lastDefined(optionsArr.map(options => options.missingTranslation)), preserveWhitespaces: _lastDefined(optionsArr.map(options => options.preserveWhitespaces)), }; } function _lastDefined(args) { for (let i = args.length - 1; i >= 0; i--) { if (args[i] !== undefined) { return args[i]; } } return undefined; } function _mergeArrays(parts) { const result = []; parts.forEach((part) => part && result.push(...part)); return result; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGlsZXJfZmFjdG9yeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJz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