What is folding?

The compiler can only resolve references to exported symbols in the metadata. Where as some of the non-exported members are folded while generating the code. i.e Folding is a process in which the collector evaluate an expression during collection and record the result in the .metadata.json instead of the original expression. For example, the compiler couldn't refer selector reference because it is not exported

let selector = 'app-root';
@Component({
selector: selector
})

Will be folded into inline selector

@Component({
selector: 'app-root'
})

Remember that the compiler can’t fold everything. For example, spread operator on arrays, objects created using new keywords and function calls.


February 18, 2022
257