Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixup! refactor(compiler-cli): use TypeScript transform to emit type …
…parameters
  • Loading branch information
JoostK committed Jun 19, 2021
1 parent 047050e commit 3198d76
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/compiler-cli/src/ngtsc/typecheck/src/type_emitter.ts
Expand Up @@ -24,7 +24,10 @@ export type TypeReferenceResolver = (type: ts.TypeReferenceNode) => ResolvedType
* A marker to indicate that a type reference is ineligible for emitting. This needs to be truthy
* as it's returned from `ts.forEachChild`, which only returns truthy values.
*/
const INELIGIBLE = {};
type INELIGIBLE = {
__brand: 'ineligible';
};
const INELIGIBLE: INELIGIBLE = {} as INELIGIBLE;

/**
* Determines whether the provided type can be emitted, which means that it can be safely emitted
Expand All @@ -41,7 +44,16 @@ export function canEmitType(type: ts.TypeNode, resolver: TypeReferenceResolver):
return visitNode(type) !== INELIGIBLE;
}

function visitNode(node: ts.Node): typeof INELIGIBLE|undefined {
// To determine whether a type can be emitted, we have to recursively look through all type nodes.
// If a type reference node is found at any position within the type and that type reference
// cannot be emitted, then the `INELIGIBLE` constant is returned to stop the recursive walk as
// the type as a whole cannot be emitted in that case. Otherwise, the result of visiting all child
// nodes determines the result. If no ineligible type reference node is found then the walk
// returns `undefined`, indicating that no type node was visited that could not be emitted.
function visitNode(node: ts.Node): INELIGIBLE|undefined {
// Emitting a type reference node in a different context requires that an import for the type
// can be created. If a type reference node cannot be emitted, `INELIGIBLE` is returned to stop
// the walk.
if (ts.isTypeReferenceNode(node) && !canEmitTypeReference(node)) {
return INELIGIBLE;
} else {
Expand Down

0 comments on commit 3198d76

Please sign in to comment.