|
| 1 | +import { CompileReflector, ExternalReference, Identifiers, getUrlScheme, syntaxError } from '@angular/compiler'; |
| 2 | +import { |
| 3 | + ANALYZE_FOR_ENTRY_COMPONENTS, |
| 4 | + ChangeDetectionStrategy, |
| 5 | + ChangeDetectorRef, |
| 6 | + Component, |
| 7 | + ComponentFactory, |
| 8 | + ComponentFactoryResolver, |
| 9 | + ComponentRef, |
| 10 | + ElementRef, |
| 11 | + Injector, |
| 12 | + LOCALE_ID, |
| 13 | + NgModuleFactory, |
| 14 | + NgModuleRef, |
| 15 | + QueryList, |
| 16 | + Renderer, |
| 17 | + SecurityContext, |
| 18 | + TRANSLATIONS_FORMAT, |
| 19 | + TemplateRef, |
| 20 | + ViewContainerRef, |
| 21 | + ViewEncapsulation, |
| 22 | + ɵCodegenComponentFactoryResolver, |
| 23 | + ɵEMPTY_ARRAY, |
| 24 | + ɵEMPTY_MAP, |
| 25 | + ɵReflectionCapabilities as ReflectionCapabilities, |
| 26 | + ɵand, |
| 27 | + ɵccf, |
| 28 | + ɵcmf, |
| 29 | + ɵcrt, |
| 30 | + ɵdid, |
| 31 | + ɵeld, |
| 32 | + ɵinlineInterpolate, |
| 33 | + ɵinterpolate, |
| 34 | + ɵmod, |
| 35 | + ɵmpd, |
| 36 | + ɵncd, |
| 37 | + ɵnov, |
| 38 | + ɵpad, |
| 39 | + ɵpid, |
| 40 | + ɵpod, |
| 41 | + ɵppd, |
| 42 | + ɵprd, |
| 43 | + ɵqud, |
| 44 | + ɵregisterModuleFactory, |
| 45 | + ɵstringify as stringify, |
| 46 | + ɵted, |
| 47 | + ɵunv, |
| 48 | + ɵvid |
| 49 | +} from '@angular/core'; |
| 50 | + |
| 51 | +export const MODULE_SUFFIX = ''; |
| 52 | +const builtinExternalReferences = createBuiltinExternalReferencesMap(); |
| 53 | + |
| 54 | +export class JitReflector implements CompileReflector { |
| 55 | + private reflectionCapabilities: ReflectionCapabilities; |
| 56 | + private builtinExternalReferences = new Map<ExternalReference, any>(); |
| 57 | + constructor() { |
| 58 | + this.reflectionCapabilities = new ReflectionCapabilities(); |
| 59 | + } |
| 60 | + componentModuleUrl(type: any, cmpMetadata: Component): string { |
| 61 | + const moduleId = cmpMetadata.moduleId; |
| 62 | + |
| 63 | + if (typeof moduleId === 'string') { |
| 64 | + const scheme = getUrlScheme(moduleId); |
| 65 | + return scheme ? moduleId : `package:${moduleId}${MODULE_SUFFIX}`; |
| 66 | + } else if (moduleId !== null && moduleId !== void 0) { |
| 67 | + throw syntaxError( |
| 68 | + `moduleId should be a string in "${stringify(type)}". See https://goo.gl/wIDDiL for more information.\n` + |
| 69 | + `If you're using Webpack you should inline the template and the styles, see https://goo.gl/X2J8zc.` |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + return `./${stringify(type)}`; |
| 74 | + } |
| 75 | + parameters(typeOrFunc: /*Type*/ any): any[][] { |
| 76 | + return this.reflectionCapabilities.parameters(typeOrFunc); |
| 77 | + } |
| 78 | + annotations(typeOrFunc: /*Type*/ any): any[] { |
| 79 | + return this.reflectionCapabilities.annotations(typeOrFunc); |
| 80 | + } |
| 81 | + propMetadata(typeOrFunc: /*Type*/ any): { [key: string]: any[] } { |
| 82 | + return this.reflectionCapabilities.propMetadata(typeOrFunc); |
| 83 | + } |
| 84 | + hasLifecycleHook(type: any, lcProperty: string): boolean { |
| 85 | + return this.reflectionCapabilities.hasLifecycleHook(type, lcProperty); |
| 86 | + } |
| 87 | + resolveExternalReference(ref: ExternalReference): any { |
| 88 | + return builtinExternalReferences.get(ref) || ref.runtime; |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +function createBuiltinExternalReferencesMap() { |
| 93 | + const map = new Map<ExternalReference, any>(); |
| 94 | + map.set(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS, ANALYZE_FOR_ENTRY_COMPONENTS); |
| 95 | + map.set(Identifiers.ElementRef, ElementRef); |
| 96 | + map.set(Identifiers.NgModuleRef, NgModuleRef); |
| 97 | + map.set(Identifiers.ViewContainerRef, ViewContainerRef); |
| 98 | + map.set(Identifiers.ChangeDetectorRef, ChangeDetectorRef); |
| 99 | + map.set(Identifiers.QueryList, QueryList); |
| 100 | + map.set(Identifiers.TemplateRef, TemplateRef); |
| 101 | + map.set(Identifiers.CodegenComponentFactoryResolver, ɵCodegenComponentFactoryResolver); |
| 102 | + map.set(Identifiers.ComponentFactoryResolver, ComponentFactoryResolver); |
| 103 | + map.set(Identifiers.ComponentFactory, ComponentFactory); |
| 104 | + map.set(Identifiers.ComponentRef, ComponentRef); |
| 105 | + map.set(Identifiers.NgModuleFactory, NgModuleFactory); |
| 106 | + map.set(Identifiers.createModuleFactory, ɵcmf); |
| 107 | + map.set(Identifiers.moduleDef, ɵmod); |
| 108 | + map.set(Identifiers.moduleProviderDef, ɵmpd); |
| 109 | + map.set(Identifiers.RegisterModuleFactoryFn, ɵregisterModuleFactory); |
| 110 | + map.set(Identifiers.Injector, Injector); |
| 111 | + map.set(Identifiers.ViewEncapsulation, ViewEncapsulation); |
| 112 | + map.set(Identifiers.ChangeDetectionStrategy, ChangeDetectionStrategy); |
| 113 | + map.set(Identifiers.SecurityContext, SecurityContext); |
| 114 | + map.set(Identifiers.LOCALE_ID, LOCALE_ID); |
| 115 | + map.set(Identifiers.TRANSLATIONS_FORMAT, TRANSLATIONS_FORMAT); |
| 116 | + map.set(Identifiers.inlineInterpolate, ɵinlineInterpolate); |
| 117 | + map.set(Identifiers.interpolate, ɵinterpolate); |
| 118 | + map.set(Identifiers.EMPTY_ARRAY, ɵEMPTY_ARRAY); |
| 119 | + map.set(Identifiers.EMPTY_MAP, ɵEMPTY_MAP); |
| 120 | + map.set(Identifiers.Renderer, Renderer); |
| 121 | + map.set(Identifiers.viewDef, ɵvid); |
| 122 | + map.set(Identifiers.elementDef, ɵeld); |
| 123 | + map.set(Identifiers.anchorDef, ɵand); |
| 124 | + map.set(Identifiers.textDef, ɵted); |
| 125 | + map.set(Identifiers.directiveDef, ɵdid); |
| 126 | + map.set(Identifiers.providerDef, ɵprd); |
| 127 | + map.set(Identifiers.queryDef, ɵqud); |
| 128 | + map.set(Identifiers.pureArrayDef, ɵpad); |
| 129 | + map.set(Identifiers.pureObjectDef, ɵpod); |
| 130 | + map.set(Identifiers.purePipeDef, ɵppd); |
| 131 | + map.set(Identifiers.pipeDef, ɵpid); |
| 132 | + map.set(Identifiers.nodeValue, ɵnov); |
| 133 | + map.set(Identifiers.ngContentDef, ɵncd); |
| 134 | + map.set(Identifiers.unwrapValue, ɵunv); |
| 135 | + map.set(Identifiers.createRendererType2, ɵcrt); |
| 136 | + map.set(Identifiers.createComponentFactory, ɵccf); |
| 137 | + return map; |
| 138 | +} |
0 commit comments