Question presented to candidate: "Take a small component with an interpolation, a click handler, an @if and an @for. What does the Angular compiler turn it into, how does the runtime use that output to render and update the DOM, and why did Ivy make libraries and tree-shaking work better than before?"
What a strong answer should cover:
- The compiler adds static definitions to each class:
ɵfac(a factory) andɵcmp(viaɵɵdefineComponent) with selectors, inputs,decls,vars,constsand a template function. - The template function takes
(rf, ctx): the create pass (rf & 1) builds DOM once with instructions likeɵɵelementStart,ɵɵtext,ɵɵlistener; the update pass (rf & 2) re-evaluates bindings withɵɵadvance,ɵɵtextInterpolate,ɵɵproperty. - Control flow compiles into separate embedded view template functions plus
ɵɵconditionalCreate/ɵɵrepeaterCreate. - Locality: each component is compiled from its own metadata plus the type-level declarations of its dependencies, so compilation is per file and incremental.
- Tree-shaking: instructions are plain functions imported from
@angular/core; unused features are never imported. - Libraries ship partial declarations (
ɵɵngDeclareComponent) that the linker turns into final definitions in the app build.
Clarifying questions expected:
- "Do you want the compiler side, the runtime side, or both?"
- "Should I compare with View Engine?"
Code / implementation expected: Optional — a small component and its real compiled output.