Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/oxc_angular_compiler/src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,8 @@ fn build_queries(
/// - `hostDirectives: [...]` → `ns.ɵɵHostDirectivesFeature([...])`
/// - `usesInheritance: true` → `ns.ɵɵInheritDefinitionFeature`
/// - `usesOnChanges: true` → `ns.ɵɵNgOnChangesFeature`
/// Order is important: ProvidersFeature → HostDirectivesFeature → InheritDefinitionFeature → NgOnChangesFeature
/// - `controlCreate: { passThroughInput }` → `ns.ɵɵControlFeature(passThroughInput)`
/// Order is important: ProvidersFeature → HostDirectivesFeature → InheritDefinitionFeature → NgOnChangesFeature → ControlFeature
/// (see packages/compiler/src/render3/view/compiler.ts:119-161)
fn build_features(meta: &ObjectExpression<'_>, source: &str, ns: &str) -> Option<String> {
let mut features: Vec<String> = Vec::new();
Expand Down Expand Up @@ -1666,6 +1667,17 @@ fn build_features(meta: &ObjectExpression<'_>, source: &str, ns: &str) -> Option
features.push(format!("{ns}.\u{0275}\u{0275}NgOnChangesFeature"));
}

// 5. ControlFeature — for signal form directives declaring controlCreate
// `controlCreate: { passThroughInput: "formField" | null }`
// emits `ɵɵControlFeature("formField")` or `ɵɵControlFeature(null)`
if let Some(control_create) = get_object_property(meta, "controlCreate") {
let pass_through = match get_string_property(control_create, "passThroughInput") {
Some(s) => format!("\"{s}\""),
None => "null".to_string(),
};
features.push(format!("{ns}.\u{0275}\u{0275}ControlFeature({pass_through})"));
}

if features.is_empty() { None } else { Some(format!("[{}]", features.join(", "))) }
}

Expand Down
26 changes: 26 additions & 0 deletions crates/oxc_angular_compiler/tests/linker_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ fn test_link_inputs_array_format_with_transform_function() {
let result = link(&allocator, &code, "test.mjs");
insta::assert_snapshot!(result.code);
}

/// Regression: signal form FormField directive declares
/// `controlCreate: { passThroughInput: "formField" }` in its partial metadata.
/// The linker must emit `ɵɵControlFeature("formField")` in the features array,
/// otherwise `DirectiveDef.controlDef` is never set and the runtime
/// `ɵɵcontrolCreate()` / `ɵɵcontrol()` instructions become no-ops.
/// See voidzero-dev/oxc-angular-compiler#229.
#[test]
fn test_link_control_feature_pass_through_input() {
let allocator = Allocator::default();
let code = r#"import * as i0 from "@angular/core";
export class FormField {}
FormField.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.8", type: FormField, selector: "[formField]", inputs: { field: { classPropertyName: "field", publicName: "formField", isRequired: true, isSignal: true } }, controlCreate: { passThroughInput: "formField" }, isStandalone: true, isSignal: true });"#;
let result = link(&allocator, code, "test.mjs");
insta::assert_snapshot!(result.code);
}

#[test]
fn test_link_control_feature_null_pass_through_input() {
let allocator = Allocator::default();
let code = r#"import * as i0 from "@angular/core";
export class MyControl {}
MyControl.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.8", type: MyControl, selector: "[myControl]", controlCreate: { passThroughInput: null }, isStandalone: true, isSignal: true });"#;
let result = link(&allocator, code, "test.mjs");
insta::assert_snapshot!(result.code);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: crates/oxc_angular_compiler/tests/linker_test.rs
expression: result.code
---
import * as i0 from "@angular/core";
export class MyControl {}
MyControl.ɵdir = i0.ɵɵdefineDirective({ type: MyControl, selectors: [["", "myControl", ""]], signals: true, features: [i0.ɵɵControlFeature(null)] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: crates/oxc_angular_compiler/tests/linker_test.rs
expression: result.code
---
import * as i0 from "@angular/core";
export class FormField {}
FormField.ɵdir = i0.ɵɵdefineDirective({ type: FormField, selectors: [["", "formField", ""]], inputs: { field: [1, "formField", "field"] }, signals: true, features: [i0.ɵɵControlFeature("formField")] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Fixture } from '../types.js'

export const fixtures: Fixture[] = [
{
name: 'formfield-alias-repro',
category: 'regressions',
description: 'Issue #229 repro: [formField] binding with aliased field input',
className: 'AppComponent',
type: 'full-transform',
sourceCode: `
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { form, FormField, required } from '@angular/forms/signals';

@Component({
selector: 'app-root',
imports: [FormField],
template: \`<input type="text" [formField]="myForm.firstName" />\`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
protected readonly myFormModel = signal({
firstName: 'Foo',
email: 'foo@bar.com',
});
protected readonly myForm = form(this.myFormModel, path => {
required(path.firstName);
});
}
`.trim(),
expectedFeatures: ['ɵɵproperty', 'ɵɵcontrol', 'ɵɵcontrolCreate'],
},
]
Loading