Skip to content

Commit

Permalink
feat(transformer): support for transforming legacy decorator (#8614)
Browse files Browse the repository at this point in the history
related: #4047
related: rolldown/rolldown#2296

This is also known as "Experimental Decorator" in `TypeScript` by [experimentalDecorators](https://www.typescriptlang.org/tsconfig/#experimentalDecorators) enabling.

### Testing

- Six tests fail due to [emitDecoratorMetadata](https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata), as we haven't supported it yet. I found `esbuild` doesn't support it as well.
- A few tests fail due to different unique binding generator
- ...
  • Loading branch information
Dunqing committed Feb 9, 2025
1 parent 5d508a4 commit f2d28f3
Show file tree
Hide file tree
Showing 10 changed files with 1,332 additions and 37 deletions.
18 changes: 18 additions & 0 deletions crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ impl<'a> AstBuilder<'a> {
mem::replace(function, empty_function)
}

/// Move a class out by replacing it with an empty [`Class`].
pub fn move_class(self, class: &mut Class<'a>) -> Class<'a> {
let empty_class = self.class(
SPAN,
ClassType::ClassDeclaration,
self.vec(),
None,
NONE,
None,
NONE,
None,
self.class_body(SPAN, self.vec()),
false,
false,
);
mem::replace(class, empty_class)
}

/// Move an array element out by replacing it with an [`ArrayExpressionElement::Elision`].
pub fn move_array_expression_element(
self,
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_transformer/src/common/helper_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ pub enum Helper {
ReadOnlyError,
WriteOnlyError,
CheckInRHS,
Decorate,
DecorateParam,
}

impl Helper {
Expand Down Expand Up @@ -193,6 +195,8 @@ impl Helper {
Self::ReadOnlyError => "readOnlyError",
Self::WriteOnlyError => "writeOnlyError",
Self::CheckInRHS => "checkInRHS",
Self::Decorate => "decorate",
Self::DecorateParam => "decorateParam",
}
}
}
Expand Down
Loading

0 comments on commit f2d28f3

Please sign in to comment.