The ReflectionHost supports enumeration of constructor parameters, and one piece of information it returns describes the origin of the parameter's type. Parameter types come in two flavors: local (the type is not imported from anywhere) or non-local (the type comes via an import). ngcc incorrectly classified all type parameters as 'local', because in the source files that ngcc processes the type parameter is a real ts.Identifer. However, that identifier may still have come from an import and thus might be non-local. This commit changes ngcc's ReflectionHost(s) to properly recognize and report these non-local type references. Fixes #33677 PR Close #33901
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 
 | |
| /**
 | |
|  * @license
 | |
|  * Copyright Google Inc. All Rights Reserved.
 | |
|  *
 | |
|  * Use of this source code is governed by an MIT-style license that can be
 | |
|  * found in the LICENSE file at https://angular.io/license
 | |
|  */
 | |
| import * as ts from 'typescript';
 | |
| import {CtorParameter} from '../../../src/ngtsc/reflection';
 | |
| 
 | |
| /**
 | |
|  * Check that a given list of `CtorParameter`s has `typeValueReference`s of specific `ts.Identifier`
 | |
|  * names.
 | |
|  */
 | |
| export function expectTypeValueReferencesForParameters(
 | |
|     parameters: CtorParameter[], expectedParams: (string | null)[],
 | |
|     fromModule: string | null = null) {
 | |
|   parameters !.forEach((param, idx) => {
 | |
|     const expected = expectedParams[idx];
 | |
|     if (expected !== null) {
 | |
|       if (param.typeValueReference === null) {
 | |
|         fail(`Incorrect typeValueReference generated, expected ${expected}`);
 | |
|       } else if (param.typeValueReference.local && fromModule !== null) {
 | |
|         fail(`Incorrect typeValueReference generated, expected non-local`);
 | |
|       } else if (!param.typeValueReference.local && fromModule === null) {
 | |
|         fail(`Incorrect typeValueReference generated, expected local`);
 | |
|       } else if (param.typeValueReference.local) {
 | |
|         if (!ts.isIdentifier(param.typeValueReference.expression)) {
 | |
|           fail(`Incorrect typeValueReference generated, expected identifer`);
 | |
|         } else {
 | |
|           expect(param.typeValueReference.expression.text).toEqual(expected);
 | |
|         }
 | |
|       } else if (param.typeValueReference !== null) {
 | |
|         expect(param.typeValueReference.moduleName).toBe(fromModule !);
 | |
|         expect(param.typeValueReference.name).toBe(expected);
 | |
|       }
 | |
|     }
 | |
|   });
 | |
| }
 |