UNPKG

9.89 kBJavaScriptView Raw
1/**
2 * @license Angular v13.2.0
3 * (c) 2010-2022 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { CompilerConfig, ResourceLoader } from '@angular/compiler';
8import * as i0 from '@angular/core';
9import { InjectionToken, PACKAGE_ROOT_URL, Compiler, ViewEncapsulation, MissingTranslationStrategy, Injector, isDevMode, createPlatformFactory, platformCore, COMPILER_OPTIONS, CompilerFactory, Injectable, PLATFORM_ID, ɵglobal, Version } from '@angular/core';
10import { ɵPLATFORM_BROWSER_ID } from '@angular/common';
11import { ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS } from '@angular/platform-browser';
12
13/**
14 * @license
15 * Copyright Google LLC All Rights Reserved.
16 *
17 * Use of this source code is governed by an MIT-style license that can be
18 * found in the LICENSE file at https://angular.io/license
19 */
20const ERROR_COLLECTOR_TOKEN = new InjectionToken('ErrorCollector');
21/**
22 * A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
23 */
24const DEFAULT_PACKAGE_URL_PROVIDER = {
25 provide: PACKAGE_ROOT_URL,
26 useValue: '/'
27};
28const COMPILER_PROVIDERS = [{ provide: Compiler, useFactory: () => new Compiler() }];
29/**
30 * @publicApi
31 *
32 * @deprecated
33 * Ivy JIT mode doesn't require accessing this symbol.
34 * See [JIT API changes due to ViewEngine deprecation](guide/deprecations#jit-api-changes) for
35 * additional context.
36 */
37class JitCompilerFactory {
38 /* @internal */
39 constructor(defaultOptions) {
40 const compilerOptions = {
41 useJit: true,
42 defaultEncapsulation: ViewEncapsulation.Emulated,
43 missingTranslation: MissingTranslationStrategy.Warning,
44 };
45 this._defaultOptions = [compilerOptions, ...defaultOptions];
46 }
47 createCompiler(options = []) {
48 const opts = _mergeOptions(this._defaultOptions.concat(options));
49 const injector = Injector.create([
50 COMPILER_PROVIDERS, {
51 provide: CompilerConfig,
52 useFactory: () => {
53 return new CompilerConfig({
54 // let explicit values from the compiler options overwrite options
55 // from the app providers
56 useJit: opts.useJit,
57 jitDevMode: isDevMode(),
58 // let explicit values from the compiler options overwrite options
59 // from the app providers
60 defaultEncapsulation: opts.defaultEncapsulation,
61 missingTranslation: opts.missingTranslation,
62 preserveWhitespaces: opts.preserveWhitespaces,
63 });
64 },
65 deps: []
66 },
67 opts.providers
68 ]);
69 return injector.get(Compiler);
70 }
71}
72function _mergeOptions(optionsArr) {
73 return {
74 useJit: _lastDefined(optionsArr.map(options => options.useJit)),
75 defaultEncapsulation: _lastDefined(optionsArr.map(options => options.defaultEncapsulation)),
76 providers: _mergeArrays(optionsArr.map(options => options.providers)),
77 missingTranslation: _lastDefined(optionsArr.map(options => options.missingTranslation)),
78 preserveWhitespaces: _lastDefined(optionsArr.map(options => options.preserveWhitespaces)),
79 };
80}
81function _lastDefined(args) {
82 for (let i = args.length - 1; i >= 0; i--) {
83 if (args[i] !== undefined) {
84 return args[i];
85 }
86 }
87 return undefined;
88}
89function _mergeArrays(parts) {
90 const result = [];
91 parts.forEach((part) => part && result.push(...part));
92 return result;
93}
94
95/**
96 * @license
97 * Copyright Google LLC All Rights Reserved.
98 *
99 * Use of this source code is governed by an MIT-style license that can be
100 * found in the LICENSE file at https://angular.io/license
101 */
102/**
103 * A platform that included corePlatform and the compiler.
104 *
105 * @publicApi
106 */
107const platformCoreDynamic = createPlatformFactory(platformCore, 'coreDynamic', [
108 { provide: COMPILER_OPTIONS, useValue: {}, multi: true },
109 { provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS] },
110]);
111
112/**
113 * @license
114 * Copyright Google LLC All Rights Reserved.
115 *
116 * Use of this source code is governed by an MIT-style license that can be
117 * found in the LICENSE file at https://angular.io/license
118 */
119class ResourceLoaderImpl extends ResourceLoader {
120 get(url) {
121 let resolve;
122 let reject;
123 const promise = new Promise((res, rej) => {
124 resolve = res;
125 reject = rej;
126 });
127 const xhr = new XMLHttpRequest();
128 xhr.open('GET', url, true);
129 xhr.responseType = 'text';
130 xhr.onload = function () {
131 // responseText is the old-school way of retrieving response (supported by IE8 & 9)
132 // response/responseType properties were introduced in ResourceLoader Level2 spec (supported
133 // by IE10)
134 const response = xhr.response || xhr.responseText;
135 // normalize IE9 bug (https://bugs.jquery.com/ticket/1450)
136 let status = xhr.status === 1223 ? 204 : xhr.status;
137 // fix status code when it is 0 (0 status is undocumented).
138 // Occurs when accessing file resources or on Android 4.1 stock browser
139 // while retrieving files from application cache.
140 if (status === 0) {
141 status = response ? 200 : 0;
142 }
143 if (200 <= status && status <= 300) {
144 resolve(response);
145 }
146 else {
147 reject(`Failed to load ${url}`);
148 }
149 };
150 xhr.onerror = function () {
151 reject(`Failed to load ${url}`);
152 };
153 xhr.send();
154 return promise;
155 }
156}
157ResourceLoaderImpl.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ResourceLoaderImpl, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
158ResourceLoaderImpl.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ResourceLoaderImpl });
159i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ResourceLoaderImpl, decorators: [{
160 type: Injectable
161 }] });
162
163/**
164 * @license
165 * Copyright Google LLC All Rights Reserved.
166 *
167 * Use of this source code is governed by an MIT-style license that can be
168 * found in the LICENSE file at https://angular.io/license
169 */
170/**
171 * @publicApi
172 */
173const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS = [
174 ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS,
175 {
176 provide: COMPILER_OPTIONS,
177 useValue: { providers: [{ provide: ResourceLoader, useClass: ResourceLoaderImpl, deps: [] }] },
178 multi: true
179 },
180 { provide: PLATFORM_ID, useValue: ɵPLATFORM_BROWSER_ID },
181];
182
183/**
184 * @license
185 * Copyright Google LLC All Rights Reserved.
186 *
187 * Use of this source code is governed by an MIT-style license that can be
188 * found in the LICENSE file at https://angular.io/license
189 */
190/**
191 * An implementation of ResourceLoader that uses a template cache to avoid doing an actual
192 * ResourceLoader.
193 *
194 * The template cache needs to be built and loaded into window.$templateCache
195 * via a separate mechanism.
196 *
197 * @publicApi
198 *
199 * @deprecated This was previously necessary in some cases to test AOT-compiled components with View
200 * Engine, but is no longer since Ivy.
201 */
202class CachedResourceLoader extends ResourceLoader {
203 constructor() {
204 super();
205 this._cache = ɵglobal.$templateCache;
206 if (this._cache == null) {
207 throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
208 }
209 }
210 get(url) {
211 if (this._cache.hasOwnProperty(url)) {
212 return Promise.resolve(this._cache[url]);
213 }
214 else {
215 return Promise.reject('CachedResourceLoader: Did not find cached template for ' + url);
216 }
217 }
218}
219
220/**
221 * @license
222 * Copyright Google LLC All Rights Reserved.
223 *
224 * Use of this source code is governed by an MIT-style license that can be
225 * found in the LICENSE file at https://angular.io/license
226 */
227
228/**
229 * @license
230 * Copyright Google LLC All Rights Reserved.
231 *
232 * Use of this source code is governed by an MIT-style license that can be
233 * found in the LICENSE file at https://angular.io/license
234 */
235/**
236 * @publicApi
237 */
238const VERSION = new Version('13.2.0');
239
240/**
241 * @license
242 * Copyright Google LLC All Rights Reserved.
243 *
244 * Use of this source code is governed by an MIT-style license that can be
245 * found in the LICENSE file at https://angular.io/license
246 */
247/**
248 * @publicApi
249 *
250 * @deprecated This was previously necessary in some cases to test AOT-compiled components with View
251 * Engine, but is no longer since Ivy.
252
253 */
254const RESOURCE_CACHE_PROVIDER = [{ provide: ResourceLoader, useClass: CachedResourceLoader, deps: [] }];
255/**
256 * @publicApi
257 */
258const platformBrowserDynamic = createPlatformFactory(platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
259
260/**
261 * @license
262 * Copyright Google LLC All Rights Reserved.
263 *
264 * Use of this source code is governed by an MIT-style license that can be
265 * found in the LICENSE file at https://angular.io/license
266 */
267// This file only reexports content of the `src` folder. Keep it that way.
268
269/**
270 * @license
271 * Copyright Google LLC All Rights Reserved.
272 *
273 * Use of this source code is governed by an MIT-style license that can be
274 * found in the LICENSE file at https://angular.io/license
275 */
276
277/**
278 * Generated bundle index. Do not edit.
279 */
280
281export { JitCompilerFactory, RESOURCE_CACHE_PROVIDER, VERSION, platformBrowserDynamic, INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, platformCoreDynamic as ɵplatformCoreDynamic };
282//# sourceMappingURL=platform-browser-dynamic.mjs.map