Commit 9724ae5
fix(angular): preserve block-body functions in decorator providers (#205)
* fix(angular): preserve block-body functions in decorator providers
Block-body arrow functions and function expressions in decorator properties
(e.g., useFactory) were silently having unsupported statements dropped.
Only return and expression statements survived, corrupting the function body
and causing runtime errors.
Add RawSource fallback: when convert_oxc_expression encounters a block-body
arrow with unsupported statement types (const, if, for, try/catch, etc.) or
a function expression, it preserves the complete source text verbatim via
span slicing instead of silently dropping statements.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(angular): pass source_text through build_decorator_metadata_array
Thread source_text into class metadata builder so decorator arguments
containing block-body arrows/function expressions are preserved via
RawSource fallback instead of being silently dropped.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(angular): thread source_text through remaining metadata builders
- build_ctor_params_metadata: pass source_text so @Inject(...) args
with complex expressions are preserved in ɵsetClassMetadata
- build_prop_decorators_metadata: pass source_text so @input({...})
with complex transform functions are preserved
- extract_provided_in: propagate source_text from parent
extract_injectable_metadata into forwardRef extraction
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(angular): strip TS types from RawSource, add expression-body fallback, thread source_text through property decorators
Three reviewer fixes:
1. P1 - RawSource now strips TypeScript type annotations via
parse-transform-codegen pipeline, preventing invalid JS output
like `(dep: Dep) => { ... }` in generated code.
2. Medium - Expression-body arrows with unsupported inner expressions
(e.g., `() => someUnsupportedExpr`) now fall back to RawSource
instead of returning None.
3. P2 - Thread source_text through property_decorators.rs so
@input({transform}), @ViewChild, @ContentChild arguments with
complex expressions are preserved via RawSource fallback.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(angular): use module source type and add fast path for TS stripping
- Use SourceType::ts().with_module(true) instead of script-mode ts()
so import.meta and ESM-only syntax parse correctly in RawSource
fallback expressions.
- Add fast path: try parsing as .mjs first. If the expression is
already valid JavaScript (no type annotations), return it as-is
without running the heavier semantic→transform→codegen pipeline.
Only expressions with actual TypeScript syntax pay the full cost.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 7d4e9a0 commit 9724ae5
File tree
22 files changed
+780
-242
lines changed- crates/oxc_angular_compiler
- src
- class_metadata
- component
- directive
- injectable
- ir
- ng_module
- output
- pipeline/phases
- pipe
- tests
- napi/angular-compiler/src
22 files changed
+780
-242
lines changedLines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| 126 | + | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| |||
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
166 | | - | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
168 | 171 | | |
169 | 172 | | |
| |||
205 | 208 | | |
206 | 209 | | |
207 | 210 | | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
251 | 255 | | |
252 | 256 | | |
253 | 257 | | |
254 | | - | |
| 258 | + | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
133 | | - | |
| 134 | + | |
| 135 | + | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
153 | | - | |
| 155 | + | |
| 156 | + | |
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
| |||
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
162 | | - | |
| 165 | + | |
| 166 | + | |
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
166 | | - | |
| 170 | + | |
| 171 | + | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
| |||
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
239 | | - | |
| 244 | + | |
240 | 245 | | |
241 | 246 | | |
242 | 247 | | |
| |||
1134 | 1139 | | |
1135 | 1140 | | |
1136 | 1141 | | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
1140 | 1149 | | |
1141 | 1150 | | |
1142 | 1151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1616 | 1616 | | |
1617 | 1617 | | |
1618 | 1618 | | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
1622 | 1626 | | |
1623 | 1627 | | |
1624 | 1628 | | |
| |||
1632 | 1636 | | |
1633 | 1637 | | |
1634 | 1638 | | |
1635 | | - | |
| 1639 | + | |
1636 | 1640 | | |
1637 | 1641 | | |
1638 | 1642 | | |
1639 | | - | |
| 1643 | + | |
1640 | 1644 | | |
1641 | 1645 | | |
1642 | 1646 | | |
| |||
1696 | 1700 | | |
1697 | 1701 | | |
1698 | 1702 | | |
1699 | | - | |
| 1703 | + | |
| 1704 | + | |
1700 | 1705 | | |
1701 | 1706 | | |
1702 | 1707 | | |
| |||
1758 | 1763 | | |
1759 | 1764 | | |
1760 | 1765 | | |
| 1766 | + | |
1761 | 1767 | | |
1762 | 1768 | | |
1763 | 1769 | | |
1764 | 1770 | | |
1765 | 1771 | | |
1766 | 1772 | | |
1767 | 1773 | | |
| 1774 | + | |
1768 | 1775 | | |
1769 | 1776 | | |
1770 | | - | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
1771 | 1780 | | |
1772 | 1781 | | |
1773 | 1782 | | |
| |||
1848 | 1857 | | |
1849 | 1858 | | |
1850 | 1859 | | |
1851 | | - | |
| 1860 | + | |
1852 | 1861 | | |
1853 | 1862 | | |
1854 | 1863 | | |
| |||
1906 | 1915 | | |
1907 | 1916 | | |
1908 | 1917 | | |
1909 | | - | |
| 1918 | + | |
| 1919 | + | |
1910 | 1920 | | |
1911 | 1921 | | |
1912 | 1922 | | |
| |||
1939 | 1949 | | |
1940 | 1950 | | |
1941 | 1951 | | |
1942 | | - | |
| 1952 | + | |
1943 | 1953 | | |
1944 | 1954 | | |
1945 | 1955 | | |
| |||
1980 | 1990 | | |
1981 | 1991 | | |
1982 | 1992 | | |
1983 | | - | |
| 1993 | + | |
| 1994 | + | |
1984 | 1995 | | |
1985 | 1996 | | |
1986 | 1997 | | |
| |||
2017 | 2028 | | |
2018 | 2029 | | |
2019 | 2030 | | |
2020 | | - | |
| 2031 | + | |
2021 | 2032 | | |
2022 | 2033 | | |
2023 | 2034 | | |
| |||
2061 | 2072 | | |
2062 | 2073 | | |
2063 | 2074 | | |
2064 | | - | |
| 2075 | + | |
| 2076 | + | |
2065 | 2077 | | |
2066 | 2078 | | |
2067 | 2079 | | |
| |||
2108 | 2120 | | |
2109 | 2121 | | |
2110 | 2122 | | |
2111 | | - | |
| 2123 | + | |
2112 | 2124 | | |
2113 | 2125 | | |
2114 | 2126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| |||
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
167 | | - | |
| 170 | + | |
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
| |||
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
183 | | - | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
| |||
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
| 258 | + | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| |||
270 | 274 | | |
271 | 275 | | |
272 | 276 | | |
273 | | - | |
| 277 | + | |
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
| |||
290 | 294 | | |
291 | 295 | | |
292 | 296 | | |
| 297 | + | |
293 | 298 | | |
294 | 299 | | |
295 | 300 | | |
| |||
306 | 311 | | |
307 | 312 | | |
308 | 313 | | |
309 | | - | |
| 314 | + | |
| 315 | + | |
310 | 316 | | |
311 | 317 | | |
312 | 318 | | |
| |||
885 | 891 | | |
886 | 892 | | |
887 | 893 | | |
888 | | - | |
| 894 | + | |
889 | 895 | | |
890 | 896 | | |
891 | 897 | | |
| |||
0 commit comments