UNPKG

21.3 kBJavaScriptView Raw
1/**
2 * @license Angular v9.0.6
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { getUrlScheme, syntaxError, Identifiers, JitCompiler, ProviderMeta, I18NHtmlParser, CompilerConfig, CompileReflector, ResourceLoader, JitSummaryResolver, SummaryResolver, Lexer, Parser, HtmlParser, TemplateParser, ElementSchemaRegistry, JitEvaluator, DirectiveNormalizer, UrlResolver, CompileMetadataResolver, NgModuleResolver, DirectiveResolver, PipeResolver, StaticSymbolCache, StyleCompiler, ViewCompiler, NgModuleCompiler, DomElementSchemaRegistry } from '@angular/compiler';
8import { ɵReflectionCapabilities, ɵstringify, ANALYZE_FOR_ENTRY_COMPONENTS, ElementRef, NgModuleRef, ViewContainerRef, ChangeDetectorRef, Renderer2, QueryList, TemplateRef, ɵCodegenComponentFactoryResolver, ComponentFactoryResolver, ComponentFactory, ComponentRef, NgModuleFactory, ɵcmf, ɵmod, ɵmpd, ɵregisterModuleFactory, Injector, ViewEncapsulation, ChangeDetectionStrategy, SecurityContext, LOCALE_ID, TRANSLATIONS_FORMAT, ɵinlineInterpolate, ɵinterpolate, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵvid, ɵeld, ɵand, ɵted, ɵdid, ɵprd, ɵqud, ɵpad, ɵpod, ɵppd, ɵpid, ɵnov, ɵncd, ɵunv, ɵcrt, ɵccf, InjectionToken, PACKAGE_ROOT_URL, Compiler, MissingTranslationStrategy, ɵConsole, Optional, Inject, TRANSLATIONS, isDevMode, createPlatformFactory, platformCore, COMPILER_OPTIONS, CompilerFactory, Injectable, PLATFORM_ID, ɵglobal, Version } from '@angular/core';
9import { __spread, __extends, __decorate } from 'tslib';
10import { ɵPLATFORM_BROWSER_ID } from '@angular/common';
11import { ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS } from '@angular/platform-browser';
12
13/**
14 * @license
15 * Copyright Google Inc. 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 */
20var MODULE_SUFFIX = '';
21var builtinExternalReferences = createBuiltinExternalReferencesMap();
22var JitReflector = /** @class */ (function () {
23 function JitReflector() {
24 this.reflectionCapabilities = new ɵReflectionCapabilities();
25 }
26 JitReflector.prototype.componentModuleUrl = function (type, cmpMetadata) {
27 var moduleId = cmpMetadata.moduleId;
28 if (typeof moduleId === 'string') {
29 var scheme = getUrlScheme(moduleId);
30 return scheme ? moduleId : "package:" + moduleId + MODULE_SUFFIX;
31 }
32 else if (moduleId !== null && moduleId !== void 0) {
33 throw syntaxError("moduleId should be a string in \"" + ɵstringify(type) + "\". See https://goo.gl/wIDDiL for more information.\n" +
34 "If you're using Webpack you should inline the template and the styles, see https://goo.gl/X2J8zc.");
35 }
36 return "./" + ɵstringify(type);
37 };
38 JitReflector.prototype.parameters = function (typeOrFunc) {
39 return this.reflectionCapabilities.parameters(typeOrFunc);
40 };
41 JitReflector.prototype.tryAnnotations = function (typeOrFunc) { return this.annotations(typeOrFunc); };
42 JitReflector.prototype.annotations = function (typeOrFunc) {
43 return this.reflectionCapabilities.annotations(typeOrFunc);
44 };
45 JitReflector.prototype.shallowAnnotations = function (typeOrFunc) {
46 throw new Error('Not supported in JIT mode');
47 };
48 JitReflector.prototype.propMetadata = function (typeOrFunc) {
49 return this.reflectionCapabilities.propMetadata(typeOrFunc);
50 };
51 JitReflector.prototype.hasLifecycleHook = function (type, lcProperty) {
52 return this.reflectionCapabilities.hasLifecycleHook(type, lcProperty);
53 };
54 JitReflector.prototype.guards = function (type) { return this.reflectionCapabilities.guards(type); };
55 JitReflector.prototype.resolveExternalReference = function (ref) {
56 return builtinExternalReferences.get(ref) || ref.runtime;
57 };
58 return JitReflector;
59}());
60function createBuiltinExternalReferencesMap() {
61 var map = new Map();
62 map.set(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS, ANALYZE_FOR_ENTRY_COMPONENTS);
63 map.set(Identifiers.ElementRef, ElementRef);
64 map.set(Identifiers.NgModuleRef, NgModuleRef);
65 map.set(Identifiers.ViewContainerRef, ViewContainerRef);
66 map.set(Identifiers.ChangeDetectorRef, ChangeDetectorRef);
67 map.set(Identifiers.Renderer2, Renderer2);
68 map.set(Identifiers.QueryList, QueryList);
69 map.set(Identifiers.TemplateRef, TemplateRef);
70 map.set(Identifiers.CodegenComponentFactoryResolver, ɵCodegenComponentFactoryResolver);
71 map.set(Identifiers.ComponentFactoryResolver, ComponentFactoryResolver);
72 map.set(Identifiers.ComponentFactory, ComponentFactory);
73 map.set(Identifiers.ComponentRef, ComponentRef);
74 map.set(Identifiers.NgModuleFactory, NgModuleFactory);
75 map.set(Identifiers.createModuleFactory, ɵcmf);
76 map.set(Identifiers.moduleDef, ɵmod);
77 map.set(Identifiers.moduleProviderDef, ɵmpd);
78 map.set(Identifiers.RegisterModuleFactoryFn, ɵregisterModuleFactory);
79 map.set(Identifiers.Injector, Injector);
80 map.set(Identifiers.ViewEncapsulation, ViewEncapsulation);
81 map.set(Identifiers.ChangeDetectionStrategy, ChangeDetectionStrategy);
82 map.set(Identifiers.SecurityContext, SecurityContext);
83 map.set(Identifiers.LOCALE_ID, LOCALE_ID);
84 map.set(Identifiers.TRANSLATIONS_FORMAT, TRANSLATIONS_FORMAT);
85 map.set(Identifiers.inlineInterpolate, ɵinlineInterpolate);
86 map.set(Identifiers.interpolate, ɵinterpolate);
87 map.set(Identifiers.EMPTY_ARRAY, ɵEMPTY_ARRAY);
88 map.set(Identifiers.EMPTY_MAP, ɵEMPTY_MAP);
89 map.set(Identifiers.viewDef, ɵvid);
90 map.set(Identifiers.elementDef, ɵeld);
91 map.set(Identifiers.anchorDef, ɵand);
92 map.set(Identifiers.textDef, ɵted);
93 map.set(Identifiers.directiveDef, ɵdid);
94 map.set(Identifiers.providerDef, ɵprd);
95 map.set(Identifiers.queryDef, ɵqud);
96 map.set(Identifiers.pureArrayDef, ɵpad);
97 map.set(Identifiers.pureObjectDef, ɵpod);
98 map.set(Identifiers.purePipeDef, ɵppd);
99 map.set(Identifiers.pipeDef, ɵpid);
100 map.set(Identifiers.nodeValue, ɵnov);
101 map.set(Identifiers.ngContentDef, ɵncd);
102 map.set(Identifiers.unwrapValue, ɵunv);
103 map.set(Identifiers.createRendererType2, ɵcrt);
104 map.set(Identifiers.createComponentFactory, ɵccf);
105 return map;
106}
107
108/**
109 * @license
110 * Copyright Google Inc. All Rights Reserved.
111 *
112 * Use of this source code is governed by an MIT-style license that can be
113 * found in the LICENSE file at https://angular.io/license
114 */
115var ERROR_COLLECTOR_TOKEN = new InjectionToken('ErrorCollector');
116/**
117 * A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
118 */
119var DEFAULT_PACKAGE_URL_PROVIDER = {
120 provide: PACKAGE_ROOT_URL,
121 useValue: '/'
122};
123var _NO_RESOURCE_LOADER = {
124 get: function (url) {
125 throw new Error("No ResourceLoader implementation has been provided. Can't read the url \"" + url + "\"");
126 }
127};
128var baseHtmlParser = new InjectionToken('HtmlParser');
129var CompilerImpl = /** @class */ (function () {
130 function CompilerImpl(injector, _metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler, summaryResolver, compileReflector, jitEvaluator, compilerConfig, console) {
131 this._metadataResolver = _metadataResolver;
132 this._delegate = new JitCompiler(_metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler, summaryResolver, compileReflector, jitEvaluator, compilerConfig, console, this.getExtraNgModuleProviders.bind(this));
133 this.injector = injector;
134 }
135 CompilerImpl.prototype.getExtraNgModuleProviders = function () {
136 return [this._metadataResolver.getProviderMetadata(new ProviderMeta(Compiler, { useValue: this }))];
137 };
138 CompilerImpl.prototype.compileModuleSync = function (moduleType) {
139 return this._delegate.compileModuleSync(moduleType);
140 };
141 CompilerImpl.prototype.compileModuleAsync = function (moduleType) {
142 return this._delegate.compileModuleAsync(moduleType);
143 };
144 CompilerImpl.prototype.compileModuleAndAllComponentsSync = function (moduleType) {
145 var result = this._delegate.compileModuleAndAllComponentsSync(moduleType);
146 return {
147 ngModuleFactory: result.ngModuleFactory,
148 componentFactories: result.componentFactories,
149 };
150 };
151 CompilerImpl.prototype.compileModuleAndAllComponentsAsync = function (moduleType) {
152 return this._delegate.compileModuleAndAllComponentsAsync(moduleType)
153 .then(function (result) { return ({
154 ngModuleFactory: result.ngModuleFactory,
155 componentFactories: result.componentFactories,
156 }); });
157 };
158 CompilerImpl.prototype.loadAotSummaries = function (summaries) { this._delegate.loadAotSummaries(summaries); };
159 CompilerImpl.prototype.hasAotSummary = function (ref) { return this._delegate.hasAotSummary(ref); };
160 CompilerImpl.prototype.getComponentFactory = function (component) {
161 return this._delegate.getComponentFactory(component);
162 };
163 CompilerImpl.prototype.clearCache = function () { this._delegate.clearCache(); };
164 CompilerImpl.prototype.clearCacheFor = function (type) { this._delegate.clearCacheFor(type); };
165 CompilerImpl.prototype.getModuleId = function (moduleType) {
166 var meta = this._metadataResolver.getNgModuleMetadata(moduleType);
167 return meta && meta.id || undefined;
168 };
169 return CompilerImpl;
170}());
171var ɵ0 = new JitReflector(), ɵ1 = _NO_RESOURCE_LOADER, ɵ2 = function (parser, translations, format, config, console) {
172 translations = translations || '';
173 var missingTranslation = translations ? config.missingTranslation : MissingTranslationStrategy.Ignore;
174 return new I18NHtmlParser(parser, translations, format, missingTranslation, console);
175}, ɵ3 = new CompilerConfig();
176/**
177 * A set of providers that provide `JitCompiler` and its dependencies to use for
178 * template compilation.
179 */
180var COMPILER_PROVIDERS__PRE_R3__ = [
181 { provide: CompileReflector, useValue: ɵ0 },
182 { provide: ResourceLoader, useValue: ɵ1 },
183 { provide: JitSummaryResolver, deps: [] },
184 { provide: SummaryResolver, useExisting: JitSummaryResolver },
185 { provide: ɵConsole, deps: [] },
186 { provide: Lexer, deps: [] },
187 { provide: Parser, deps: [Lexer] },
188 {
189 provide: baseHtmlParser,
190 useClass: HtmlParser,
191 deps: [],
192 },
193 {
194 provide: I18NHtmlParser,
195 useFactory: ɵ2,
196 deps: [
197 baseHtmlParser,
198 [new Optional(), new Inject(TRANSLATIONS)],
199 [new Optional(), new Inject(TRANSLATIONS_FORMAT)],
200 [CompilerConfig],
201 [ɵConsole],
202 ]
203 },
204 {
205 provide: HtmlParser,
206 useExisting: I18NHtmlParser,
207 },
208 {
209 provide: TemplateParser, deps: [CompilerConfig, CompileReflector,
210 Parser, ElementSchemaRegistry,
211 I18NHtmlParser, ɵConsole]
212 },
213 { provide: JitEvaluator, useClass: JitEvaluator, deps: [] },
214 { provide: DirectiveNormalizer, deps: [ResourceLoader, UrlResolver, HtmlParser, CompilerConfig] },
215 { provide: CompileMetadataResolver, deps: [CompilerConfig, HtmlParser, NgModuleResolver,
216 DirectiveResolver, PipeResolver,
217 SummaryResolver,
218 ElementSchemaRegistry,
219 DirectiveNormalizer, ɵConsole,
220 [Optional, StaticSymbolCache],
221 CompileReflector,
222 [Optional, ERROR_COLLECTOR_TOKEN]] },
223 DEFAULT_PACKAGE_URL_PROVIDER,
224 { provide: StyleCompiler, deps: [UrlResolver] },
225 { provide: ViewCompiler, deps: [CompileReflector] },
226 { provide: NgModuleCompiler, deps: [CompileReflector] },
227 { provide: CompilerConfig, useValue: ɵ3 },
228 { provide: Compiler, useClass: CompilerImpl, deps: [Injector, CompileMetadataResolver,
229 TemplateParser, StyleCompiler,
230 ViewCompiler, NgModuleCompiler,
231 SummaryResolver, CompileReflector, JitEvaluator, CompilerConfig,
232 ɵConsole] },
233 { provide: DomElementSchemaRegistry, deps: [] },
234 { provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry },
235 { provide: UrlResolver, deps: [PACKAGE_ROOT_URL] },
236 { provide: DirectiveResolver, deps: [CompileReflector] },
237 { provide: PipeResolver, deps: [CompileReflector] },
238 { provide: NgModuleResolver, deps: [CompileReflector] },
239];
240var COMPILER_PROVIDERS__POST_R3__ = [{ provide: Compiler, useFactory: function () { return new Compiler(); } }];
241var COMPILER_PROVIDERS = COMPILER_PROVIDERS__PRE_R3__;
242/**
243 * @publicApi
244 */
245var JitCompilerFactory = /** @class */ (function () {
246 /* @internal */
247 function JitCompilerFactory(defaultOptions) {
248 var compilerOptions = {
249 useJit: true,
250 defaultEncapsulation: ViewEncapsulation.Emulated,
251 missingTranslation: MissingTranslationStrategy.Warning,
252 };
253 this._defaultOptions = __spread([compilerOptions], defaultOptions);
254 }
255 JitCompilerFactory.prototype.createCompiler = function (options) {
256 if (options === void 0) { options = []; }
257 var opts = _mergeOptions(this._defaultOptions.concat(options));
258 var injector = Injector.create([
259 COMPILER_PROVIDERS, {
260 provide: CompilerConfig,
261 useFactory: function () {
262 return new CompilerConfig({
263 // let explicit values from the compiler options overwrite options
264 // from the app providers
265 useJit: opts.useJit,
266 jitDevMode: isDevMode(),
267 // let explicit values from the compiler options overwrite options
268 // from the app providers
269 defaultEncapsulation: opts.defaultEncapsulation,
270 missingTranslation: opts.missingTranslation,
271 preserveWhitespaces: opts.preserveWhitespaces,
272 });
273 },
274 deps: []
275 },
276 opts.providers
277 ]);
278 return injector.get(Compiler);
279 };
280 return JitCompilerFactory;
281}());
282function _mergeOptions(optionsArr) {
283 return {
284 useJit: _lastDefined(optionsArr.map(function (options) { return options.useJit; })),
285 defaultEncapsulation: _lastDefined(optionsArr.map(function (options) { return options.defaultEncapsulation; })),
286 providers: _mergeArrays(optionsArr.map(function (options) { return options.providers; })),
287 missingTranslation: _lastDefined(optionsArr.map(function (options) { return options.missingTranslation; })),
288 preserveWhitespaces: _lastDefined(optionsArr.map(function (options) { return options.preserveWhitespaces; })),
289 };
290}
291function _lastDefined(args) {
292 for (var i = args.length - 1; i >= 0; i--) {
293 if (args[i] !== undefined) {
294 return args[i];
295 }
296 }
297 return undefined;
298}
299function _mergeArrays(parts) {
300 var result = [];
301 parts.forEach(function (part) { return part && result.push.apply(result, __spread(part)); });
302 return result;
303}
304
305/**
306 * @license
307 * Copyright Google Inc. All Rights Reserved.
308 *
309 * Use of this source code is governed by an MIT-style license that can be
310 * found in the LICENSE file at https://angular.io/license
311 */
312var ɵ0$1 = {};
313/**
314 * A platform that included corePlatform and the compiler.
315 *
316 * @publicApi
317 */
318var platformCoreDynamic = createPlatformFactory(platformCore, 'coreDynamic', [
319 { provide: COMPILER_OPTIONS, useValue: ɵ0$1, multi: true },
320 { provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS] },
321]);
322
323var ResourceLoaderImpl = /** @class */ (function (_super) {
324 __extends(ResourceLoaderImpl, _super);
325 function ResourceLoaderImpl() {
326 return _super !== null && _super.apply(this, arguments) || this;
327 }
328 ResourceLoaderImpl.prototype.get = function (url) {
329 var resolve;
330 var reject;
331 var promise = new Promise(function (res, rej) {
332 resolve = res;
333 reject = rej;
334 });
335 var xhr = new XMLHttpRequest();
336 xhr.open('GET', url, true);
337 xhr.responseType = 'text';
338 xhr.onload = function () {
339 // responseText is the old-school way of retrieving response (supported by IE8 & 9)
340 // response/responseType properties were introduced in ResourceLoader Level2 spec (supported
341 // by IE10)
342 var response = xhr.response || xhr.responseText;
343 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
344 var status = xhr.status === 1223 ? 204 : xhr.status;
345 // fix status code when it is 0 (0 status is undocumented).
346 // Occurs when accessing file resources or on Android 4.1 stock browser
347 // while retrieving files from application cache.
348 if (status === 0) {
349 status = response ? 200 : 0;
350 }
351 if (200 <= status && status <= 300) {
352 resolve(response);
353 }
354 else {
355 reject("Failed to load " + url);
356 }
357 };
358 xhr.onerror = function () { reject("Failed to load " + url); };
359 xhr.send();
360 return promise;
361 };
362 ResourceLoaderImpl = __decorate([
363 Injectable()
364 ], ResourceLoaderImpl);
365 return ResourceLoaderImpl;
366}(ResourceLoader));
367
368/**
369 * @license
370 * Copyright Google Inc. All Rights Reserved.
371 *
372 * Use of this source code is governed by an MIT-style license that can be
373 * found in the LICENSE file at https://angular.io/license
374 */
375var ɵ0$2 = { providers: [{ provide: ResourceLoader, useClass: ResourceLoaderImpl, deps: [] }] }, ɵ1$1 = ɵPLATFORM_BROWSER_ID;
376/**
377 * @publicApi
378 */
379var INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS = [
380 ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS,
381 {
382 provide: COMPILER_OPTIONS,
383 useValue: ɵ0$2,
384 multi: true
385 },
386 { provide: PLATFORM_ID, useValue: ɵ1$1 },
387];
388
389/**
390 * @license
391 * Copyright Google Inc. All Rights Reserved.
392 *
393 * Use of this source code is governed by an MIT-style license that can be
394 * found in the LICENSE file at https://angular.io/license
395 */
396/**
397 * An implementation of ResourceLoader that uses a template cache to avoid doing an actual
398 * ResourceLoader.
399 *
400 * The template cache needs to be built and loaded into window.$templateCache
401 * via a separate mechanism.
402 *
403 * @publicApi
404 */
405var CachedResourceLoader = /** @class */ (function (_super) {
406 __extends(CachedResourceLoader, _super);
407 function CachedResourceLoader() {
408 var _this = _super.call(this) || this;
409 _this._cache = ɵglobal.$templateCache;
410 if (_this._cache == null) {
411 throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
412 }
413 return _this;
414 }
415 CachedResourceLoader.prototype.get = function (url) {
416 if (this._cache.hasOwnProperty(url)) {
417 return Promise.resolve(this._cache[url]);
418 }
419 else {
420 return Promise.reject('CachedResourceLoader: Did not find cached template for ' + url);
421 }
422 };
423 return CachedResourceLoader;
424}(ResourceLoader));
425
426/**
427 * @license
428 * Copyright Google Inc. All Rights Reserved.
429 *
430 * Use of this source code is governed by an MIT-style license that can be
431 * found in the LICENSE file at https://angular.io/license
432 */
433
434/**
435 * @license
436 * Copyright Google Inc. All Rights Reserved.
437 *
438 * Use of this source code is governed by an MIT-style license that can be
439 * found in the LICENSE file at https://angular.io/license
440 */
441/**
442 * @publicApi
443 */
444var VERSION = new Version('9.0.6');
445
446/**
447 * @license
448 * Copyright Google Inc. All Rights Reserved.
449 *
450 * Use of this source code is governed by an MIT-style license that can be
451 * found in the LICENSE file at https://angular.io/license
452 */
453/**
454 * @publicApi
455 */
456var RESOURCE_CACHE_PROVIDER = [{ provide: ResourceLoader, useClass: CachedResourceLoader, deps: [] }];
457/**
458 * @publicApi
459 */
460var platformBrowserDynamic = createPlatformFactory(platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
461
462/**
463 * @license
464 * Copyright Google Inc. All Rights Reserved.
465 *
466 * Use of this source code is governed by an MIT-style license that can be
467 * found in the LICENSE file at https://angular.io/license
468 */
469// This file only reexports content of the `src` folder. Keep it that way.
470
471/**
472 * @license
473 * Copyright Google Inc. All Rights Reserved.
474 *
475 * Use of this source code is governed by an MIT-style license that can be
476 * found in the LICENSE file at https://angular.io/license
477 */
478
479/**
480 * Generated bundle index. Do not edit.
481 */
482
483export { JitCompilerFactory, RESOURCE_CACHE_PROVIDER, VERSION, platformBrowserDynamic, COMPILER_PROVIDERS__POST_R3__ as ɵCOMPILER_PROVIDERS__POST_R3__, CompilerImpl as ɵCompilerImpl, INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ResourceLoaderImpl as ɵResourceLoaderImpl, CachedResourceLoader as ɵangular_packages_platform_browser_dynamic_platform_browser_dynamic_a, platformCoreDynamic as ɵplatformCoreDynamic };
484//# sourceMappingURL=platform-browser-dynamic.js.map