(type: Type<any>, metadata: Component)
| 68 | * until the global queue has been resolved with a call to `resolveComponentResources`. |
| 69 | */ |
| 70 | export function compileComponent(type: Type<any>, metadata: Component): void { |
| 71 | // Initialize ngDevMode. This must be the first statement in compileComponent. |
| 72 | // See the `initNgDevMode` docstring for more information. |
| 73 | (typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode(); |
| 74 | |
| 75 | let ngComponentDef: ComponentDef<unknown> | null = null; |
| 76 | |
| 77 | // Metadata may have resources which need to be resolved. |
| 78 | maybeQueueResolutionOfComponentResources(type, metadata); |
| 79 | |
| 80 | // Note that we're using the same function as `Directive`, because that's only subset of metadata |
| 81 | // that we need to create the ngFactoryDef. We're avoiding using the component metadata |
| 82 | // because we'd have to resolve the asynchronous templates. |
| 83 | addDirectiveFactoryDef(type, metadata); |
| 84 | |
| 85 | Object.defineProperty(type, NG_COMP_DEF, { |
| 86 | get: () => { |
| 87 | if (ngComponentDef === null) { |
| 88 | const compiler = getCompilerFacade({ |
| 89 | usage: JitCompilerUsage.Decorator, |
| 90 | kind: 'component', |
| 91 | type: type, |
| 92 | }); |
| 93 | |
| 94 | if (componentNeedsResolution(metadata)) { |
| 95 | const error = [`Component '${type.name}' is not resolved:`]; |
| 96 | if (metadata.templateUrl) { |
| 97 | error.push(` - templateUrl: ${metadata.templateUrl}`); |
| 98 | } |
| 99 | if (metadata.styleUrls && metadata.styleUrls.length) { |
| 100 | error.push(` - styleUrls: ${JSON.stringify(metadata.styleUrls)}`); |
| 101 | } |
| 102 | if (metadata.styleUrl) { |
| 103 | error.push(` - styleUrl: ${metadata.styleUrl}`); |
| 104 | } |
| 105 | error.push(`Did you run and wait for 'resolveComponentResources()'?`); |
| 106 | throw new Error(error.join('\n')); |
| 107 | } |
| 108 | |
| 109 | // This const was called `jitOptions` previously but had to be renamed to `options` because |
| 110 | // of a bug with Terser that caused optimized JIT builds to throw a `ReferenceError`. |
| 111 | // This bug was investigated in https://github.com/angular/angular-cli/issues/17264. |
| 112 | // We should not rename it back until https://github.com/terser/terser/issues/615 is fixed. |
| 113 | const options = getJitOptions(); |
| 114 | let preserveWhitespaces = metadata.preserveWhitespaces; |
| 115 | if (preserveWhitespaces === undefined) { |
| 116 | if (options !== null && options.preserveWhitespaces !== undefined) { |
| 117 | preserveWhitespaces = options.preserveWhitespaces; |
| 118 | } else { |
| 119 | preserveWhitespaces = false; |
| 120 | } |
| 121 | } |
| 122 | let encapsulation = metadata.encapsulation; |
| 123 | if (encapsulation === undefined) { |
| 124 | if (options !== null && options.defaultEncapsulation !== undefined) { |
| 125 | encapsulation = options.defaultEncapsulation; |
| 126 | } else { |
| 127 | encapsulation = ViewEncapsulation.Emulated; |
no test coverage detected
searching dependent graphs…