mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
This commit removes the View Engine runtime. Itself, this change is relatively straightforward, but it represents the final step in a multi-year journey. It's only possible due to the hard work of many current and former team members and collaborators, who are too numerous to list here. Co-authored-by: Alan Agius <alan.agius4@gmail.com> Co-authored-by: Andrew Kushnir <akushnir@google.com> Co-authored-by: Andrew Scott <atscott01@gmail.com> Co-authored-by: Andrew Seguin <andrewjs@google.com> Co-authored-by: Cédric Exbrayat <cedric@ninja-squad.com> Co-authored-by: Charles Lyding <19598772+clydin@users.noreply.github.com> Co-authored-by: Dave Shevitz <dshevitz@google.com> Co-authored-by: Doug Parker <dgp1130@users.noreply.github.com> Co-authored-by: Dylan Hunn <dylhunn@gmail.com> Co-authored-by: Emma Twersky <emmatwersky@google.com> Co-authored-by: George Kalpakas <kalpakas.g@gmail.com> Co-authored-by: Igor Minar <iminar@google.com> Co-authored-by: Jeremy Elbourn <jelbourn@google.com> Co-authored-by: Jessica Janiuk <jessicajaniuk@google.com> Co-authored-by: JiaLiPassion <JiaLi.Passion@gmail.com> Co-authored-by: Joey Perrott <josephperrott@gmail.com> Co-authored-by: Joost Koehoorn <joost.koehoorn@gmail.com> Co-authored-by: Kristiyan Kostadinov <crisbeto@abv.bg> Co-authored-by: Madleina Scheidegger <mscheid@google.com> Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com> Co-authored-by: Minko Gechev <mgechev@gmail.com> Co-authored-by: Paul Gschwendtner <paulgschwendtner@gmail.com> Co-authored-by: Pawel Kozlowski <pkozlowski.opensource@gmail.com> Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com> Co-authored-by: Wagner Maciel <wagnermaciel@google.com> Co-authored-by: Zach Arend <zachzach@google.com> PR Close #43884
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
/**
|
|
* @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, CompilerFactory, CompilerOptions, InjectionToken, Injector, isDevMode, MissingTranslationStrategy, PACKAGE_ROOT_URL, StaticProvider, ViewEncapsulation} from '@angular/core';
|
|
|
|
export const ERROR_COLLECTOR_TOKEN = new InjectionToken('ErrorCollector');
|
|
|
|
/**
|
|
* A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
|
|
*/
|
|
export const DEFAULT_PACKAGE_URL_PROVIDER = {
|
|
provide: PACKAGE_ROOT_URL,
|
|
useValue: '/'
|
|
};
|
|
|
|
export const COMPILER_PROVIDERS =
|
|
<StaticProvider[]>[{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 implements CompilerFactory {
|
|
private _defaultOptions: CompilerOptions[];
|
|
|
|
/* @internal */
|
|
constructor(defaultOptions: CompilerOptions[]) {
|
|
const compilerOptions: CompilerOptions = {
|
|
useJit: true,
|
|
defaultEncapsulation: ViewEncapsulation.Emulated,
|
|
missingTranslation: MissingTranslationStrategy.Warning,
|
|
};
|
|
|
|
this._defaultOptions = [compilerOptions, ...defaultOptions];
|
|
}
|
|
createCompiler(options: CompilerOptions[] = []): Compiler {
|
|
const opts = _mergeOptions(this._defaultOptions.concat(options));
|
|
const injector = Injector.create([
|
|
COMPILER_PROVIDERS, {
|
|
provide: CompilerConfig,
|
|
useFactory: () => {
|
|
return new CompilerConfig({
|
|
// let explicit values from the compiler options overwrite options
|
|
// from the app providers
|
|
useJit: opts.useJit,
|
|
jitDevMode: isDevMode(),
|
|
// 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: CompilerOptions[]): CompilerOptions {
|
|
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<T>(args: T[]): T|undefined {
|
|
for (let i = args.length - 1; i >= 0; i--) {
|
|
if (args[i] !== undefined) {
|
|
return args[i];
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function _mergeArrays(parts: any[][]): any[] {
|
|
const result: any[] = [];
|
|
parts.forEach((part) => part && result.push(...part));
|
|
return result;
|
|
}
|