Commit 630484f
fix(es/decorators): Emit correct metadata for enum parameters (#11154)
## Summary
Fixes decorator metadata emission to correctly handle enum parameters in
decorated methods and constructors.
Previously, SWC incorrectly emitted `typeof Options === "undefined" ?
Object : Options` for enum parameters, but it should emit:
- `Number` for numeric enums
- `String` for string enums
- `Object` for mixed enums
This matches TypeScript's behavior with `emitDecoratorMetadata`.
## Changes
- Updated `visit_mut_class_method` in `metadata.rs` to check the enum
map before serializing parameter types
- Updated `visit_mut_class` in `metadata.rs` to check the enum map for
constructor parameters
- Added test case for issue #11032 demonstrating the fix
## Root Cause
The bug was an inconsistency in how parameter types were handled vs.
return types and property types:
- Return types and property types correctly checked
`self.enums.get_kind_as_str()` before calling `serialize_type()`
- Parameter types (both in methods and constructors) did NOT check the
enum map
The fix applies the same pattern used for return types to parameter
types as well.
## Test Plan
- [x] Added new test case in
`tests/fixture/legacy-metadata/issues/11032/1/`
- [x] All existing legacy-metadata tests pass
- [x] New test verifies that numeric enum parameters emit `Number`
instead of the typeof check
- [x] Code formatted with `cargo fmt --all`
## Related Issue
Fixes #11032
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Donny/강동윤 <kdy.1997.dev@gmail.com>1 parent c2e75f3 commit 630484f
File tree
4 files changed
+54
-9
lines changed- .changeset
- crates
- swc_ecma_transforms_proposal/src/decorators/legacy
- swc_ecma_transforms/tests/fixture/legacy-metadata/issues/11032/1
4 files changed
+54
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
Lines changed: 19 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
179 | 191 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | 192 | | |
185 | 193 | | |
186 | 194 | | |
| |||
231 | 239 | | |
232 | 240 | | |
233 | 241 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
238 | 248 | | |
239 | 249 | | |
240 | 250 | | |
| |||
0 commit comments