Skip to content

Commit 61a540b

Browse files
Brooooooklynclaude
andauthored
fix: linker converts providers/usesInheritance/usesOnChanges to features for directives (#76)
The directive linker was passing through a raw `features` property that doesn't exist on partial declarations. Replace with `build_features()` (already used by the component linker) so `providers`, `usesInheritance`, and `usesOnChanges` are correctly converted to their feature equivalents. - Close #66 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3796ddd commit 61a540b

File tree

1 file changed

+88
-1
lines changed
  • crates/oxc_angular_compiler/src/linker

1 file changed

+88
-1
lines changed

crates/oxc_angular_compiler/src/linker/mod.rs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ fn link_directive(
10501050
if let Some(host_directives) = get_property_source(meta, "hostDirectives", source) {
10511051
parts.push(format!("hostDirectives: {host_directives}"));
10521052
}
1053-
if let Some(features) = get_property_source(meta, "features", source) {
1053+
if let Some(features) = build_features(meta, source, ns) {
10541054
parts.push(format!("features: {features}"));
10551055
}
10561056

@@ -2090,4 +2090,91 @@ class EmptyOutletComponent {
20902090
result.code
20912091
);
20922092
}
2093+
2094+
#[test]
2095+
fn test_link_directive_with_providers() {
2096+
let allocator = Allocator::default();
2097+
let code = r#"
2098+
import * as i0 from "@angular/core";
2099+
class BrnTooltipTrigger {
2100+
}
2101+
BrnTooltipTrigger.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", ngImport: i0, type: BrnTooltipTrigger, selector: "[brnTooltipTrigger]", isStandalone: true, providers: [BRN_TOOLTIP_SCROLL_STRATEGY_FACTORY_PROVIDER] });
2102+
"#;
2103+
let result = link(&allocator, code, "test.mjs");
2104+
assert!(result.linked);
2105+
assert!(
2106+
result.code.contains("ProvidersFeature"),
2107+
"Should have ProvidersFeature for directive providers, got:\n{}",
2108+
result.code
2109+
);
2110+
assert!(
2111+
result.code.contains("BRN_TOOLTIP_SCROLL_STRATEGY_FACTORY_PROVIDER"),
2112+
"Should preserve provider reference, got:\n{}",
2113+
result.code
2114+
);
2115+
}
2116+
2117+
#[test]
2118+
fn test_link_directive_with_uses_inheritance() {
2119+
let allocator = Allocator::default();
2120+
let code = r#"
2121+
import * as i0 from "@angular/core";
2122+
class MyDirective {
2123+
}
2124+
MyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", ngImport: i0, type: MyDirective, selector: "[myDir]", isStandalone: true, usesInheritance: true });
2125+
"#;
2126+
let result = link(&allocator, code, "test.mjs");
2127+
assert!(result.linked);
2128+
assert!(
2129+
result.code.contains("InheritDefinitionFeature"),
2130+
"Should have InheritDefinitionFeature, got:\n{}",
2131+
result.code
2132+
);
2133+
}
2134+
2135+
#[test]
2136+
fn test_link_directive_with_uses_on_changes() {
2137+
let allocator = Allocator::default();
2138+
let code = r#"
2139+
import * as i0 from "@angular/core";
2140+
class MyDirective {
2141+
}
2142+
MyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", ngImport: i0, type: MyDirective, selector: "[myDir]", isStandalone: true, usesOnChanges: true });
2143+
"#;
2144+
let result = link(&allocator, code, "test.mjs");
2145+
assert!(result.linked);
2146+
assert!(
2147+
result.code.contains("NgOnChangesFeature"),
2148+
"Should have NgOnChangesFeature, got:\n{}",
2149+
result.code
2150+
);
2151+
}
2152+
2153+
#[test]
2154+
fn test_link_directive_with_all_features() {
2155+
let allocator = Allocator::default();
2156+
let code = r#"
2157+
import * as i0 from "@angular/core";
2158+
class MyDirective {
2159+
}
2160+
MyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.0", ngImport: i0, type: MyDirective, selector: "[myDir]", isStandalone: true, providers: [SomeService], usesInheritance: true, usesOnChanges: true });
2161+
"#;
2162+
let result = link(&allocator, code, "test.mjs");
2163+
assert!(result.linked);
2164+
assert!(
2165+
result.code.contains("ProvidersFeature"),
2166+
"Should have ProvidersFeature, got:\n{}",
2167+
result.code
2168+
);
2169+
assert!(
2170+
result.code.contains("InheritDefinitionFeature"),
2171+
"Should have InheritDefinitionFeature, got:\n{}",
2172+
result.code
2173+
);
2174+
assert!(
2175+
result.code.contains("NgOnChangesFeature"),
2176+
"Should have NgOnChangesFeature, got:\n{}",
2177+
result.code
2178+
);
2179+
}
20932180
}

0 commit comments

Comments
 (0)