UNPKG

21.1 kBJavaScriptView Raw
1/**
2 * @license Angular v8.2.9
3 * (c) 2010-2019 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { getUrlScheme, syntaxError, Identifiers, JitCompiler, ProviderMeta, CompileReflector, ResourceLoader, JitSummaryResolver, SummaryResolver, Lexer, Parser, HtmlParser, I18NHtmlParser, CompilerConfig, 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, Renderer, ɵvid, ɵeld, ɵand, ɵted, ɵdid, ɵprd, ɵqud, ɵpad, ɵpod, ɵppd, ɵpid, ɵnov, ɵncd, ɵunv, ɵcrt, ɵccf, InjectionToken, PACKAGE_ROOT_URL, Compiler, ɵConsole, MissingTranslationStrategy, 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.Renderer, Renderer);
90 map.set(Identifiers.viewDef, ɵvid);
91 map.set(Identifiers.elementDef, ɵeld);
92 map.set(Identifiers.anchorDef, ɵand);
93 map.set(Identifiers.textDef, ɵted);
94 map.set(Identifiers.directiveDef, ɵdid);
95 map.set(Identifiers.providerDef, ɵprd);
96 map.set(Identifiers.queryDef, ɵqud);
97 map.set(Identifiers.pureArrayDef, ɵpad);
98 map.set(Identifiers.pureObjectDef, ɵpod);
99 map.set(Identifiers.purePipeDef, ɵppd);
100 map.set(Identifiers.pipeDef, ɵpid);
101 map.set(Identifiers.nodeValue, ɵnov);
102 map.set(Identifiers.ngContentDef, ɵncd);
103 map.set(Identifiers.unwrapValue, ɵunv);
104 map.set(Identifiers.createRendererType2, ɵcrt);
105 map.set(Identifiers.createComponentFactory, ɵccf);
106 return map;
107}
108
109/**
110 * @license
111 * Copyright Google Inc. All Rights Reserved.
112 *
113 * Use of this source code is governed by an MIT-style license that can be
114 * found in the LICENSE file at https://angular.io/license
115 */
116var ERROR_COLLECTOR_TOKEN = new InjectionToken('ErrorCollector');
117/**
118 * A default provider for {@link PACKAGE_ROOT_URL} that maps to '/'.
119 */
120var DEFAULT_PACKAGE_URL_PROVIDER = {
121 provide: PACKAGE_ROOT_URL,
122 useValue: '/'
123};
124var _NO_RESOURCE_LOADER = {
125 get: function (url) {
126 throw new Error("No ResourceLoader implementation has been provided. Can't read the url \"" + url + "\"");
127 }
128};
129var baseHtmlParser = new InjectionToken('HtmlParser');
130var CompilerImpl = /** @class */ (function () {
131 function CompilerImpl(injector, _metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler, summaryResolver, compileReflector, jitEvaluator, compilerConfig, console) {
132 this._metadataResolver = _metadataResolver;
133 this._delegate = new JitCompiler(_metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler, summaryResolver, compileReflector, jitEvaluator, compilerConfig, console, this.getExtraNgModuleProviders.bind(this));
134 this.injector = injector;
135 }
136 CompilerImpl.prototype.getExtraNgModuleProviders = function () {
137 return [this._metadataResolver.getProviderMetadata(new ProviderMeta(Compiler, { useValue: this }))];
138 };
139 CompilerImpl.prototype.compileModuleSync = function (moduleType) {
140 return this._delegate.compileModuleSync(moduleType);
141 };
142 CompilerImpl.prototype.compileModuleAsync = function (moduleType) {
143 return this._delegate.compileModuleAsync(moduleType);
144 };
145 CompilerImpl.prototype.compileModuleAndAllComponentsSync = function (moduleType) {
146 var result = this._delegate.compileModuleAndAllComponentsSync(moduleType);
147 return {
148 ngModuleFactory: result.ngModuleFactory,
149 componentFactories: result.componentFactories,
150 };
151 };
152 CompilerImpl.prototype.compileModuleAndAllComponentsAsync = function (moduleType) {
153 return this._delegate.compileModuleAndAllComponentsAsync(moduleType)
154 .then(function (result) { return ({
155 ngModuleFactory: result.ngModuleFactory,
156 componentFactories: result.componentFactories,
157 }); });
158 };
159 CompilerImpl.prototype.loadAotSummaries = function (summaries) { this._delegate.loadAotSummaries(summaries); };
160 CompilerImpl.prototype.hasAotSummary = function (ref) { return this._delegate.hasAotSummary(ref); };
161 CompilerImpl.prototype.getComponentFactory = function (component) {
162 return this._delegate.getComponentFactory(component);
163 };
164 CompilerImpl.prototype.clearCache = function () { this._delegate.clearCache(); };
165 CompilerImpl.prototype.clearCacheFor = function (type) { this._delegate.clearCacheFor(type); };
166 CompilerImpl.prototype.getModuleId = function (moduleType) {
167 var meta = this._metadataResolver.getNgModuleMetadata(moduleType);
168 return meta && meta.id || undefined;
169 };
170 return CompilerImpl;
171}());
172/**
173 * A set of providers that provide `JitCompiler` and its dependencies to use for
174 * template compilation.
175 */
176var COMPILER_PROVIDERS = [
177 { provide: CompileReflector, useValue: new JitReflector() },
178 { provide: ResourceLoader, useValue: _NO_RESOURCE_LOADER },
179 { provide: JitSummaryResolver, deps: [] },
180 { provide: SummaryResolver, useExisting: JitSummaryResolver },
181 { provide: ɵConsole, deps: [] },
182 { provide: Lexer, deps: [] },
183 { provide: Parser, deps: [Lexer] },
184 {
185 provide: baseHtmlParser,
186 useClass: HtmlParser,
187 deps: [],
188 },
189 {
190 provide: I18NHtmlParser,
191 useFactory: function (parser, translations, format, config, console) {
192 translations = translations || '';
193 var missingTranslation = translations ? config.missingTranslation : MissingTranslationStrategy.Ignore;
194 return new I18NHtmlParser(parser, translations, format, missingTranslation, console);
195 },
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: new CompilerConfig() },
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];
240/**
241 * @publicApi
242 */
243var JitCompilerFactory = /** @class */ (function () {
244 /* @internal */
245 function JitCompilerFactory(defaultOptions) {
246 var compilerOptions = {
247 useJit: true,
248 defaultEncapsulation: ViewEncapsulation.Emulated,
249 missingTranslation: MissingTranslationStrategy.Warning,
250 };
251 this._defaultOptions = __spread([compilerOptions], defaultOptions);
252 }
253 JitCompilerFactory.prototype.createCompiler = function (options) {
254 if (options === void 0) { options = []; }
255 var opts = _mergeOptions(this._defaultOptions.concat(options));
256 var injector = Injector.create([
257 COMPILER_PROVIDERS, {
258 provide: CompilerConfig,
259 useFactory: function () {
260 return new CompilerConfig({
261 // let explicit values from the compiler options overwrite options
262 // from the app providers
263 useJit: opts.useJit,
264 jitDevMode: isDevMode(),
265 // let explicit values from the compiler options overwrite options
266 // from the app providers
267 defaultEncapsulation: opts.defaultEncapsulation,
268 missingTranslation: opts.missingTranslation,
269 preserveWhitespaces: opts.preserveWhitespaces,
270 });
271 },
272 deps: []
273 },
274 opts.providers
275 ]);
276 return injector.get(Compiler);
277 };
278 return JitCompilerFactory;
279}());
280function _mergeOptions(optionsArr) {
281 return {
282 useJit: _lastDefined(optionsArr.map(function (options) { return options.useJit; })),
283 defaultEncapsulation: _lastDefined(optionsArr.map(function (options) { return options.defaultEncapsulation; })),
284 providers: _mergeArrays(optionsArr.map(function (options) { return options.providers; })),
285 missingTranslation: _lastDefined(optionsArr.map(function (options) { return options.missingTranslation; })),
286 preserveWhitespaces: _lastDefined(optionsArr.map(function (options) { return options.preserveWhitespaces; })),
287 };
288}
289function _lastDefined(args) {
290 for (var i = args.length - 1; i >= 0; i--) {
291 if (args[i] !== undefined) {
292 return args[i];
293 }
294 }
295 return undefined;
296}
297function _mergeArrays(parts) {
298 var result = [];
299 parts.forEach(function (part) { return part && result.push.apply(result, __spread(part)); });
300 return result;
301}
302
303/**
304 * @license
305 * Copyright Google Inc. All Rights Reserved.
306 *
307 * Use of this source code is governed by an MIT-style license that can be
308 * found in the LICENSE file at https://angular.io/license
309 */
310var ɵ0 = {};
311/**
312 * A platform that included corePlatform and the compiler.
313 *
314 * @publicApi
315 */
316var platformCoreDynamic = createPlatformFactory(platformCore, 'coreDynamic', [
317 { provide: COMPILER_OPTIONS, useValue: ɵ0, multi: true },
318 { provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS] },
319]);
320
321var ResourceLoaderImpl = /** @class */ (function (_super) {
322 __extends(ResourceLoaderImpl, _super);
323 function ResourceLoaderImpl() {
324 return _super !== null && _super.apply(this, arguments) || this;
325 }
326 ResourceLoaderImpl.prototype.get = function (url) {
327 var resolve;
328 var reject;
329 var promise = new Promise(function (res, rej) {
330 resolve = res;
331 reject = rej;
332 });
333 var xhr = new XMLHttpRequest();
334 xhr.open('GET', url, true);
335 xhr.responseType = 'text';
336 xhr.onload = function () {
337 // responseText is the old-school way of retrieving response (supported by IE8 & 9)
338 // response/responseType properties were introduced in ResourceLoader Level2 spec (supported
339 // by IE10)
340 var response = xhr.response || xhr.responseText;
341 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
342 var status = xhr.status === 1223 ? 204 : xhr.status;
343 // fix status code when it is 0 (0 status is undocumented).
344 // Occurs when accessing file resources or on Android 4.1 stock browser
345 // while retrieving files from application cache.
346 if (status === 0) {
347 status = response ? 200 : 0;
348 }
349 if (200 <= status && status <= 300) {
350 resolve(response);
351 }
352 else {
353 reject("Failed to load " + url);
354 }
355 };
356 xhr.onerror = function () { reject("Failed to load " + url); };
357 xhr.send();
358 return promise;
359 };
360 ResourceLoaderImpl = __decorate([
361 Injectable()
362 ], ResourceLoaderImpl);
363 return ResourceLoaderImpl;
364}(ResourceLoader));
365
366/**
367 * @license
368 * Copyright Google Inc. All Rights Reserved.
369 *
370 * Use of this source code is governed by an MIT-style license that can be
371 * found in the LICENSE file at https://angular.io/license
372 */
373var ɵ0$1 = { providers: [{ provide: ResourceLoader, useClass: ResourceLoaderImpl, deps: [] }] }, ɵ1 = ɵPLATFORM_BROWSER_ID;
374/**
375 * @publicApi
376 */
377var INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS = [
378 ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS,
379 {
380 provide: COMPILER_OPTIONS,
381 useValue: ɵ0$1,
382 multi: true
383 },
384 { provide: PLATFORM_ID, useValue: ɵ1 },
385];
386
387/**
388 * @license
389 * Copyright Google Inc. All Rights Reserved.
390 *
391 * Use of this source code is governed by an MIT-style license that can be
392 * found in the LICENSE file at https://angular.io/license
393 */
394/**
395 * An implementation of ResourceLoader that uses a template cache to avoid doing an actual
396 * ResourceLoader.
397 *
398 * The template cache needs to be built and loaded into window.$templateCache
399 * via a separate mechanism.
400 *
401 * @publicApi
402 */
403var CachedResourceLoader = /** @class */ (function (_super) {
404 __extends(CachedResourceLoader, _super);
405 function CachedResourceLoader() {
406 var _this = _super.call(this) || this;
407 _this._cache = ɵglobal.$templateCache;
408 if (_this._cache == null) {
409 throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
410 }
411 return _this;
412 }
413 CachedResourceLoader.prototype.get = function (url) {
414 if (this._cache.hasOwnProperty(url)) {
415 return Promise.resolve(this._cache[url]);
416 }
417 else {
418 return Promise.reject('CachedResourceLoader: Did not find cached template for ' + url);
419 }
420 };
421 return CachedResourceLoader;
422}(ResourceLoader));
423
424/**
425 * @license
426 * Copyright Google Inc. All Rights Reserved.
427 *
428 * Use of this source code is governed by an MIT-style license that can be
429 * found in the LICENSE file at https://angular.io/license
430 */
431
432/**
433 * @license
434 * Copyright Google Inc. All Rights Reserved.
435 *
436 * Use of this source code is governed by an MIT-style license that can be
437 * found in the LICENSE file at https://angular.io/license
438 */
439/**
440 * @publicApi
441 */
442var VERSION = new Version('8.2.9');
443
444/**
445 * @license
446 * Copyright Google Inc. All Rights Reserved.
447 *
448 * Use of this source code is governed by an MIT-style license that can be
449 * found in the LICENSE file at https://angular.io/license
450 */
451/**
452 * @publicApi
453 */
454var RESOURCE_CACHE_PROVIDER = [{ provide: ResourceLoader, useClass: CachedResourceLoader, deps: [] }];
455/**
456 * @publicApi
457 */
458var platformBrowserDynamic = createPlatformFactory(platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
459
460/**
461 * @license
462 * Copyright Google Inc. All Rights Reserved.
463 *
464 * Use of this source code is governed by an MIT-style license that can be
465 * found in the LICENSE file at https://angular.io/license
466 */
467// This file only reexports content of the `src` folder. Keep it that way.
468
469/**
470 * @license
471 * Copyright Google Inc. All Rights Reserved.
472 *
473 * Use of this source code is governed by an MIT-style license that can be
474 * found in the LICENSE file at https://angular.io/license
475 */
476
477/**
478 * Generated bundle index. Do not edit.
479 */
480
481export { CachedResourceLoader as ɵangular_packages_platform_browser_dynamic_platform_browser_dynamic_a, RESOURCE_CACHE_PROVIDER, platformBrowserDynamic, VERSION, JitCompilerFactory, CompilerImpl as ɵCompilerImpl, platformCoreDynamic as ɵplatformCoreDynamic, INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, ResourceLoaderImpl as ɵResourceLoaderImpl };
482//# sourceMappingURL=platform-browser-dynamic.js.map